2023_02_01_182158_create_website_settings.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreateWebsiteSettings 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('website.motd_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_ENABLED", true) : true);
  11. $this->migrator->add(
  12. 'website.motd_message',
  13. $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_MESSAGE") :
  14. "<h1 style='text-align: center;'><img style='display: block; margin-left: auto; margin-right: auto;' src='https://ctrlpanel.gg/img/controlpanel.png' alt=' width='200' height='200'><span style='font-size: 36pt;'>CtrlPanel.gg</span></h1>
  15. <p><span style='font-size: 18pt;'>Thank you for using our Software</span></p>
  16. <p><span style='font-size: 18pt;'>If you have any questions, make sure to join our <a href='https://discord.com/invite/4Y6HjD2uyU' target='_blank' rel='noopener'>Discord</a></span></p>
  17. <p><span style='font-size: 10pt;'>(you can change this message in the <a href='admin/settings#system'>Settings</a> )</span></p>"
  18. );
  19. $this->migrator->add('website.show_imprint', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_IMPRINT", false) : false);
  20. $this->migrator->add('website.show_privacy', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_PRIVACY", false) : false);
  21. $this->migrator->add('website.show_tos', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_TOS", false) : false);
  22. $this->migrator->add('website.useful_links_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:USEFULLINKS_ENABLED", true) : true);
  23. $this->migrator->add('website.seo_title', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SEO_TITLE") : 'CtrlPanel.gg');
  24. $this->migrator->add('website.seo_description', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SEO_DESCRIPTION") : 'Billing software for Pterodactyl Panel.');
  25. $this->migrator->add('website.enable_login_logo', true);
  26. }
  27. public function down(): void
  28. {
  29. DB::table('settings_old')->insert([
  30. [
  31. 'key' => 'SETTINGS::SYSTEM:MOTD_ENABLED',
  32. 'value' => $this->getNewValue('motd_enabled', 'website'),
  33. 'type' => 'boolean',
  34. 'description' => 'Enable or disable the MOTD.',
  35. ],
  36. [
  37. 'key' => 'SETTINGS::SYSTEM:MOTD_MESSAGE',
  38. 'value' => $this->getNewValue('motd_message', 'website'),
  39. 'type' => 'text',
  40. 'description' => 'The message that will be displayed in the MOTD.',
  41. ],
  42. [
  43. 'key' => 'SETTINGS::SYSTEM:SHOW_IMPRINT',
  44. 'value' => $this->getNewValue('show_imprint', 'website'),
  45. 'type' => 'boolean',
  46. 'description' => 'Enable or disable the imprint.',
  47. ],
  48. [
  49. 'key' => 'SETTINGS::SYSTEM:SHOW_PRIVACY',
  50. 'value' => $this->getNewValue('show_privacy', 'website'),
  51. 'type' => 'boolean',
  52. 'description' => 'Enable or disable the privacy policy.',
  53. ],
  54. [
  55. 'key' => 'SETTINGS::SYSTEM:SHOW_TOS',
  56. 'value' => $this->getNewValue('show_tos', 'website'),
  57. 'type' => 'boolean',
  58. 'description' => 'Enable or disable the terms of service.',
  59. ],
  60. [
  61. 'key' => 'SETTINGS::SYSTEM:USEFULLINKS_ENABLED',
  62. 'value' => $this->getNewValue('useful_links_enabled', 'website'),
  63. 'type' => 'boolean',
  64. 'description' => 'Enable or disable the useful links.',
  65. ],
  66. [
  67. 'key' => 'SETTINGS::SYSTEM:SEO_TITLE',
  68. 'value' => $this->getNewValue('seo_title', 'website'),
  69. 'type' => 'string',
  70. 'description' => 'The title of the website.',
  71. ],
  72. [
  73. 'key' => 'SETTINGS::SYSTEM:SEO_DESCRIPTION',
  74. 'value' => $this->getNewValue('seo_description', 'website'),
  75. 'type' => 'string',
  76. 'description' => 'The description of the website.',
  77. ],
  78. [
  79. 'key' => 'SETTINGS::SYSTEM:ENABLE_LOGIN_LOGO',
  80. 'value' => $this->getNewValue('enable_login_logo', 'website'),
  81. 'type' => 'boolean',
  82. 'description' => 'Enable or disable the login logo.',
  83. ]
  84. ]);
  85. try {
  86. $this->migrator->delete('website.motd_enabled');
  87. $this->migrator->delete('website.motd_message');
  88. $this->migrator->delete('website.show_imprint');
  89. $this->migrator->delete('website.show_privacy');
  90. $this->migrator->delete('website.show_tos');
  91. $this->migrator->delete('website.useful_links_enabled');
  92. $this->migrator->delete('website.seo_title');
  93. $this->migrator->delete('website.seo_description');
  94. $this->migrator->delete('website.enable_login_logo');
  95. } catch (Exception $e) {
  96. // Do nothing
  97. }
  98. }
  99. }