Insert the roolback for the old method.
This commit is contained in:
parent
2073aa632d
commit
415a7ed2da
3 changed files with 81 additions and 1 deletions
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
};
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue