Insert the roolback for the old method.

This commit is contained in:
Ferks-FK 2023-02-13 16:28:04 +00:00 committed by IceToast
parent 2073aa632d
commit 415a7ed2da
3 changed files with 81 additions and 1 deletions

View file

@ -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");
});
}

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('settings_old');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::create('settings_old', function (Blueprint $table) {
$table->string('key', 191);
$table->text('value')->nullable();
$table->string('type');
$table->longText('description');
$table->timestamps();
});
}
};

View file

@ -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.