Files
alrahma_sunday_school/app/Database/Migrations/2026-08-08-000200_GrantEnrollmentExceptionPermission.php
2026-08-15 15:07:16 -04:00

65 lines
1.9 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class GrantEnrollmentExceptionPermission extends Migration
{
private string $permissionName = 'enrollment.exception.manage';
public function up()
{
if (! $this->db->tableExists('permissions')) {
return;
}
$permission = $this->db->table('permissions')
->where('name', $this->permissionName)
->limit(1)
->get()
->getRowArray();
if ($permission === null) {
$insert = [
'name' => $this->permissionName,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
];
if ($this->db->fieldExists('description', 'permissions')) {
$insert['description'] = 'Manage scoped enrollment eligibility exceptions.';
}
$this->db->table('permissions')->insert($insert);
$permissionId = (int) $this->db->insertID();
} else {
$permissionId = (int) $permission['id'];
}
// The plan requires a narrow permission but not an automatic broad role grant.
// Assign enrollment.exception.manage through the existing role-permission UI.
}
public function down()
{
if (! $this->db->tableExists('permissions') || ! $this->db->tableExists('role_permissions')) {
return;
}
$permission = $this->db->table('permissions')
->where('name', $this->permissionName)
->limit(1)
->get()
->getRowArray();
if ($permission === null) {
return;
}
$this->db->table('role_permissions')
->where('permission_id', (int) $permission['id'])
->delete();
$this->db->table('permissions')
->where('id', (int) $permission['id'])
->delete();
}
}