diff --git a/database/migrations/2023_02_01_155140_rename_settings_table.php b/database/migrations/2023_02_01_155140_rename_settings_table.php index 89f0995a..7bdb5f7f 100644 --- a/database/migrations/2023_02_01_155140_rename_settings_table.php +++ b/database/migrations/2023_02_01_155140_rename_settings_table.php @@ -15,7 +15,7 @@ return new class extends Migration public function down() { - Schema::table('settings', function (Blueprint $table) { + Schema::table('settings_old', function (Blueprint $table) { $table->rename("settings"); }); } diff --git a/database/migrations/2023_02_13_150022_delete_old_settings_table.php b/database/migrations/2023_02_13_150022_delete_old_settings_table.php new file mode 100644 index 00000000..b7b9c347 --- /dev/null +++ b/database/migrations/2023_02_13_150022_delete_old_settings_table.php @@ -0,0 +1,34 @@ +string('key', 191); + $table->text('value')->nullable(); + $table->string('type'); + $table->longText('description'); + $table->timestamps(); + }); + } +}; 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 8fdb2e6a..f5c23dc0 100644 --- a/database/settings/2023_02_01_164731_create_general_settings.php +++ b/database/settings/2023_02_01_164731_create_general_settings.php @@ -24,6 +24,52 @@ class CreateGeneralSettings extends SettingsMigration $this->migrator->add('general.main_site', ''); } + public function down(): void + { + $table_exists = DB::table('settings')->exists(); + + 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 + ], + ]); + } + } + + 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; + } + + return $new_value->payload; + } + public function getOldValue(string $key) { // Always get the first value of the key.