2023_02_01_181950_create_server_settings.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreateServerSettings 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('server.allocation_limit', $table_exists ? $this->getOldValue('SETTINGS::SERVER:ALLOCATION_LIMIT', 200) : 200);
  11. $this->migrator->add('server.creation_enabled', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS', true) : true);
  12. $this->migrator->add('server.enable_upgrade', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:ENABLE_UPGRADE', false) : false);
  13. }
  14. public function down(): void
  15. {
  16. DB::table('settings_old')->insert([
  17. [
  18. 'key' => 'SETTINGS::SERVER:ALLOCATION_LIMIT',
  19. 'value' => $this->getNewValue('allocation_limit', 'server'),
  20. 'type' => 'integer',
  21. 'description' => 'The number of servers to show per page.',
  22. ],
  23. [
  24. 'key' => 'SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS',
  25. 'value' => $this->getNewValue('creation_enabled', 'server'),
  26. 'type' => 'boolean',
  27. 'description' => 'Whether or not users can create new servers.',
  28. ],
  29. [
  30. 'key' => 'SETTINGS::SYSTEM:ENABLE_UPGRADE',
  31. 'value' => $this->getNewValue('enable_upgrade', 'server'),
  32. 'type' => 'boolean',
  33. 'description' => 'Whether or not users can upgrade their servers.',
  34. ],
  35. ]);
  36. try {
  37. $this->migrator->delete('server.allocation_limit');
  38. $this->migrator->delete('server.creation_enabled');
  39. $this->migrator->delete('server.enable_upgrade');
  40. } catch (Exception $e) {
  41. // Do nothing
  42. }
  43. }
  44. }