update
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const SCENARIOS = [
|
||||
'service_expiry',
|
||||
'service_renewal_reminder',
|
||||
'invoice_notification',
|
||||
'invoice_payment_reminder',
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$this->update(fn (array $disabled) => array_values(array_unique([...$disabled, ...self::SCENARIOS])));
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->update(fn (array $disabled) => array_values(array_diff($disabled, self::SCENARIOS)));
|
||||
}
|
||||
|
||||
private function update(callable $change): void
|
||||
{
|
||||
$row = DB::table('setting')->where('key', 'email_settings')->first();
|
||||
$value = $row ? (json_decode($row->value, true) ?: []) : [];
|
||||
$value['auto_disabled'] = $change((array) ($value['auto_disabled'] ?? []));
|
||||
|
||||
DB::table('setting')->updateOrInsert(
|
||||
['key' => 'email_settings'],
|
||||
['value' => json_encode($value), 'updated_at' => now()],
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user