2023_02_01_182108_create_locale_settings.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreateLocaleSettings 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('locale.available', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:AVAILABLE') : '');
  11. $this->migrator->add('locale.clients_can_change', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE', true) : true);
  12. $this->migrator->add('locale.datatables', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DATATABLES') : 'en-gb');
  13. $this->migrator->add('locale.default', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DEFAULT', 'en') : 'en');
  14. $this->migrator->add('locale.dynamic', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DYNAMIC', false) : false);
  15. }
  16. public function down(): void
  17. {
  18. DB::table('settings_old')->insert([
  19. [
  20. 'key' => 'SETTINGS::LOCALE:AVAILABLE',
  21. 'value' => $this->getNewValue('available', 'locale'),
  22. 'type' => 'string',
  23. 'description' => 'The available locales.',
  24. ],
  25. [
  26. 'key' => 'SETTINGS::LOCALE:CLIENTS_CAN_CHANGE',
  27. 'value' => $this->getNewValue('clients_can_change', 'locale'),
  28. 'type' => 'boolean',
  29. 'description' => 'If clients can change their locale.',
  30. ],
  31. [
  32. 'key' => 'SETTINGS::LOCALE:DATATABLES',
  33. 'value' => $this->getNewValue('datatables', 'locale'),
  34. 'type' => 'string',
  35. 'description' => 'The locale for datatables.',
  36. ],
  37. [
  38. 'key' => 'SETTINGS::LOCALE:DEFAULT',
  39. 'value' => $this->getNewValue('default', 'locale'),
  40. 'type' => 'string',
  41. 'description' => 'The default locale.',
  42. ],
  43. [
  44. 'key' => 'SETTINGS::LOCALE:DYNAMIC',
  45. 'value' => $this->getNewValue('dynamic', 'locale'),
  46. 'type' => 'boolean',
  47. 'description' => 'If the locale should be dynamic.',
  48. ],
  49. ]);
  50. try {
  51. $this->migrator->delete('locale.available');
  52. $this->migrator->delete('locale.clients_can_change');
  53. $this->migrator->delete('locale.datatables');
  54. $this->migrator->delete('locale.default');
  55. $this->migrator->delete('locale.dynamic');
  56. } catch (Exception $e) {
  57. // Do nothing
  58. }
  59. }
  60. }