2023_02_04_181156_create_ticket_settings.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreateTicketSettings extends LegacySettingsMigration
  5. {
  6. public function up(): void
  7. {
  8. $table_exists = DB::table('settings_old')->exists();
  9. // Get the user-set configuration values from the old table.
  10. $this->migrator->add('ticket.enabled', $table_exists ? $this->getOldValue('SETTINGS::TICKET:ENABLED') : 'true');
  11. $this->migrator->add('ticket.notify', $table_exists ? $this->getOldValue('SETTINGS::TICKET:NOTIFY') : 'all');
  12. }
  13. public function down(): void
  14. {
  15. DB::table('settings_old')->insert([
  16. [
  17. 'key' => 'SETTINGS::TICKET:NOTIFY',
  18. 'value' => $this->getNewValue('notify', 'ticket'),
  19. 'type' => 'string',
  20. 'description' => 'The notification type for tickets.',
  21. ],
  22. [
  23. 'key' => 'SETTINGS::TICKET:ENABLED',
  24. 'value' => $this->getNewValue('enabled', 'ticket'),
  25. 'type' => 'boolean',
  26. 'description' => 'Enable or disable the ticket system.',
  27. ]
  28. ]);
  29. try {
  30. $this->migrator->delete('ticket.enabled');
  31. $this->migrator->delete('ticket.notify');
  32. } catch (Exception $e) {
  33. // Do nothing.
  34. }
  35. }
  36. }