2023_02_01_181334_create_pterodactyl_settings.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreatePterodactylSettings extends LegacySettingsMigration
  5. {
  6. public function up(): void
  7. {
  8. $table_exists = DB::table('settings_old')->exists();
  9. $this->migrator->addEncrypted('pterodactyl.admin_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:TOKEN', '') : env('PTERODACTYL_TOKEN', ''));
  10. $this->migrator->addEncrypted('pterodactyl.user_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN', '') : '');
  11. $this->migrator->add('pterodactyl.panel_url', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:URL', '') : env('PTERODACTYL_URL', ''));
  12. $this->migrator->add('pterodactyl.per_page_limit', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT', 200) : 200);
  13. }
  14. public function down(): void
  15. {
  16. DB::table('settings_old')->insert([
  17. [
  18. 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN',
  19. 'value' => $this->getNewValue('admin_token', 'pterodactyl'),
  20. 'type' => 'string',
  21. 'description' => 'The admin token for the Pterodactyl panel.',
  22. ],
  23. [
  24. 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN',
  25. 'value' => $this->getNewValue('user_token', 'pterodactyl'),
  26. 'type' => 'string',
  27. 'description' => 'The user token for the Pterodactyl panel.',
  28. ],
  29. [
  30. 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:URL',
  31. 'value' => $this->getNewValue('panel_url', 'pterodactyl'),
  32. 'type' => 'string',
  33. 'description' => 'The URL for the Pterodactyl panel.',
  34. ],
  35. [
  36. 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT',
  37. 'value' => $this->getNewValue('per_page_limit', 'pterodactyl'),
  38. 'type' => 'integer',
  39. 'description' => 'The number of servers to show per page.',
  40. ],
  41. ]);
  42. try {
  43. $this->migrator->delete('pterodactyl.admin_token');
  44. $this->migrator->delete('pterodactyl.user_token');
  45. $this->migrator->delete('pterodactyl.panel_url');
  46. $this->migrator->delete('pterodactyl.per_page_limit');
  47. } catch (Exception $e) {
  48. echo 'Caught exception: ', $e->getMessage(), "\n";
  49. }
  50. }
  51. }