Update pre-update.blade.php

This commit is contained in:
Julian Prieber 2024-06-25 13:22:05 +02:00
parent 31c8ba0daa
commit e977f0d63b
1 changed files with 39 additions and 36 deletions

View File

@ -4,7 +4,6 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Models\Link; use App\Models\Link;
// Disable execution time limit
set_time_limit(0); set_time_limit(0);
if(trim(file_get_contents(base_path("version.json"))) < '4.0.0'){ if(trim(file_get_contents(base_path("version.json"))) < '4.0.0'){
@ -17,10 +16,8 @@ if(trim(file_get_contents(base_path("version.json"))) < '4.0.0'){
} catch (Exception $e) {} } catch (Exception $e) {}
} }
// Check version
if (trim(file_get_contents(base_path("version.json"))) < '4.8.1') { 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')) { if (!Schema::hasColumn('links', 'type')) {
Schema::table('links', function (Blueprint $table) { Schema::table('links', function (Blueprint $table) {
$table->string('type')->nullable(); $table->string('type')->nullable();
@ -33,26 +30,30 @@ if (!Schema::hasColumn('links', 'type_params')) {
}); });
} }
// Get all links
$links = Link::all(); $links = Link::all();
foreach ($links as $link) { foreach ($links as $link) {
$type = null; $type = null;
$params = false;
// Assign type based on button_id
switch ($link->button_id) { switch ($link->button_id) {
case "1": case "1":
$type = "link";
break;
case "2": case "2":
$type = "link"; $type = "link";
break; break;
case "43": case "43":
$type = "spacer"; $type = "spacer";
$params = true;
break; break;
case "42": case "42":
$type = "heading"; $type = "heading";
$params = true;
break; break;
case "93": case "93":
$type = "text"; $type = "text";
$params = true;
break; break;
case "44": case "44":
$type = "telephone"; $type = "telephone";
@ -65,9 +66,11 @@ if (!Schema::hasColumn('links', 'type_params')) {
break; break;
} }
// Update the link if a type was assigned
if ($type !== null) { if ($type !== null) {
$link->type = $type; $link->type = $type;
if ($params === true) {
$link->type_params = json_encode(["custom_html" => true]);
}
$link->save(); $link->save();
} }
} }