From d6573b9bfda0aa44e03864bc3e44020d91408140 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sun, 19 Feb 2023 00:34:26 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=97=83=EF=B8=8F=20Add=20settings?= =?UTF-8?q?=20migrations=20down=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3_02_01_164731_create_general_settings.php | 69 +++++---- ..._01_181334_create_pterodactyl_settings.php | 51 ++++++- ...2023_02_01_181453_create_mail_settings.php | 84 ++++++++++- ...2023_02_01_181925_create_user_settings.php | 134 ++++++++++++++++-- ...23_02_01_181950_create_server_settings.php | 57 +++++++- ...3_02_01_182021_create_invoice_settings.php | 93 ++++++++++-- ...3_02_01_182043_create_discord_settings.php | 76 +++++++++- ...23_02_01_182108_create_locale_settings.php | 66 ++++++++- ..._02_01_182135_create_referral_settings.php | 63 +++++++- ...3_02_01_182158_create_website_settings.php | 90 +++++++++++- ...23_02_04_181156_create_ticket_settings.php | 34 ++++- 11 files changed, 739 insertions(+), 78 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 f5c23dc0..66525c30 100644 --- a/database/settings/2023_02_01_164731_create_general_settings.php +++ b/database/settings/2023_02_01_164731_create_general_settings.php @@ -26,36 +26,45 @@ class CreateGeneralSettings extends SettingsMigration public function down(): void { - $table_exists = DB::table('settings')->exists(); + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME', + 'value' => $this->getNewValue('credits_display_name'), + 'type' => 'string', + 'description' => 'The name of the credits on the panel.' + ], + [ + 'key' => 'SETTINGS::SYSTEM:ALERT_ENABLED', + 'value' => $this->getNewValue('alert_enabled'), + 'type' => 'boolean', + 'description' => 'Enable the alert at the top of the panel.' + ], + [ + 'key' => 'SETTINGS::SYSTEM:ALERT_TYPE', + 'value' => $this->getNewValue('alert_type'), + 'type' => 'string', + 'description' => 'The type of alert to display.' + ], + [ + 'key' => 'SETTINGS::SYSTEM:ALERT_MESSAGE', + 'value' => $this->getNewValue('alert_message'), + 'type' => 'text', + 'description' => 'The message to display in the alert.' + ], + ]); - if ($table_exists) { - DB::table('settings')->insert([ - [ - 'key' => 'SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME', - 'value' => $this->getNewValue('credits_display_name'), - 'type' => 'string', - 'description' => null - ], - [ - 'key' => 'SETTINGS::SYSTEM:ALERT_ENABLED', - 'value' => $this->getNewValue('alert_enabled'), - 'type' => 'boolean', - 'description' => null - ], - [ - 'key' => 'SETTINGS::SYSTEM:ALERT_TYPE', - 'value' => $this->getNewValue('alert_type'), - 'type' => 'string', - 'description' => null - ], - [ - 'key' => 'SETTINGS::SYSTEM:ALERT_MESSAGE', - 'value' => $this->getNewValue('alert_message'), - 'type' => 'text', - 'description' => null - ], - ]); - } + $this->migrator->delete('general.credits_display_name'); + $this->migrator->delete('general.initial_user_credits'); + $this->migrator->delete('general.initial_server_limit'); + $this->migrator->delete('general.recaptcha_site_key'); + $this->migrator->delete('general.recaptcha_secret_key'); + $this->migrator->delete('general.recaptcha_enabled'); + $this->migrator->delete('general.phpmyadmin_url'); + $this->migrator->delete('general.alert_enabled'); + $this->migrator->delete('general.alert_type'); + $this->migrator->delete('general.alert_message'); + $this->migrator->delete('general.theme'); + $this->migrator->delete('general.main_site'); } public function getNewValue(string $name) @@ -95,4 +104,4 @@ class CreateGeneralSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 17fdc0c5..e96367ad 100644 --- a/database/settings/2023_02_01_181334_create_pterodactyl_settings.php +++ b/database/settings/2023_02_01_181334_create_pterodactyl_settings.php @@ -16,6 +16,55 @@ class CreatePterodactylSettings extends SettingsMigration $this->migrator->add('pterodactyl.per_page_limit', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT') : 200); } + public function down(): void + { + + + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN', + 'value' => $this->getNewValue('admin_token'), + 'type' => 'string', + 'description' => 'The admin token for the Pterodactyl panel.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN', + 'value' => $this->getNewValue('user_token'), + 'type' => 'string', + 'description' => 'The user token for the Pterodactyl panel.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:URL', + 'value' => $this->getNewValue('panel_url'), + 'type' => 'string', + 'description' => 'The URL for the Pterodactyl panel.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:PTERODACTYL:PER_PAGE_LIMIT', + 'value' => $this->getNewValue('per_page_limit'), + 'type' => 'integer', + 'description' => 'The number of servers to show per page.', + ], + ]); + + $this->migrator->delete('pterodactyl.admin_token'); + $this->migrator->delete('pterodactyl.user_token'); + $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; + } + + return $new_value->payload; + } + public function getOldValue(string $key) { // Always get the first value of the key. @@ -41,4 +90,4 @@ class CreatePterodactylSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 cf89f0bb..606375db 100644 --- a/database/settings/2023_02_01_181453_create_mail_settings.php +++ b/database/settings/2023_02_01_181453_create_mail_settings.php @@ -21,6 +21,88 @@ class CreateMailSettings extends SettingsMigration $this->migrator->add('mail.mail_enabled', true); } + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::MAIL:HOST', + 'value' => $this->getNewValue('mail_host'), + 'type' => 'string', + 'description' => 'The host of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:PORT', + 'value' => $this->getNewValue('mail_port'), + 'type' => 'integer', + 'description' => 'The port of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:USERNAME', + 'value' => $this->getNewValue('mail_username'), + 'type' => 'string', + 'description' => 'The username of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:PASSWORD', + 'value' => $this->getNewValue('mail_password'), + 'type' => 'string', + 'description' => 'The password of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:ENCRYPTION', + 'value' => $this->getNewValue('mail_encryption'), + 'type' => 'string', + 'description' => 'The encryption of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:FROM_ADDRESS', + 'value' => $this->getNewValue('mail_from_address'), + 'type' => 'string', + 'description' => 'The from address of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:FROM_NAME', + 'value' => $this->getNewValue('mail_from_name'), + 'type' => 'string', + 'description' => 'The from name of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:MAILER', + 'value' => $this->getNewValue('mail_mailer'), + 'type' => 'string', + 'description' => 'The mailer of the mail server.', + ], + [ + 'key' => 'SETTINGS::MAIL:ENABLED', + 'value' => $this->getNewValue('mail_enabled'), + 'type' => 'boolean', + 'description' => 'The enabled state of the mail server.', + ], + ]); + + $this->migrator->delete('mail.mail_host'); + $this->migrator->delete('mail.mail_port'); + $this->migrator->delete('mail.mail_username'); + $this->migrator->delete('mail.mail_password'); + $this->migrator->delete('mail.mail_encryption'); + $this->migrator->delete('mail.mail_from_address'); + $this->migrator->delete('mail.mail_from_name'); + $this->migrator->delete('mail.mail_mailer'); + $this->migrator->delete('mail.mail_enabled'); + } + + + 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; + } + + return $new_value->payload; + } public function getOldValue(string $key) { // Always get the first value of the key. @@ -46,4 +128,4 @@ class CreateMailSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 a108edc9..83afe791 100644 --- a/database/settings/2023_02_01_181925_create_user_settings.php +++ b/database/settings/2023_02_01_181925_create_user_settings.php @@ -8,20 +8,126 @@ 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', $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); + $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 down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD', + 'value' => $this->getNewValue('credits_reward_after_verify_discord'), + 'type' => 'integer', + 'description' => 'The amount of credits that the user will receive after verifying their Discord account.', + ], + [ + 'key' => 'SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_EMAIL', + 'value' => $this->getNewValue('credits_reward_after_verify_email'), + 'type' => 'integer', + 'description' => 'The amount of credits that the user will receive after verifying their email.', + + ], + [ + 'key' => 'SETTINGS::USER:FORCE_DISCORD_VERIFICATION', + 'value' => $this->getNewValue('force_discord_verification'), + 'type' => 'boolean', + 'description' => 'If the user must verify their Discord account to use the panel.', + ], + [ + 'key' => 'SETTINGS::USER:FORCE_EMAIL_VERIFICATION', + 'value' => $this->getNewValue('force_email_verification'), + 'type' => 'boolean', + 'description' => 'If the user must verify their email to use the panel.', + + ], + [ + 'key' => 'SETTINGS::USER:INITIAL_CREDITS', + 'value' => $this->getNewValue('initial_credits'), + 'type' => 'integer', + 'description' => 'The amount of credits that the user will receive when they register.', + ], + [ + 'key' => 'SETTINGS::USER:INITIAL_SERVER_LIMIT', + 'value' => $this->getNewValue('initial_server_limit'), + 'type' => 'integer', + 'description' => 'The amount of servers that the user will be able to create when they register.', + ], + [ + 'key' => 'SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', + 'value' => $this->getNewValue('min_credits_to_make_server'), + 'type' => 'integer', + 'description' => 'The minimum amount of credits that the user must have to create a server.', + ], + [ + 'key' => 'SETTINGS::USER:SERVER_LIMIT_AFTER_IRL_PURCHASE', + 'value' => $this->getNewValue('server_limit_after_irl_purchase'), + 'type' => 'integer', + 'description' => 'The amount of servers that the user will be able to create after making a real purchase.', + ], + [ + 'key' => 'SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD', + 'value' => $this->getNewValue('server_limit_after_verify_discord'), + 'type' => 'integer', + 'description' => 'The amount of servers that the user will be able to create after verifying their Discord account.', + + ], + [ + 'key' => 'SETTINGS::USER:SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL', + 'value' => $this->getNewValue('server_limit_after_verify_email'), + 'type' => 'integer', + 'description' => 'The amount of servers that the user will be able to create after verifying their email.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:REGISTER_IP_CHECK', + 'value' => $this->getNewValue('register_ip_check'), + 'type' => 'boolean', + 'description' => 'If the user must verify their IP address to register.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:CREATION_OF_NEW_USERS', + 'value' => $this->getNewValue('creation_enabled'), + 'type' => 'boolean', + 'description' => 'If the user can register.', + ], + ]); + + $this->migrator->delete('user.credits_reward_after_verify_discord'); + $this->migrator->delete('user.credits_reward_after_verify_email'); + $this->migrator->delete('user.force_discord_verification'); + $this->migrator->delete('user.force_email_verification'); + $this->migrator->delete('user.initial_credits'); + $this->migrator->delete('user.initial_server_limit'); + $this->migrator->delete('user.min_credits_to_make_server'); + $this->migrator->delete('user.server_limit_after_irl_purchase'); + $this->migrator->delete('user.server_limit_after_verify_discord'); + $this->migrator->delete('user.server_limit_after_verify_email'); + $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; + } + + return $new_value->payload; } public function getOldValue(string $key) @@ -49,4 +155,4 @@ class CreateUserSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 98f20c26..34a7ed38 100644 --- a/database/settings/2023_02_01_181950_create_server_settings.php +++ b/database/settings/2023_02_01_181950_create_server_settings.php @@ -10,10 +10,57 @@ class CreateServerSettings extends SettingsMigration $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.charge_first_hour', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:SERVER_CREATE_CHARGE_FIRST_HOUR'): 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); + $this->migrator->add('server.charge_first_hour', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:SERVER_CREATE_CHARGE_FIRST_HOUR') : false); + } + + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::SERVER:ALLOCATION_LIMIT', + 'value' => $this->getNewValue('allocation_limit'), + 'type' => 'integer', + 'description' => 'The number of servers to show per page.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:CREATION', + 'value' => $this->getNewValue('creation_enabled'), + 'type' => 'boolean', + 'description' => 'Whether or not users can create new servers.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:ENABLE_UPGRADE', + 'value' => $this->getNewValue('enable_upgrade'), + 'type' => 'boolean', + 'description' => 'Whether or not users can upgrade their servers.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:SERVER_CREATE_CHARGE_FIRST_HOUR', + 'value' => $this->getNewValue('charge_first_hour'), + 'type' => 'boolean', + 'description' => 'Whether or not to charge the user for the first hour of their server.', + ], + ]); + + $this->migrator->delete('server.allocation_limit'); + $this->migrator->delete('server.creation_enabled'); + $this->migrator->delete('server.enable_upgrade'); + $this->migrator->delete('server.charge_first_hour'); + } + + 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; + } + + return $new_value->payload; } public function getOldValue(string $key) @@ -41,4 +88,4 @@ class CreateServerSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 15945f55..ae420800 100644 --- a/database/settings/2023_02_01_182021_create_invoice_settings.php +++ b/database/settings/2023_02_01_182021_create_invoice_settings.php @@ -10,14 +10,89 @@ class CreateInvoiceSettings extends SettingsMigration $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'): true); - $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') : ''); + $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') : true); + $this->migrator->add('invoice.prefix', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:PREFIX') : 'INV'); + } + + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::INVOICE:COMPANY_ADDRESS', + 'value' => $this->getNewValue('company_address'), + 'type' => 'string', + 'description' => 'The address of the company.', + ], + [ + 'key' => 'SETTINGS::INVOICE:COMPANY_MAIL', + 'value' => $this->getNewValue('company_mail'), + 'type' => 'string', + 'description' => 'The email address of the company.', + ], + [ + 'key' => 'SETTINGS::INVOICE:COMPANY_NAME', + 'value' => $this->getNewValue('company_name'), + 'type' => 'string', + 'description' => 'The name of the company.', + ], + [ + 'key' => 'SETTINGS::INVOICE:COMPANY_PHONE', + 'value' => $this->getNewValue('company_phone'), + 'type' => 'string', + 'description' => 'The phone number of the company.', + ], + [ + 'key' => 'SETTINGS::INVOICE:COMPANY_VAT', + 'value' => $this->getNewValue('company_vat'), + 'type' => 'string', + 'description' => 'The VAT number of the company.', + ], + [ + 'key' => 'SETTINGS::INVOICE:COMPANY_WEBSITE', + 'value' => $this->getNewValue('company_website'), + 'type' => 'string', + 'description' => 'The website of the company.', + ], + [ + 'key' => 'SETTINGS::INVOICE:ENABLED', + 'value' => $this->getNewValue('enabled'), + 'type' => 'boolean', + 'description' => 'Enable or disable the invoice system.', + ], + [ + 'key' => 'SETTINGS::INVOICE:PREFIX', + 'value' => $this->getNewValue('prefix'), + 'type' => 'string', + 'description' => 'The prefix of the invoice.', + ], + ]); + + $this->migrator->delete('invoice.company_address'); + $this->migrator->delete('invoice.company_mail'); + $this->migrator->delete('invoice.company_name'); + $this->migrator->delete('invoice.company_phone'); + $this->migrator->delete('invoice.company_vat'); + $this->migrator->delete('invoice.company_website'); + $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; + } + + return $new_value->payload; } public function getOldValue(string $key) @@ -45,4 +120,4 @@ class CreateInvoiceSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 e83797a8..8514a48b 100644 --- a/database/settings/2023_02_01_182043_create_discord_settings.php +++ b/database/settings/2023_02_01_182043_create_discord_settings.php @@ -10,12 +10,74 @@ class CreateDiscordSettings extends SettingsMigration $table_exists = DB::table('settings_old')->exists(); // Get the user-set configuration values from the old table. - $this->migrator->addEncrypted('discord.bot_token', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN'): ''); - $this->migrator->addEncrypted('discord.client_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_ID'): ''); - $this->migrator->addEncrypted('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->addEncrypted('discord.bot_token', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:BOT_TOKEN') : ''); + $this->migrator->addEncrypted('discord.client_id', $table_exists ? $this->getOldValue('SETTINGS::DISCORD:CLIENT_ID') : ''); + $this->migrator->addEncrypted('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') : ''); + } + + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::DISCORD:BOT_TOKEN', + 'value' => $this->getNewValue('bot_token'), + 'type' => 'string', + 'description' => 'The bot token for the Discord bot.', + ], + [ + 'key' => 'SETTINGS::DISCORD:CLIENT_ID', + 'value' => $this->getNewValue('client_id'), + 'type' => 'string', + 'description' => 'The client ID for the Discord bot.', + + ], + [ + 'key' => 'SETTINGS::DISCORD:CLIENT_SECRET', + 'value' => $this->getNewValue('client_secret'), + 'type' => 'string', + 'description' => 'The client secret for the Discord bot.', + ], + [ + 'key' => 'SETTINGS::DISCORD:GUILD_ID', + 'value' => $this->getNewValue('guild_id'), + 'type' => 'string', + 'description' => 'The guild ID for the Discord bot.', + ], + [ + 'key' => 'SETTINGS::DISCORD:INVITE_URL', + 'value' => $this->getNewValue('invite_url'), + 'type' => 'string', + 'description' => 'The invite URL for the Discord bot.', + ], + [ + 'key' => 'SETTINGS::DISCORD:ROLE_ID', + 'value' => $this->getNewValue('role_id'), + 'type' => 'string', + 'description' => 'The role ID for the Discord bot.', + ] + ]); + + $this->migrator->delete('discord.bot_token'); + $this->migrator->delete('discord.client_id'); + $this->migrator->delete('discord.client_secret'); + $this->migrator->delete('discord.guild_id'); + $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; + } + + return $new_value->payload; } public function getOldValue(string $key) @@ -43,4 +105,4 @@ class CreateDiscordSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 ff9e0bf0..ade120e2 100644 --- a/database/settings/2023_02_01_182108_create_locale_settings.php +++ b/database/settings/2023_02_01_182108_create_locale_settings.php @@ -10,11 +10,65 @@ class CreateLocaleSettings extends SettingsMigration $table_exists = DB::table('settings_old')->exists(); // 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.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.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 down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::LOCALE:AVAILABLE', + 'value' => $this->getNewValue('available'), + 'type' => 'string', + 'description' => 'The available locales.', + ], + [ + 'key' => 'SETTINGS::LOCALE:CLIENTS_CAN_CHANGE', + 'value' => $this->getNewValue('clients_can_change'), + 'type' => 'boolean', + 'description' => 'If clients can change their locale.', + ], + [ + 'key' => 'SETTINGS::LOCALE:DATATABLES', + 'value' => $this->getNewValue('datatables'), + 'type' => 'string', + 'description' => 'The locale for datatables.', + ], + [ + 'key' => 'SETTINGS::LOCALE:DEFAULT', + 'value' => $this->getNewValue('default'), + 'type' => 'string', + 'description' => 'The default locale.', + ], + [ + 'key' => 'SETTINGS::LOCALE:DYNAMIC', + 'value' => $this->getNewValue('dynamic'), + 'type' => 'boolean', + 'description' => 'If the locale should be dynamic.', + ], + ]); + + $this->migrator->delete('locale.available'); + $this->migrator->delete('locale.clients_can_change'); + $this->migrator->delete('locale.datatables'); + $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; + } + + return $new_value->payload; } public function getOldValue(string $key) @@ -42,4 +96,4 @@ class CreateLocaleSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 8ee55dce..52a254b9 100644 --- a/database/settings/2023_02_01_182135_create_referral_settings.php +++ b/database/settings/2023_02_01_182135_create_referral_settings.php @@ -18,6 +18,67 @@ class CreateReferralSettings extends SettingsMigration $this->migrator->add('referral.percentage', $table_exists ? $this->getOldValue('SETTINGS::REFERRAL:PERCENTAGE') : 100); } + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::REFERRAL::ALLOWED', + 'value' => $this->getNewValue('allowed'), + 'type' => 'string', + 'description' => 'The allowed referral types.', + ], + [ + 'key' => 'SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION', + 'value' => $this->getNewValue('always_give_commission'), + 'type' => 'boolean', + 'description' => 'Whether to always give commission to the referrer.', + ], + [ + 'key' => 'SETTINGS::REFERRAL::ENABLED', + 'value' => $this->getNewValue('enabled'), + 'type' => 'boolean', + 'description' => 'Whether to enable the referral system.', + ], + [ + 'key' => 'SETTINGS::REFERRAL::REWARD', + 'value' => $this->getNewValue('reward'), + 'type' => 'integer', + 'description' => 'The reward for the referral.', + ], + [ + 'key' => 'SETTINGS::REFERRAL:MODE', + 'value' => $this->getNewValue('mode'), + 'type' => 'string', + 'description' => 'The referral mode.', + ], + [ + 'key' => 'SETTINGS::REFERRAL:PERCENTAGE', + 'value' => $this->getNewValue('percentage'), + 'type' => 'integer', + 'description' => 'The referral percentage.', + ], + ]); + + $this->migrator->delete('referral.allowed'); + $this->migrator->delete('referral.always_give_commission'); + $this->migrator->delete('referral.enabled'); + $this->migrator->delete('referral.reward'); + $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; + } + + return $new_value->payload; + } + public function getOldValue(string $key) { // Always get the first value of the key. @@ -43,4 +104,4 @@ class CreateReferralSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 e241fcb9..26f99f8b 100644 --- a/database/settings/2023_02_01_182158_create_website_settings.php +++ b/database/settings/2023_02_01_182158_create_website_settings.php @@ -11,8 +11,10 @@ class CreateWebsiteSettings extends SettingsMigration // 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_message', $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_MESSAGE") : - '

Controlpanel.gg

+ $this->migrator->add( + 'website.motd_message', + $table_exists ? $this->getOldValue("SETTINGS::SYSTEM:MOTD_MESSAGE") : + '

Controlpanel.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 )

' @@ -26,6 +28,88 @@ class CreateWebsiteSettings extends SettingsMigration $this->migrator->add('website.enable_login_logo', true); } + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::SYSTEM:MOTD_ENABLED', + 'value' => $this->getNewValue('motd_enabled'), + 'type' => 'boolean', + 'description' => 'Enable or disable the MOTD.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:MOTD_MESSAGE', + 'value' => $this->getNewValue('motd_message'), + 'type' => 'text', + 'description' => 'The message that will be displayed in the MOTD.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:SHOW_IMPRINT', + 'value' => $this->getNewValue('show_imprint'), + 'type' => 'boolean', + 'description' => 'Enable or disable the imprint.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:SHOW_PRIVACY', + 'value' => $this->getNewValue('show_privacy'), + 'type' => 'boolean', + 'description' => 'Enable or disable the privacy policy.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:SHOW_TOS', + 'value' => $this->getNewValue('show_tos'), + 'type' => 'boolean', + 'description' => 'Enable or disable the terms of service.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:USEFULLINKS_ENABLED', + 'value' => $this->getNewValue('useful_links_enabled'), + 'type' => 'boolean', + 'description' => 'Enable or disable the useful links.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:SEO_TITLE', + 'value' => $this->getNewValue('seo_title'), + 'type' => 'string', + 'description' => 'The title of the website.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:SEO_DESCRIPTION', + 'value' => $this->getNewValue('seo_description'), + 'type' => 'string', + 'description' => 'The description of the website.', + ], + [ + 'key' => 'SETTINGS::SYSTEM:ENABLE_LOGIN_LOGO', + 'value' => $this->getNewValue('enable_login_logo'), + 'type' => 'boolean', + 'description' => 'Enable or disable the login logo.', + ] + ]); + + $this->migrator->delete('website.motd_enabled'); + $this->migrator->delete('website.motd_message'); + $this->migrator->delete('website.show_imprint'); + $this->migrator->delete('website.show_privacy'); + $this->migrator->delete('website.show_tos'); + $this->migrator->delete('website.useful_links_enabled'); + $this->migrator->delete('website.seo_title'); + $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; + } + + return $new_value->payload; + } + public function getOldValue(string $key) { // Always get the first value of the key. @@ -51,4 +135,4 @@ class CreateWebsiteSettings extends SettingsMigration return filter_var($old_value->value, FILTER_VALIDATE_INT); } -} \ No newline at end of file +} 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 2601ccd7..ac701cee 100644 --- a/database/settings/2023_02_04_181156_create_ticket_settings.php +++ b/database/settings/2023_02_04_181156_create_ticket_settings.php @@ -10,9 +10,41 @@ class CreateTicketSettings extends SettingsMigration $table_exists = DB::table('settings_old')->exists(); // Get the user-set configuration values from the old table. - $this->migrator->add('ticket.enabled', true); + $this->migrator->add('ticket.enabled', $table_exists ? $this->getOldValue('SETTINGS::TICKET:ENABLED') : 'all'); $this->migrator->add('ticket.notify', $table_exists ? $this->getOldValue('SETTINGS::TICKET:NOTIFY') : 'all'); + } + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::TICKET:NOTIFY', + 'value' => $this->getNewValue('notify'), + 'type' => 'string', + 'description' => 'The notification type for tickets.', + ], + [ + 'key' => 'SETTINGS::TICKET:ENABLED', + 'value' => $this->getNewValue('enabled'), + 'type' => 'boolean', + 'description' => 'Enable or disable the ticket system.', + ] + ]); + + $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; + } + + return $new_value->payload; } public function getOldValue(string $key)