This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class AddReviewDecisionEnrollmentStatus extends Migration
|
||||
{
|
||||
private const STATUSES_WITH_REVIEW_DECISION = [
|
||||
'admission under review',
|
||||
'review & decision',
|
||||
'payment pending',
|
||||
'enrolled',
|
||||
'withdraw under review',
|
||||
'refund pending',
|
||||
'withdrawn',
|
||||
'waitlist',
|
||||
'denied',
|
||||
];
|
||||
|
||||
private const STATUSES_WITHOUT_REVIEW_DECISION = [
|
||||
'admission under review',
|
||||
'payment pending',
|
||||
'enrolled',
|
||||
'withdraw under review',
|
||||
'refund pending',
|
||||
'withdrawn',
|
||||
'waitlist',
|
||||
'denied',
|
||||
];
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->modifyEnrollmentStatusEnum(self::STATUSES_WITH_REVIEW_DECISION);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
if ($this->db->tableExists('enrollments')) {
|
||||
$this->db->table('enrollments')
|
||||
->where('enrollment_status', 'review & decision')
|
||||
->update(['enrollment_status' => 'admission under review']);
|
||||
}
|
||||
|
||||
$this->modifyEnrollmentStatusEnum(self::STATUSES_WITHOUT_REVIEW_DECISION);
|
||||
}
|
||||
|
||||
private function modifyEnrollmentStatusEnum(array $statuses): void
|
||||
{
|
||||
if (! $this->db->tableExists('enrollments') || ! $this->db->fieldExists('enrollment_status', 'enrollments')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array($this->db->DBDriver, ['MySQLi', 'MySQL'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$enumValues = implode(',', array_map(static fn (string $status): string => "'" . str_replace("'", "''", $status) . "'", $statuses));
|
||||
$this->db->query(
|
||||
"ALTER TABLE `enrollments` MODIFY `enrollment_status` ENUM({$enumValues}) NOT NULL DEFAULT 'admission under review'"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user