Fix Updater

This commit is contained in:
Julian Prieber 2024-06-20 12:47:01 +02:00
parent c1a47556f5
commit cc406d18b5
2 changed files with 64 additions and 66 deletions

View File

@ -1,4 +1,12 @@
<?php // Runs before updating <?php // Runs before updating
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\Link;
// Disable execution time limit
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'){
try { try {
$file = base_path('storage/RSTAC'); $file = base_path('storage/RSTAC');
@ -8,6 +16,59 @@ if(trim(file_get_contents(base_path("version.json"))) < '4.0.0'){
} }
} catch (Exception $e) {} } catch (Exception $e) {}
} }
?>
{{-- update links table to new structure --}} // Check version
@include('components.updater.links-table-translation-layer') 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();
}
}
}

View File

@ -1,63 +0,0 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\Link;
// 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();
});
}
// 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();
}
}
}