From 48cce11ebc776fc71f3d32009fc6e01821b89d26 Mon Sep 17 00:00:00 2001 From: IceToast Date: Fri, 12 Apr 2024 14:04:26 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Use=20LegacySett?= =?UTF-8?q?ingsMigration=20&&=20mind=20nullable=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3_02_01_164731_create_general_settings.php | 61 +++------------- ..._01_181334_create_pterodactyl_settings.php | 60 +++------------- ...2023_02_01_181453_create_mail_settings.php | 47 +----------- ...2023_02_01_181925_create_user_settings.php | 71 ++++--------------- ...23_02_01_181950_create_server_settings.php | 53 ++------------ ...3_02_01_182021_create_invoice_settings.php | 63 +++------------- ...3_02_01_182043_create_discord_settings.php | 59 +++------------ ...23_02_01_182108_create_locale_settings.php | 53 ++------------ ..._02_01_182135_create_referral_settings.php | 55 ++------------ ...3_02_01_182158_create_website_settings.php | 60 +++------------- ...23_02_04_181156_create_ticket_settings.php | 52 +------------- 11 files changed, 78 insertions(+), 556 deletions(-) diff --git a/database/settings/2023_02_01_164731_create_general_settings.php b/database/settings/2023_02_01_164731_create_general_settings.php index 5d183590..5e7360dc 100644 --- a/database/settings/2023_02_01_164731_create_general_settings.php +++ b/database/settings/2023_02_01_164731_create_general_settings.php @@ -1,9 +1,9 @@ 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); - } } diff --git a/database/settings/2023_02_01_181334_create_pterodactyl_settings.php b/database/settings/2023_02_01_181334_create_pterodactyl_settings.php index 9ab9d72f..d8f65248 100644 --- a/database/settings/2023_02_01_181334_create_pterodactyl_settings.php +++ b/database/settings/2023_02_01_181334_create_pterodactyl_settings.php @@ -1,21 +1,20 @@ 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); - } } diff --git a/database/settings/2023_02_01_181453_create_mail_settings.php b/database/settings/2023_02_01_181453_create_mail_settings.php index 8437a61a..42ab0f4b 100644 --- a/database/settings/2023_02_01_181453_create_mail_settings.php +++ b/database/settings/2023_02_01_181453_create_mail_settings.php @@ -1,9 +1,9 @@ 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); - } } diff --git a/database/settings/2023_02_01_181925_create_user_settings.php b/database/settings/2023_02_01_181925_create_user_settings.php index 524ef0b7..8c9e088b 100644 --- a/database/settings/2023_02_01_181925_create_user_settings.php +++ b/database/settings/2023_02_01_181925_create_user_settings.php @@ -1,27 +1,27 @@ 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); - } } diff --git a/database/settings/2023_02_01_181950_create_server_settings.php b/database/settings/2023_02_01_181950_create_server_settings.php index 7198adcb..de25c94f 100644 --- a/database/settings/2023_02_01_181950_create_server_settings.php +++ b/database/settings/2023_02_01_181950_create_server_settings.php @@ -1,18 +1,18 @@ 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); - } } diff --git a/database/settings/2023_02_01_182021_create_invoice_settings.php b/database/settings/2023_02_01_182021_create_invoice_settings.php index 8569c3ff..effc67d7 100644 --- a/database/settings/2023_02_01_182021_create_invoice_settings.php +++ b/database/settings/2023_02_01_182021_create_invoice_settings.php @@ -1,23 +1,23 @@ 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); - } } diff --git a/database/settings/2023_02_01_182043_create_discord_settings.php b/database/settings/2023_02_01_182043_create_discord_settings.php index 60e450b9..21ccc5b6 100644 --- a/database/settings/2023_02_01_182043_create_discord_settings.php +++ b/database/settings/2023_02_01_182043_create_discord_settings.php @@ -1,21 +1,21 @@ 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); - } } diff --git a/database/settings/2023_02_01_182108_create_locale_settings.php b/database/settings/2023_02_01_182108_create_locale_settings.php index 014dd8fd..13dbde9d 100644 --- a/database/settings/2023_02_01_182108_create_locale_settings.php +++ b/database/settings/2023_02_01_182108_create_locale_settings.php @@ -1,9 +1,9 @@ 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); - } } diff --git a/database/settings/2023_02_01_182135_create_referral_settings.php b/database/settings/2023_02_01_182135_create_referral_settings.php index 5727557b..839f0e28 100644 --- a/database/settings/2023_02_01_182135_create_referral_settings.php +++ b/database/settings/2023_02_01_182135_create_referral_settings.php @@ -1,20 +1,20 @@ 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); - } } diff --git a/database/settings/2023_02_01_182158_create_website_settings.php b/database/settings/2023_02_01_182158_create_website_settings.php index fd542ff3..2bbdd5b5 100644 --- a/database/settings/2023_02_01_182158_create_website_settings.php +++ b/database/settings/2023_02_01_182158_create_website_settings.php @@ -1,27 +1,28 @@ 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") : "

 width=CtrlPanel.gg

Thank you for using our Software

If you have any questions, make sure to join our Discord

-

(you can change this message in the Settings )

"); - $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); +

(you can change this message in the Settings )

" + ); + $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); - } } diff --git a/database/settings/2023_02_04_181156_create_ticket_settings.php b/database/settings/2023_02_04_181156_create_ticket_settings.php index 1e71ad3a..41eefe73 100644 --- a/database/settings/2023_02_04_181156_create_ticket_settings.php +++ b/database/settings/2023_02_04_181156_create_ticket_settings.php @@ -1,9 +1,9 @@ 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); - } }