From cc406d18b5e21ae0999d0b7338d4cb2946a0eb2e Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Thu, 20 Jun 2024 12:47:01 +0200 Subject: [PATCH] Fix Updater --- .../views/components/pre-update.blade.php | 67 ++++++++++++++++++- .../links-table-translation-layer.blade.php | 63 ----------------- 2 files changed, 64 insertions(+), 66 deletions(-) delete mode 100644 resources/views/components/updater/links-table-translation-layer.blade.php diff --git a/resources/views/components/pre-update.blade.php b/resources/views/components/pre-update.blade.php index 899ca5a..8897737 100644 --- a/resources/views/components/pre-update.blade.php +++ b/resources/views/components/pre-update.blade.php @@ -1,4 +1,12 @@ -{{-- update links table to new structure --}} -@include('components.updater.links-table-translation-layer') \ No newline at end of file + +// Check version +if (trim(file_get_contents(base_path("version.json"))) < '4.8.1') { + +// First, check if the 'type' and 'type_params' columns exist, and add them if they don't +if (!Schema::hasColumn('links', 'type')) { + Schema::table('links', function (Blueprint $table) { + $table->string('type')->nullable(); + }); +} + +if (!Schema::hasColumn('links', 'type_params')) { + Schema::table('links', function (Blueprint $table) { + $table->text('type_params')->nullable(); + }); +} + + // Get all links + $links = Link::all(); + + foreach ($links as $link) { + $type = null; + + // Assign type based on button_id + switch ($link->button_id) { + case "1": + case "2": + $type = "link"; + break; + case "43": + $type = "spacer"; + break; + case "42": + $type = "heading"; + break; + case "93": + $type = "text"; + break; + case "44": + $type = "telephone"; + break; + case "6": + $type = "email"; + break; + case "96": + $type = "vcard"; + break; + } + + // Update the link if a type was assigned + if ($type !== null) { + $link->type = $type; + $link->save(); + } + } +} \ No newline at end of file diff --git a/resources/views/components/updater/links-table-translation-layer.blade.php b/resources/views/components/updater/links-table-translation-layer.blade.php deleted file mode 100644 index 1f47236..0000000 --- a/resources/views/components/updater/links-table-translation-layer.blade.php +++ /dev/null @@ -1,63 +0,0 @@ -string('type')->nullable(); - }); -} - -if (!Schema::hasColumn('links', 'type_params')) { - Schema::table('links', function (Blueprint $table) { - $table->text('type_params')->nullable(); - }); -} - -// Disable execution time limit -set_time_limit(0); - -// Check version -if (trim(file_get_contents(base_path("version.json"))) < '4.8.1') { - // Get all links - $links = Link::all(); - - foreach ($links as $link) { - $type = null; - - // Assign type based on button_id - switch ($link->button_id) { - case "1": - case "2": - $type = "link"; - break; - case "43": - $type = "spacer"; - break; - case "42": - $type = "heading"; - break; - case "93": - $type = "text"; - break; - case "44": - $type = "telephone"; - break; - case "6": - $type = "email"; - break; - case "96": - $type = "vcard"; - break; - } - - // Update the link if a type was assigned - if ($type !== null) { - $link->type = $type; - $link->save(); - } - } -} \ No newline at end of file