Explorar o código

fix: 🚑️ Use LegacySettingsMigration && mind nullable values

IceToast hai 1 ano
pai
achega
48cce11ebc

+ 9 - 52
database/settings/2023_02_01_164731_create_general_settings.php

@@ -1,9 +1,9 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateGeneralSettings extends SettingsMigration
+class CreateGeneralSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
@@ -11,15 +11,15 @@ class CreateGeneralSettings extends SettingsMigration
 
         // Get the user-set configuration values from the old table.
         $this->migrator->add('general.store_enabled',  true);
-        $this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME') : 'Credits');
+        $this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME', 'Credits') : 'Credits');
         $this->migrator->add('general.recaptcha_site_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") : env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'));
         $this->migrator->add('general.recaptcha_secret_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SECRET_KEY") : env('RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'));
-        $this->migrator->add('general.recaptcha_enabled', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:ENABLED") : true);
-        $this->migrator->add('general.phpmyadmin_url', $table_exists ? $this->getOldValue("SETTINGS::MISC:PHPMYADMIN:URL") : env('PHPMYADMIN_URL', ''));
-        $this->migrator->add('general.alert_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_ENABLED") : false);
-        $this->migrator->add('general.alert_type', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_TYPE") : 'dark');
-        $this->migrator->add('general.alert_message', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_MESSAGE") : '');
-        $this->migrator->add('general.theme', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:THEME") : 'default');
+        $this->migrator->add('general.recaptcha_enabled', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:ENABLED", false) : false);
+        $this->migrator->add('general.phpmyadmin_url', $table_exists ? $this->getOldValue("SETTINGS::MISC:PHPMYADMIN:URL") : env('PHPMYADMIN_URL'));
+        $this->migrator->add('general.alert_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_ENABLED", false) : false);
+        $this->migrator->add('general.alert_type', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_TYPE", 'dark') : 'dark');
+        $this->migrator->add('general.alert_message', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:ALERT_MESSAGE") : null);
+        $this->migrator->add('general.theme', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:THEME", 'default') : 'default');
     }
 
     public function down(): void
@@ -93,47 +93,4 @@ class CreateGeneralSettings extends SettingsMigration
         $this->migrator->delete('general.alert_message');
         $this->migrator->delete('general.theme');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'general'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 8 - 52
database/settings/2023_02_01_181334_create_pterodactyl_settings.php

@@ -1,21 +1,20 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreatePterodactylSettings extends SettingsMigration
+class CreatePterodactylSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
-        // Get the user-set configuration values from the old table.
-        //$this->migrator->addEncrypted('pterodactyl.admin_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:TOKEN') : env('PTERODACTYL_TOKEN', ''));
-        //$this->migrator->addEncrypted('pterodactyl.user_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN') : '');
-        $this->migrator->add('pterodactyl.admin_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:TOKEN') : env('PTERODACTYL_TOKEN', ''));
-        $this->migrator->add('pterodactyl.user_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN') : '');
-        $this->migrator->add('pterodactyl.panel_url', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:URL') : env('PTERODACTYL_URL', ''));
-        $this->migrator->add('pterodactyl.per_page_limit', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT') : 200);
+        $this->migrator->addEncrypted('pterodactyl.admin_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:TOKEN', '') : env('PTERODACTYL_TOKEN', ''));
+        $this->migrator->addEncrypted('pterodactyl.user_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN', '') : '');
+        // $this->migrator->add('pterodactyl.admin_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:TOKEN') : env('PTERODACTYL_TOKEN', ''));
+        // $this->migrator->add('pterodactyl.user_token', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN') : '');
+        $this->migrator->add('pterodactyl.panel_url', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:URL', '') : env('PTERODACTYL_URL', ''));
+        $this->migrator->add('pterodactyl.per_page_limit', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT', 200) : 200);
     }
 
     public function down(): void
@@ -54,47 +53,4 @@ class CreatePterodactylSettings extends SettingsMigration
         $this->migrator->delete('pterodactyl.panel_url');
         $this->migrator->delete('pterodactyl.per_page_limit');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'pterodactyl'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 2 - 45
database/settings/2023_02_01_181453_create_mail_settings.php

@@ -1,9 +1,9 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateMailSettings extends SettingsMigration
+class CreateMailSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
@@ -83,47 +83,4 @@ class CreateMailSettings extends SettingsMigration
         $this->migrator->delete('mail.mail_from_name');
         $this->migrator->delete('mail.mail_mailer');
     }
-
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'mail'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 14 - 57
database/settings/2023_02_01_181925_create_user_settings.php

@@ -1,27 +1,27 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateUserSettings extends SettingsMigration
+class CreateUserSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('user.credits_reward_after_verify_discord', $table_exists ? $this->getOldValue('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD') : 250);
-        $this->migrator->add('user.credits_reward_after_verify_email', $table_exists ? $this->getOldValue('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_EMAIL') : 250);
-        $this->migrator->add('user.force_discord_verification', $table_exists ? $this->getOldValue('SETTINGS::USER:FORCE_DISCORD_VERIFICATION') : false);
-        $this->migrator->add('user.force_email_verification', $table_exists ? $this->getOldValue('SETTINGS::USER:FORCE_EMAIL_VERIFICATION') : false);
-        $this->migrator->add('user.initial_credits', $table_exists ? $this->getOldValue('SETTINGS::USER:INITIAL_CREDITS') : 250);
-        $this->migrator->add('user.initial_server_limit', $table_exists ? $this->getOldValue('SETTINGS::USER:INITIAL_SERVER_LIMIT') : 1);
-        $this->migrator->add('user.min_credits_to_make_server', $table_exists ? $this->getOldValue('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER') : 50);
-        $this->migrator->add('user.server_limit_after_irl_purchase', $table_exists ? $this->getOldValue('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE') : 10);
-        $this->migrator->add('user.server_limit_after_verify_discord', $table_exists ? $this->getOldValue('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD') : 2);
-        $this->migrator->add('user.server_limit_after_verify_email', $table_exists ? $this->getOldValue('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL') : 2);
-        $this->migrator->add('user.register_ip_check', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:REGISTER_IP_CHECK") : true);
-        $this->migrator->add('user.creation_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:CREATION_OF_NEW_USERS") : true);
+        $this->migrator->add('user.credits_reward_after_verify_discord', $table_exists ? $this->getOldValue('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD', 250) : 250);
+        $this->migrator->add('user.credits_reward_after_verify_email', $table_exists ? $this->getOldValue('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_EMAIL', 250) : 250);
+        $this->migrator->add('user.force_discord_verification', $table_exists ? $this->getOldValue('SETTINGS::USER:FORCE_DISCORD_VERIFICATION', false) : false);
+        $this->migrator->add('user.force_email_verification', $table_exists ? $this->getOldValue('SETTINGS::USER:FORCE_EMAIL_VERIFICATION', false) : false);
+        $this->migrator->add('user.initial_credits', $table_exists ? $this->getOldValue('SETTINGS::USER:INITIAL_CREDITS', 250) : 250);
+        $this->migrator->add('user.initial_server_limit', $table_exists ? $this->getOldValue('SETTINGS::USER:INITIAL_SERVER_LIMIT', 1) : 1);
+        $this->migrator->add('user.min_credits_to_make_server', $table_exists ? $this->getOldValue('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50) : 50);
+        $this->migrator->add('user.server_limit_after_irl_purchase', $table_exists ? $this->getOldValue('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE', 10) : 10);
+        $this->migrator->add('user.server_limit_after_verify_discord', $table_exists ? $this->getOldValue('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD', 2) : 2);
+        $this->migrator->add('user.server_limit_after_verify_email', $table_exists ? $this->getOldValue('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL', 2) : 2);
+        $this->migrator->add('user.register_ip_check', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:REGISTER_IP_CHECK", true) : true);
+        $this->migrator->add('user.creation_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:CREATION_OF_NEW_USERS", true) : true);
     }
 
     public function down(): void
@@ -117,47 +117,4 @@ class CreateUserSettings extends SettingsMigration
         $this->migrator->delete('user.register_ip_check');
         $this->migrator->delete('user.creation_enabled');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'user'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 5 - 48
database/settings/2023_02_01_181950_create_server_settings.php

@@ -1,18 +1,18 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateServerSettings extends SettingsMigration
+class CreateServerSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('server.allocation_limit', $table_exists ? $this->getOldValue('SETTINGS::SERVER:ALLOCATION_LIMIT') : 200);
-        $this->migrator->add('server.creation_enabled', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS') : true);
-        $this->migrator->add('server.enable_upgrade', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:ENABLE_UPGRADE') : false);
+        $this->migrator->add('server.allocation_limit', $table_exists ? $this->getOldValue('SETTINGS::SERVER:ALLOCATION_LIMIT', 200) : 200);
+        $this->migrator->add('server.creation_enabled', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS', true) : true);
+        $this->migrator->add('server.enable_upgrade', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:ENABLE_UPGRADE', false) : false);
     }
 
     public function down(): void
@@ -42,47 +42,4 @@ class CreateServerSettings extends SettingsMigration
         $this->migrator->delete('server.creation_enabled');
         $this->migrator->delete('server.enable_upgrade');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'server'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 10 - 53
database/settings/2023_02_01_182021_create_invoice_settings.php

@@ -1,23 +1,23 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateInvoiceSettings extends SettingsMigration
+class CreateInvoiceSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('invoice.company_address', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_ADDRESS') : '');
-        $this->migrator->add('invoice.company_mail', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_MAIL') : '');
-        $this->migrator->add('invoice.company_name', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_NAME') : '');
-        $this->migrator->add('invoice.company_phone', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_PHONE') : '');
-        $this->migrator->add('invoice.company_vat', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_VAT') : '');
-        $this->migrator->add('invoice.company_website', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_WEBSITE') : '');
-        $this->migrator->add('invoice.enabled', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:ENABLED') : false);
-        $this->migrator->add('invoice.prefix', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:PREFIX') : 'INV');
+        $this->migrator->add('invoice.company_address', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_ADDRESS') : null);
+        $this->migrator->add('invoice.company_mail', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_MAIL') : null);
+        $this->migrator->add('invoice.company_name', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_NAME') : null);
+        $this->migrator->add('invoice.company_phone', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_PHONE') : null);
+        $this->migrator->add('invoice.company_vat', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_VAT') : null);
+        $this->migrator->add('invoice.company_website', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_WEBSITE') : null);
+        $this->migrator->add('invoice.enabled', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:ENABLED', false) : false);
+        $this->migrator->add('invoice.prefix', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:PREFIX') : null);
     }
 
     public function down(): void
@@ -82,47 +82,4 @@ class CreateInvoiceSettings extends SettingsMigration
         $this->migrator->delete('invoice.enabled');
         $this->migrator->delete('invoice.prefix');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'invoice'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 8 - 51
database/settings/2023_02_01_182043_create_discord_settings.php

@@ -1,21 +1,21 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateDiscordSettings extends SettingsMigration
+class CreateDiscordSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('discord.bot_token', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN') : '');
-        $this->migrator->add('discord.client_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_ID') : '');
-        $this->migrator->add('discord.client_secret', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_SECRET') : '');
-        $this->migrator->add('discord.guild_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:GUILD_ID') : '');
-        $this->migrator->add('discord.invite_url', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:INVITE_URL') : '');
-        $this->migrator->add('discord.role_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:ROLE_ID') : '');
+        $this->migrator->add('discord.bot_token', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN') : null);
+        $this->migrator->add('discord.client_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_ID') : null);
+        $this->migrator->add('discord.client_secret', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_SECRET') : null);
+        $this->migrator->add('discord.guild_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:GUILD_ID') : null);
+        $this->migrator->add('discord.invite_url', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:INVITE_URL') : null);
+        $this->migrator->add('discord.role_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:ROLE_ID') : null);
     }
 
     public function down(): void
@@ -67,47 +67,4 @@ class CreateDiscordSettings extends SettingsMigration
         $this->migrator->delete('discord.invite_url');
         $this->migrator->delete('discord.role_id');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'discord'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 5 - 48
database/settings/2023_02_01_182108_create_locale_settings.php

@@ -1,9 +1,9 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateLocaleSettings extends SettingsMigration
+class CreateLocaleSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
@@ -11,10 +11,10 @@ class CreateLocaleSettings extends SettingsMigration
 
         // Get the user-set configuration values from the old table.
         $this->migrator->add('locale.available', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:AVAILABLE') : '');
-        $this->migrator->add('locale.clients_can_change', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') : true);
+        $this->migrator->add('locale.clients_can_change', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE', true) : true);
         $this->migrator->add('locale.datatables', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DATATABLES') : 'en-gb');
-        $this->migrator->add('locale.default', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DEFAULT') : 'en');
-        $this->migrator->add('locale.dynamic', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DYNAMIC') : false);
+        $this->migrator->add('locale.default', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DEFAULT', 'en') : 'en');
+        $this->migrator->add('locale.dynamic', $table_exists ? $this->getOldValue('SETTINGS::LOCALE:DYNAMIC', false) : false);
     }
 
     public function down(): void
@@ -58,47 +58,4 @@ class CreateLocaleSettings extends SettingsMigration
         $this->migrator->delete('locale.default');
         $this->migrator->delete('locale.dynamic');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'locale'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 6 - 49
database/settings/2023_02_01_182135_create_referral_settings.php

@@ -1,20 +1,20 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateReferralSettings extends SettingsMigration
+class CreateReferralSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('referral.always_give_commission', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION') : false);
-        $this->migrator->add('referral.enabled', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL::ENABLED') : false);
+        $this->migrator->add('referral.always_give_commission', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION', false) : false);
+        $this->migrator->add('referral.enabled', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL::ENABLED', false) : false);
         $this->migrator->add('referral.reward', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL::REWARD') : 100);
-        $this->migrator->add('referral.mode', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL:MODE') : 'sign-up');
-        $this->migrator->add('referral.percentage', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL:PERCENTAGE') : 100);
+        $this->migrator->add('referral.mode', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL:MODE', 'sign-up') : 'sign-up');
+        $this->migrator->add('referral.percentage', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL:PERCENTAGE', 100) : 100);
     }
 
     public function down(): void
@@ -65,47 +65,4 @@ class CreateReferralSettings extends SettingsMigration
         $this->migrator->delete('referral.mode');
         $this->migrator->delete('referral.percentage');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'referral'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 9 - 51
database/settings/2023_02_01_182158_create_website_settings.php

@@ -1,27 +1,28 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateWebsiteSettings extends SettingsMigration
+class CreateWebsiteSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
         $table_exists = DB::table('settings_old')->exists();
 
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('website.motd_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_ENABLED") : true);
+        $this->migrator->add('website.motd_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_ENABLED", true) : true);
         $this->migrator->add(
             'website.motd_message',
             $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_MESSAGE") :
                 "<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>
  <p><span style='font-size: 18pt;'>Thank you for using our Software</span></p>
  <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>
- <p><span style='font-size: 10pt;'>(you can change this message in the <a href='admin/settings#system'>Settings</a> )</span></p>");
-        $this->migrator->add('website.show_imprint', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_IMPRINT") : false);
-        $this->migrator->add('website.show_privacy', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_PRIVACY") : false);
-        $this->migrator->add('website.show_tos', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_TOS") : false);
-        $this->migrator->add('website.useful_links_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:USEFULLINKS_ENABLED") : true);
+ <p><span style='font-size: 10pt;'>(you can change this message in the <a href='admin/settings#system'>Settings</a> )</span></p>"
+        );
+        $this->migrator->add('website.show_imprint', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_IMPRINT", false) : false);
+        $this->migrator->add('website.show_privacy', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_PRIVACY", false) : false);
+        $this->migrator->add('website.show_tos', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SHOW_TOS", false) : false);
+        $this->migrator->add('website.useful_links_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:USEFULLINKS_ENABLED", true) : true);
         $this->migrator->add('website.seo_title', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SEO_TITLE") : 'CtrlPanel.gg');
         $this->migrator->add('website.seo_description', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SEO_DESCRIPTION") : 'Billing software for Pterodactyl Panel.');
         $this->migrator->add('website.enable_login_logo', true);
@@ -96,47 +97,4 @@ class CreateWebsiteSettings extends SettingsMigration
         $this->migrator->delete('website.seo_description');
         $this->migrator->delete('website.enable_login_logo');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'website'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }

+ 2 - 50
database/settings/2023_02_04_181156_create_ticket_settings.php

@@ -1,9 +1,9 @@
 <?php
 
-use Spatie\LaravelSettings\Migrations\SettingsMigration;
+use App\Classes\LegacySettingsMigration;
 use Illuminate\Support\Facades\DB;
 
-class CreateTicketSettings extends SettingsMigration
+class CreateTicketSettings extends LegacySettingsMigration
 {
     public function up(): void
     {
@@ -34,52 +34,4 @@ class CreateTicketSettings extends SettingsMigration
         $this->migrator->delete('ticket.enabled');
         $this->migrator->delete('ticket.notify');
     }
-
-    public function getNewValue(string $name)
-    {
-        $new_value = DB::table('settings')->where([['group', '=', 'ticket'], ['name', '=', $name]])->get(['payload'])->first();
-
-        // Some keys returns '""' as a value.
-        if ($new_value->payload === '""') {
-            return null;
-        }
-
-        // remove the quotes from the string
-        if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
-            return substr($new_value->payload, 1, -1);
-        }
-
-        return $new_value->payload;
-    }
-
-    public function getOldValue(string $key)
-    {
-        // Always get the first value of the key.
-        $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
-
-        // Handle the old values to return without it being a string in all cases.
-
-        if (is_null($old_value)) {
-            return '';
-        }
-        if ($old_value->type === "string" || $old_value->type === "text") {
-            if (is_null($old_value->value)) {
-                return '';
-            }
-
-
-            // Some values have the type string, but their values are boolean.
-            if ($old_value->value === "false" || $old_value->value === "true") {
-                return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-            }
-
-            return $old_value->value;
-        }
-
-        if ($old_value->type === "boolean") {
-            return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
-        }
-
-        return filter_var($old_value->value, FILTER_VALIDATE_INT);
-    }
 }