Bladeren bron

Insert the roolback for the old method.

Ferks-FK 2 jaren geleden
bovenliggende
commit
415a7ed2da

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

+ 34 - 0
database/migrations/2023_02_13_150022_delete_old_settings_table.php

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

+ 46 - 0
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.