diff --git a/db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php b/db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php new file mode 100644 index 00000000..32e91ece --- /dev/null +++ b/db/migrations/2023_12_06_000000_change_edit_shirt_require_bureaucrat.php @@ -0,0 +1,57 @@ +db = $this->schema->getConnection(); + + $this->editShirt = $this->db->table('privileges') + ->where('name', 'user.edit.shirt') + ->get(['id']) + ->first()->id; + } + + /** + * Run the migration + */ + public function up(): void + { + $this->movePermission($this->editShirt, $this->shiCo, $this->bureaucrat); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $this->movePermission($this->editShirt, $this->bureaucrat, $this->shiCo); + } + + protected function movePermission(int $privilege, int $oldGroup, int $newGroup): void + { + $this->db->table('group_privileges') + ->insertOrIgnore(['group_id' => $newGroup, 'privilege_id' => $privilege]); + + $this->db->table('group_privileges') + ->where(['group_id' => $oldGroup, 'privilege_id' => $privilege]) + ->delete(); + } +}