2023_02_01_164731_create_general_settings.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreateGeneralSettings 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('general.store_enabled', true);
  11. $this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME', 'Credits') : 'Credits');
  12. $this->migrator->add('general.recaptcha_site_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") : env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'));
  13. $this->migrator->add('general.recaptcha_secret_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SECRET_KEY") : env('RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'));
  14. $this->migrator->add('general.recaptcha_enabled', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:ENABLED", false) : false);
  15. $this->migrator->add('general.phpmyadmin_url', $table_exists ? $this->getOldValue("SETTINGS::MISC:PHPMYADMIN:URL") : env('PHPMYADMIN_URL'));
  16. $this->migrator->add('general.alert_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_ENABLED", false) : false);
  17. $this->migrator->add('general.alert_type', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_TYPE", 'dark') : 'dark');
  18. $this->migrator->add('general.alert_message', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_MESSAGE") : null);
  19. $this->migrator->add('general.theme', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:THEME", 'default') : 'default');
  20. }
  21. public function down(): void
  22. {
  23. DB::table('settings_old')->insert([
  24. [
  25. 'key' => 'SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME',
  26. 'value' => $this->getNewValue('credits_display_name', 'general'),
  27. 'type' => 'string',
  28. 'description' => 'The name of the credits on the panel.'
  29. ],
  30. [
  31. 'key' => 'SETTINGS::SYSTEM:ALERT_ENABLED',
  32. 'value' => $this->getNewValue('alert_enabled', 'general'),
  33. 'type' => 'boolean',
  34. 'description' => 'Enable the alert at the top of the panel.'
  35. ],
  36. [
  37. 'key' => 'SETTINGS::SYSTEM:ALERT_TYPE',
  38. 'value' => $this->getNewValue('alert_type', 'general'),
  39. 'type' => 'string',
  40. 'description' => 'The type of alert to display.'
  41. ],
  42. [
  43. 'key' => 'SETTINGS::SYSTEM:ALERT_MESSAGE',
  44. 'value' => $this->getNewValue('alert_message', 'general'),
  45. 'type' => 'text',
  46. 'description' => 'The message to display in the alert.'
  47. ],
  48. [
  49. 'key' => 'SETTINGS::SYSTEM:THEME',
  50. 'value' => $this->getNewValue('theme', 'general'),
  51. 'type' => 'string',
  52. 'description' => 'The theme to use for the panel.'
  53. ],
  54. [
  55. 'key' => 'SETTINGS::RECAPTCHA:SITE_KEY',
  56. 'value' => $this->getNewValue('recaptcha_site_key', 'general'),
  57. 'type' => 'string',
  58. 'description' => 'The site key for reCAPTCHA.'
  59. ],
  60. [
  61. 'key' => 'SETTINGS::RECAPTCHA:SECRET_KEY',
  62. 'value' => $this->getNewValue('recaptcha_secret_key', 'general'),
  63. 'type' => 'string',
  64. 'description' => 'The secret key for reCAPTCHA.'
  65. ],
  66. [
  67. 'key' => 'SETTINGS::RECAPTCHA:ENABLED',
  68. 'value' => $this->getNewValue('recaptcha_enabled', 'general'),
  69. 'type' => 'boolean',
  70. 'description' => 'Enable reCAPTCHA on the panel.'
  71. ],
  72. [
  73. 'key' => 'SETTINGS::MISC:PHPMYADMIN:URL',
  74. 'value' => $this->getNewValue('phpmyadmin_url', 'general'),
  75. 'type' => 'string',
  76. 'description' => 'The URL to your phpMyAdmin installation.'
  77. ],
  78. ]);
  79. try {
  80. $this->migrator->delete('general.store_enabled');
  81. $this->migrator->delete('general.credits_display_name');
  82. $this->migrator->delete('general.recaptcha_site_key');
  83. $this->migrator->delete('general.recaptcha_secret_key');
  84. $this->migrator->delete('general.recaptcha_enabled');
  85. $this->migrator->delete('general.phpmyadmin_url');
  86. $this->migrator->delete('general.alert_enabled');
  87. $this->migrator->delete('general.alert_type');
  88. $this->migrator->delete('general.alert_message');
  89. $this->migrator->delete('general.theme');
  90. } catch (Exception $e) {
  91. // Do nothing
  92. }
  93. }
  94. }