فهرست منبع

fix: Ternary would always return 'true'

Ferks-FK 2 سال پیش
والد
کامیت
5305ae7803

+ 1 - 1
database/seeders/DatabaseSeeder.php

@@ -15,7 +15,7 @@ class DatabaseSeeder extends Seeder
     public function run()
     {
         $this->call([
-            SettingsSeeder::class,
+            //SettingsSeeder::class,
         ]);
     }
 }

+ 0 - 2
database/seeders/Seeds/SettingsSeeder.php

@@ -4,7 +4,6 @@ namespace Database\Seeders\Seeds;
 
 use App\Models\Settings;
 use Illuminate\Database\Seeder;
-use Illuminate\Support\Facades\DB;
 
 class SettingsSeeder extends Seeder
 {
@@ -15,7 +14,6 @@ class SettingsSeeder extends Seeder
      */
     public function run()
     {
-        DB::table('settings_old', 'old')->where('');
         //initials
         Settings::firstOrCreate([
             'key' => 'SETTINGS::USER:INITIAL_CREDITS',

+ 15 - 16
database/settings/2023_02_01_164731_create_general_settings.php

@@ -7,27 +7,26 @@ class CreateGeneralSettings extends SettingsMigration
 {
     public function up(): void
     {
+        $table_exists = DB::table('settings_old')->exists();
+
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('general.credits_display_name', ($this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME') != null) ?: 'Credits');
-        $this->migrator->add('general.initial_user_credits', ($this->getOldValue("SETTINGS::USER:INITIAL_CREDITS") != null) ?: 250);
-        $this->migrator->add('general.initial_server_limit', ($this->getOldValue("SETTINGS::USER:INITIAL_SERVER_LIMIT") != null) ?: 1);
-        $this->migrator->add('general.recaptcha_site_key', ($this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") != null) ?: env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'));
-        $this->migrator->add('general.recaptcha_secret_key', ($this->getOldValue("SETTINGS::RECAPTCHA:SECRET_KEY") != null) ?: env('RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'));
-        $this->migrator->add('general.recaptcha_enabled', ($this->getOldValue("SETTINGS::RECAPTCHA:ENABLED") != null) ?: true);
-        $this->migrator->add('general.phpmyadmin_url', ($this->getOldValue("SETTINGS::MISC:PHPMYADMIN:URL") != null) ?: env('PHPMYADMIN_URL', ''));
-        $this->migrator->add('general.alert_enabled', ($this->getOldValue("SETTINGS::SYSTEM:ALERT_ENABLED") != null) ?: false);
-        $this->migrator->add('general.alert_type', ($this->getOldValue("SETTINGS::SYSTEM:ALERT_TYPE") != null) ?: 'dark');
-        $this->migrator->add('general.alert_message', ($this->getOldValue("SETTINGS::SYSTEM:ALERT_MESSAGE") != null) ?: '');
-        $this->migrator->add('general.theme', ($this->getOldValue("SETTINGS::SYSTEM:THEME") != null) ?: 'default');
+        $this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME') : 'Credits');
+        $this->migrator->add('general.initial_user_credits', $table_exists ? $this->getOldValue("SETTINGS::USER:INITIAL_CREDITS") : 250);
+        $this->migrator->add('general.initial_server_limit', $table_exists ? $this->getOldValue("SETTINGS::USER:INITIAL_SERVER_LIMIT") : 1);
+        $this->migrator->addEncrypted('general.recaptcha_site_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") : env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'));
+        $this->migrator->addEncrypted('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.main_site', '');
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

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

@@ -7,19 +7,18 @@ class CreatePterodactylSettings extends SettingsMigration
 {
     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', ($this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:TOKEN') != null) ?: env('PTERODACTYL_TOKEN', ''));
-        $this->migrator->addEncrypted('pterodactyl.user_token', ($this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN') != null) ?: '');
-        $this->migrator->add('pterodactyl.panel_url', ($this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:URL') != null) ?: env('PTERODACTYL_URL', ''));
-        $this->migrator->add('pterodactyl.per_page_limit', ($this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT') != null) ?: 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.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);
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 12 - 13
database/settings/2023_02_01_181453_create_mail_settings.php

@@ -7,24 +7,23 @@ class CreateMailSettings extends SettingsMigration
 {
     public function up(): void
     {
+        $table_exists = DB::table('settings_old')->exists();
+
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('mail.mail_host', ($this->getOldValue('SETTINGS::MAIL:HOST') != null) ?: env('MAIL_HOST', 'localhost'));
-        $this->migrator->add('mail.mail_port', ($this->getOldValue('SETTINGS::MAIL:PORT') != null) ?: env('MAIL_PORT', '25'));
-        $this->migrator->add('mail.mail_username', ($this->getOldValue('SETTINGS::MAIL:USERNAME') != null) ?: env('MAIL_USERNAME', ''));
-        $this->migrator->addEncrypted('mail.mail_password', ($this->getOldValue('SETTINGS::MAIL:PASSWORD') != null) ?: env('MAIL_PASSWORD', ''));
-        $this->migrator->add('mail.mail_encryption', ($this->getOldValue('SETTINGS::MAIL:ENCRYPTION') != null) ?: env('MAIL_ENCRYPTION', 'tls'));
-        $this->migrator->add('mail.mail_from_address', ($this->getOldValue('SETTINGS::MAIL:FROM_ADDRESS') != null) ?: env('MAIL_FROM_ADDRESS', ''));
-        $this->migrator->add('mail.mail_from_name', ($this->getOldValue('SETTINGS::MAIL:FROM_NAME') != null) ?: env('APP_NAME', 'ControlPanel.gg'));
-        $this->migrator->add('mail.mail_mailer', ($this->getOldValue('SETTINGS::MAIL:MAILER') != null) ?: env('MAIL_MAILER', 'smtp'));
+        $this->migrator->add('mail.mail_host', $table_exists ? $this->getOldValue('SETTINGS::MAIL:HOST') : env('MAIL_HOST', 'localhost'));
+        $this->migrator->add('mail.mail_port', $table_exists ? $this->getOldValue('SETTINGS::MAIL:PORT') : env('MAIL_PORT', '25'));
+        $this->migrator->add('mail.mail_username', $table_exists ? $this->getOldValue('SETTINGS::MAIL:USERNAME') : env('MAIL_USERNAME', ''));
+        $this->migrator->addEncrypted('mail.mail_password', $table_exists ? $this->getOldValue('SETTINGS::MAIL:PASSWORD') : env('MAIL_PASSWORD', ''));
+        $this->migrator->add('mail.mail_encryption', $table_exists ? $this->getOldValue('SETTINGS::MAIL:ENCRYPTION') : env('MAIL_ENCRYPTION', 'tls'));
+        $this->migrator->add('mail.mail_from_address', $table_exists ? $this->getOldValue('SETTINGS::MAIL:FROM_ADDRESS') : env('MAIL_FROM_ADDRESS', ''));
+        $this->migrator->add('mail.mail_from_name', $table_exists ? $this->getOldValue('SETTINGS::MAIL:FROM_NAME') : env('APP_NAME', 'ControlPanel.gg'));
+        $this->migrator->add('mail.mail_mailer', $table_exists ? $this->getOldValue('SETTINGS::MAIL:MAILER') : env('MAIL_MAILER', 'smtp'));
         $this->migrator->add('mail.mail_enabled', true);
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 16 - 17
database/settings/2023_02_01_181925_create_user_settings.php

@@ -7,27 +7,26 @@ class CreateUserSettings extends SettingsMigration
 {
     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', ($this->getOldValue('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD') != null) ?: 250);
-        $this->migrator->add('user.credits_reward_after_verify_email', ($this->getOldValue('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_EMAIL') != null) ?: 250);
-        $this->migrator->add('user.force_discord_verification', ($this->getOldValue('SETTINGS::USER:FORCE_DISCORD_VERIFICATION') != null) ?: false);
-        $this->migrator->add('user.force_email_verification', ($this->getOldValue('SETTINGS::USER:FORCE_EMAIL_VERIFICATION') != null) ?: false);
-        $this->migrator->add('user.initial_credits', ($this->getOldValue('SETTINGS::USER:INITIAL_CREDITS') != null) ?: 250);
-        $this->migrator->add('user.initial_server_limit', ($this->getOldValue('SETTINGS::USER:INITIAL_SERVER_LIMIT') != null) ?: 1);
-        $this->migrator->add('user.min_credits_to_make_server', ($this->getOldValue('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER') != null) ?: 50);
-        $this->migrator->add('user.server_limit_after_irl_purchase', ($this->getOldValue('SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE') != null) ?: 10);
-        $this->migrator->add('user.server_limit_after_verify_discord', ($this->getOldValue('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD') != null) ?: 2);
-        $this->migrator->add('user.server_limit_after_verify_email', ($this->getOldValue('SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL') != null) ?: 2);
-        $this->migrator->add('user.register_ip_check', ($this->getOldValue("SETTINGS::SYSTEM:REGISTER_IP_CHECK") != null) ?: true);
-        $this->migrator->add('user.creation_enabled', ($this->getOldValue("SETTINGS::SYSTEM:CREATION_OF_NEW_USERS") != null) ?: true);
+        $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);
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 7 - 8
database/settings/2023_02_01_181950_create_server_settings.php

@@ -7,18 +7,17 @@ class CreateServerSettings extends SettingsMigration
 {
     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', ($this->getOldValue('SETTINGS::SERVER:ALLOCATION_LIMIT') != null) ?: 200);
-        $this->migrator->add('server.creation_enabled', ($this->getOldValue('SETTINGS::SYSTEM:CREATION_OF_NEW_SERVERS') != null) ?: true);
-        $this->migrator->add('server.enable_upgrade', ($this->getOldValue('SETTINGS::SYSTEM:ENABLE_UPGRADE') != null) ?: false);
+        $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);
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 12 - 13
database/settings/2023_02_01_182021_create_invoice_settings.php

@@ -7,23 +7,22 @@ class CreateInvoiceSettings extends SettingsMigration
 {
     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', ($this->getOldValue('SETTINGS::INVOICE:COMPANY_ADDRESS') != null) ?: null);
-        $this->migrator->add('invoice.company_mail', ($this->getOldValue('SETTINGS::INVOICE:COMPANY_MAIL') != null) ?: null);
-        $this->migrator->add('invoice.company_name', ($this->getOldValue('SETTINGS::INVOICE:COMPANY_NAME') != null) ?: null);
-        $this->migrator->add('invoice.company_phone', ($this->getOldValue('SETTINGS::INVOICE:COMPANY_PHONE') != null) ?: null);
-        $this->migrator->add('invoice.company_vat', ($this->getOldValue('SETTINGS::INVOICE:COMPANY_VAT') != null) ?: null);
-        $this->migrator->add('invoice.company_website', ($this->getOldValue('SETTINGS::INVOICE:COMPANY_WEBSITE') != null) ?: null);
-        $this->migrator->add('invoice.enabled', ($this->getOldValue('SETTINGS::INVOICE:ENABLED') != null) ?: true);
-        $this->migrator->add('invoice.prefix', ($this->getOldValue('SETTINGS::INVOICE:PREFIX') != null) ?: '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'): true);
+        $this->migrator->add('invoice.prefix', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:PREFIX'): 'INV');
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 10 - 11
database/settings/2023_02_01_182043_create_discord_settings.php

@@ -7,21 +7,20 @@ class CreateDiscordSettings extends SettingsMigration
 {
     public function up(): void
     {
+        $table_exists = DB::table('settings_old')->exists();
+
         // Get the user-set configuration values from the old table.
-        $this->migrator->addEncrypted('discord.bot_token', ($this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN') != null) ?: null);
-        $this->migrator->addEncrypted('discord.client_id', ($this->getOldValue('SETTINGS::DISCORD:CLIENT_ID') != null) ?: null);
-        $this->migrator->addEncrypted('discord.client_secret', ($this->getOldValue('SETTINGS::DISCORD:CLIENT_SECRET') != null) ?: null);
-        $this->migrator->add('discord.guild_id', ($this->getOldValue('SETTINGS::DISCORD:GUILD_ID') != null) ?: null);
-        $this->migrator->add('discord.invite_url', ($this->getOldValue('SETTINGS::DISCORD:INVITE_URL') != null) ?: null);
-        $this->migrator->add('discord.role_id', ($this->getOldValue('SETTINGS::DISCORD:ROLE_ID') != null) ?: null);
+        $this->migrator->addEncrypted('discord.bot_token', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN'): null);
+        $this->migrator->addEncrypted('discord.client_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_ID'): null);
+        $this->migrator->addEncrypted('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 getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 9 - 10
database/settings/2023_02_01_182108_create_locale_settings.php

@@ -7,20 +7,19 @@ class CreateLocaleSettings extends SettingsMigration
 {
     public function up(): void
     {
+        $table_exists = DB::table('settings_old')->exists();
+
         // Get the user-set configuration values from the old table.
-        $this->migrator->add('locale.available', ($this->getOldValue('SETTINGS::LOCALE:AVAILABLE') != null) ?: '');
-        $this->migrator->add('locale.clients_can_change', ($this->getOldValue('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') != null) ?: true);
-        $this->migrator->add('locale.datatables', ($this->getOldValue('SETTINGS::LOCALE:DATATABLES') != null) ?: 'en-gb');
-        $this->migrator->add('locale.default', ($this->getOldValue('SETTINGS::LOCALE:DEFAULT') != null) ?: 'en');
-        $this->migrator->add('locale.dynamic', ($this->getOldValue('SETTINGS::LOCALE:DYNAMIC') != null) ?: false);
+        $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.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);
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 10 - 11
database/settings/2023_02_01_182135_create_referral_settings.php

@@ -7,21 +7,20 @@ class CreateReferralSettings extends SettingsMigration
 {
     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.allowed', ($this->getOldValue('SETTINGS::REFERRAL::ALLOWED') != null) ?: 'client');
-        $this->migrator->add('referral.always_give_commission', ($this->getOldValue('SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION') != null) ?: false);
-        $this->migrator->add('referral.enabled', ($this->getOldValue('SETTINGS::REFERRAL::ENABLED') != null) ?: false);
-        $this->migrator->add('referral.reward', ($this->getOldValue('SETTINGS::REFERRAL::REWARD') != null) ?: 100);
-        $this->migrator->add('referral.mode', ($this->getOldValue('SETTINGS::REFERRAL:MODE') != null) ?: 'sign-up');
-        $this->migrator->add('referral.percentage', ($this->getOldValue('SETTINGS::REFERRAL:PERCENTAGE') != null) ?: 100);
+        $this->migrator->add('referral.allowed', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL::ALLOWED') : 'client');
+        $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.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);
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }

+ 12 - 13
database/settings/2023_02_01_182158_create_website_settings.php

@@ -7,29 +7,28 @@ class CreateWebsiteSettings extends SettingsMigration
 {
     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', ($this->getOldValue("SETTINGS::SYSTEM:MOTD_ENABLED") != null) ?: true);
-        $this->migrator->add('website.motd_message', ($this->getOldValue("SETTINGS::SYSTEM:MOTD_MESSAGE") != null) ?:
+        $this->migrator->add('website.motd_enabled', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_ENABLED") : 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://controlpanel.gg/img/controlpanel.png" alt="" width="200" height="200"><span style="font-size: 36pt;">Controlpanel.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', ($this->getOldValue("SETTINGS::SYSTEM:SHOW_IMPRINT") != null) ?: false);
-        $this->migrator->add('website.show_privacy', ($this->getOldValue("SETTINGS::SYSTEM:SHOW_PRIVACY") != null) ?: false);
-        $this->migrator->add('website.show_tos', ($this->getOldValue("SETTINGS::SYSTEM:SHOW_TOS") != null) ?: false);
-        $this->migrator->add('website.useful_links_enabled', ($this->getOldValue("SETTINGS::SYSTEM:USEFULLINKS_ENABLED") != null) ?: true);
-        $this->migrator->add('website.seo_title', ($this->getOldValue("SETTINGS::SYSTEM:SEO_TITLE") != null) ?: 'ControlPanel.gg');
-        $this->migrator->add('website.seo_description', ($this->getOldValue("SETTINGS::SYSTEM:SEO_DESCRIPTION") != null) ?: 'Billing software for Pterodactyl Panel.');
+        $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);
+        $this->migrator->add('website.seo_title', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SEO_TITLE") : 'ControlPanel.gg');
+        $this->migrator->add('website.seo_description', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:SEO_DESCRIPTION") : 'Billing software for Pterodactyl Panel.');
     
     }
 
     public function getOldValue(string $key)
     {
-        if (DB::table('settings_old')->exists()) {
-            return DB::table('settings_old')->where('key', '=', $key)->get(['value']);
-        }
-
-        return null;
+        // Always get the first value of the key.
+        return DB::table('settings_old')->where('key', '=', $key)->get(['value'])->first()->value;
     }
 }