Improve error handling

This commit is contained in:
Julian Prieber 2024-11-27 14:10:31 +01:00
parent 42615036cd
commit 76f14a78fe
2 changed files with 361 additions and 225 deletions

View File

@ -11,75 +11,141 @@ use App\Models\Page;
set_time_limit(0); set_time_limit(0);
//run before finishing: //run before finishing:
if(EnvEditor::keyExists('JOIN_BETA')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('JOIN_BETA')) {
} else { EnvEditor::addKey('JOIN_BETA', 'false');} // Adds key to .env file /* Do nothing if key already exists */
} else {
EnvEditor::addKey('JOIN_BETA', 'false');
} // Adds key to .env file
if(EnvEditor::keyExists('SKIP_UPDATE_BACKUP')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('SKIP_UPDATE_BACKUP')) {
} else { EnvEditor::addKey('SKIP_UPDATE_BACKUP', 'false');} // Adds key to .env file /* Do nothing if key already exists */
} else {
EnvEditor::addKey('SKIP_UPDATE_BACKUP', 'false');
} // Adds key to .env file
if(EnvEditor::keyExists('CUSTOM_META_TAGS')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('CUSTOM_META_TAGS')) {
} else {EnvEditor::addKey('CUSTOM_META_TAGS', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('CUSTOM_META_TAGS', 'false');
}
if(EnvEditor::keyExists('MAINTENANCE_MODE')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('MAINTENANCE_MODE')) {
} else {EnvEditor::addKey('MAINTENANCE_MODE', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('MAINTENANCE_MODE', 'false');
}
if(EnvEditor::keyExists('ALLOW_CUSTOM_CODE_IN_THEMES')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ALLOW_CUSTOM_CODE_IN_THEMES')) {
} else {EnvEditor::addKey('ALLOW_CUSTOM_CODE_IN_THEMES', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ALLOW_CUSTOM_CODE_IN_THEMES', 'true');
}
if(EnvEditor::keyExists('ENABLE_THEME_UPDATER')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ENABLE_THEME_UPDATER')) {
} else {EnvEditor::addKey('ENABLE_THEME_UPDATER', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ENABLE_THEME_UPDATER', 'true');
}
if(EnvEditor::keyExists('ENABLE_SOCIAL_LOGIN')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ENABLE_SOCIAL_LOGIN')) {
} else {EnvEditor::addKey('ENABLE_SOCIAL_LOGIN', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ENABLE_SOCIAL_LOGIN', 'false');
}
if(EnvEditor::keyExists('USE_THEME_PREVIEW_IFRAME')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('USE_THEME_PREVIEW_IFRAME')) {
} else {EnvEditor::addKey('USE_THEME_PREVIEW_IFRAME', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('USE_THEME_PREVIEW_IFRAME', 'true');
}
if(EnvEditor::keyExists('FORCE_ROUTE_HTTPS')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('FORCE_ROUTE_HTTPS')) {
} else {EnvEditor::addKey('FORCE_ROUTE_HTTPS', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('FORCE_ROUTE_HTTPS', 'false');
}
if(EnvEditor::keyExists('HIDE_VERIFICATION_CHECKMARK')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('HIDE_VERIFICATION_CHECKMARK')) {
} else {EnvEditor::addKey('HIDE_VERIFICATION_CHECKMARK', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('HIDE_VERIFICATION_CHECKMARK', 'false');
}
if(EnvEditor::keyExists('ALLOW_CUSTOM_BACKGROUNDS')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ALLOW_CUSTOM_BACKGROUNDS')) {
} else {EnvEditor::addKey('ALLOW_CUSTOM_BACKGROUNDS', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ALLOW_CUSTOM_BACKGROUNDS', 'true');
}
if(EnvEditor::keyExists('ALLOW_USER_IMPORT')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ALLOW_USER_IMPORT')) {
} else {EnvEditor::addKey('ALLOW_USER_IMPORT', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ALLOW_USER_IMPORT', 'true');
}
if(EnvEditor::keyExists('ALLOW_USER_EXPORT')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ALLOW_USER_EXPORT')) {
} else {EnvEditor::addKey('ALLOW_USER_EXPORT', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ALLOW_USER_EXPORT', 'true');
}
if(EnvEditor::keyExists('SUPPORTED_DOMAINS')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('SUPPORTED_DOMAINS')) {
} else {EnvEditor::addKey('SUPPORTED_DOMAINS', '');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('SUPPORTED_DOMAINS', '');
}
if(EnvEditor::keyExists('MANUAL_USER_VERIFICATION')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('MANUAL_USER_VERIFICATION')) {
} else {EnvEditor::addKey('MANUAL_USER_VERIFICATION', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('MANUAL_USER_VERIFICATION', 'false');
}
if(EnvEditor::keyExists('DISPLAY_CREDIT_FOOTER')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('DISPLAY_CREDIT_FOOTER')) {
} else {EnvEditor::addKey('DISPLAY_CREDIT_FOOTER', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('DISPLAY_CREDIT_FOOTER', 'true');
}
if(EnvEditor::keyExists('LOCALE')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('LOCALE')) {
} else {EnvEditor::addKey('LOCALE', 'en');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('LOCALE', 'en');
}
if(EnvEditor::keyExists('ENABLE_REPORT_ICON')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ENABLE_REPORT_ICON')) {
} else {EnvEditor::addKey('ENABLE_REPORT_ICON', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ENABLE_REPORT_ICON', 'false');
}
if(EnvEditor::keyExists('ENABLE_ADMIN_BAR')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ENABLE_ADMIN_BAR')) {
} else {EnvEditor::addKey('ENABLE_ADMIN_BAR', 'true');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ENABLE_ADMIN_BAR', 'true');
}
if(EnvEditor::keyExists('ENABLE_ADMIN_BAR_USERS')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('ENABLE_ADMIN_BAR_USERS')) {
} else {EnvEditor::addKey('ENABLE_ADMIN_BAR_USERS', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('ENABLE_ADMIN_BAR_USERS', 'false');
}
if(EnvEditor::keyExists('ADMIN_EMAIL')){} else if (EnvEditor::keyExists('ADMIN_EMAIL')) {
{if(Auth::user()->id == 1){EnvEditor::addKey('ADMIN_EMAIL', App\Models\User::find(1)->email);} } else {
else{EnvEditor::addKey('ADMIN_EMAIL', '');}} if (Auth::user()->id == 1) {
EnvEditor::addKey('ADMIN_EMAIL', App\Models\User::find(1)->email);
} else {
EnvEditor::addKey('ADMIN_EMAIL', '');
}
}
if (env('APP_NAME') == 'LittleLink Custom' or env('APP_NAME') == 'LittleLink') { if (env('APP_NAME') == 'LittleLink Custom' or env('APP_NAME') == 'LittleLink') {
EnvEditor::editKey('APP_NAME', 'LinkStack'); EnvEditor::editKey('APP_NAME', 'LinkStack');
} }
if (EnvEditor::keyExists('ALLOW_REGISTRATION')) { /* Do nothing if key already exists */ if (EnvEditor::keyExists('ALLOW_REGISTRATION')) {
/* Do nothing if key already exists */
} else { } else {
$pagedb = DB::table('pages')->select('register')->first(); $pagedb = DB::table('pages')->select('register')->first();
if ($pagedb->register) { if ($pagedb->register) {
@ -89,7 +155,9 @@ set_time_limit(0);
} }
try { try {
DB::table('pages')->update(['register' => null]); DB::table('pages')->update(['register' => null]);
} catch (Exception $e) {} } catch (Exception $e) {
session(['update_error' => $e->getMessage()]);
}
} }
try { try {
@ -98,28 +166,62 @@ set_time_limit(0);
copy(base_path('storage/templates/advanced-config.php'), base_path('config/advanced-config.php')); copy(base_path('storage/templates/advanced-config.php'), base_path('config/advanced-config.php'));
unlink($file); unlink($file);
} }
} catch (Exception $e) {} } catch (Exception $e) {
session(['update_error' => $e->getMessage()]);
}
try { try {
$vendorLangPath = resource_path('lang/vendor'); $vendorLangPath = resource_path('lang/vendor');
if (File::exists($vendorLangPath)) { if (File::exists($vendorLangPath)) {
File::deleteDirectory($vendorLangPath); File::deleteDirectory($vendorLangPath);
} }
} catch (Exception $e) {} } catch (Exception $e) {
session(['update_error' => $e->getMessage()]);
}
// Footer page customization // Footer page customization
if(EnvEditor::keyExists('DISPLAY_FOOTER_HOME')){} else {EnvEditor::addKey('DISPLAY_FOOTER_HOME', 'true');} if (EnvEditor::keyExists('DISPLAY_FOOTER_HOME')) {
if(EnvEditor::keyExists('DISPLAY_FOOTER_TERMS')){} else {EnvEditor::addKey('DISPLAY_FOOTER_TERMS', 'true');} } else {
if(EnvEditor::keyExists('DISPLAY_FOOTER_PRIVACY')){} else {EnvEditor::addKey('DISPLAY_FOOTER_PRIVACY', 'true');} EnvEditor::addKey('DISPLAY_FOOTER_HOME', 'true');
if(EnvEditor::keyExists('DISPLAY_FOOTER_CONTACT')){} else {EnvEditor::addKey('DISPLAY_FOOTER_CONTACT', 'true');} }
if(EnvEditor::keyExists('TITLE_FOOTER_HOME')){} else {EnvEditor::addKey('TITLE_FOOTER_HOME', 'Home');} if (EnvEditor::keyExists('DISPLAY_FOOTER_TERMS')) {
if(EnvEditor::keyExists('TITLE_FOOTER_TERMS')){} else {EnvEditor::addKey('TITLE_FOOTER_TERMS', 'Terms');} } else {
if(EnvEditor::keyExists('TITLE_FOOTER_PRIVACY')){} else {EnvEditor::addKey('TITLE_FOOTER_PRIVACY', 'Privacy');} EnvEditor::addKey('DISPLAY_FOOTER_TERMS', 'true');
if(EnvEditor::keyExists('TITLE_FOOTER_CONTACT')){} else {EnvEditor::addKey('TITLE_FOOTER_CONTACT', 'Contact');} }
if(EnvEditor::keyExists('HOME_FOOTER_LINK')){} else {EnvEditor::addKey('HOME_FOOTER_LINK', '');} if (EnvEditor::keyExists('DISPLAY_FOOTER_PRIVACY')) {
} else {
EnvEditor::addKey('DISPLAY_FOOTER_PRIVACY', 'true');
}
if (EnvEditor::keyExists('DISPLAY_FOOTER_CONTACT')) {
} else {
EnvEditor::addKey('DISPLAY_FOOTER_CONTACT', 'true');
}
if (EnvEditor::keyExists('TITLE_FOOTER_HOME')) {
} else {
EnvEditor::addKey('TITLE_FOOTER_HOME', 'Home');
}
if (EnvEditor::keyExists('TITLE_FOOTER_TERMS')) {
} else {
EnvEditor::addKey('TITLE_FOOTER_TERMS', 'Terms');
}
if (EnvEditor::keyExists('TITLE_FOOTER_PRIVACY')) {
} else {
EnvEditor::addKey('TITLE_FOOTER_PRIVACY', 'Privacy');
}
if (EnvEditor::keyExists('TITLE_FOOTER_CONTACT')) {
} else {
EnvEditor::addKey('TITLE_FOOTER_CONTACT', 'Contact');
}
if (EnvEditor::keyExists('HOME_FOOTER_LINK')) {
} else {
EnvEditor::addKey('HOME_FOOTER_LINK', '');
}
if(EnvEditor::keyExists('FORCE_HTTPS')){ /* Do nothing if key already exists */ if (EnvEditor::keyExists('FORCE_HTTPS')) {
} else {EnvEditor::addKey('FORCE_HTTPS', 'false');} /* Do nothing if key already exists */
} else {
EnvEditor::addKey('FORCE_HTTPS', 'false');
}
$data['page'] = Page::select('contact')->first(); $data['page'] = Page::select('contact')->first();
if (strpos($data['page']->contact, 'info@littlelink-custom.com') !== false or strpos($data['page']->contact, 'LittleLink Custom') !== false) { if (strpos($data['page']->contact, 'info@littlelink-custom.com') !== false or strpos($data['page']->contact, 'LittleLink Custom') !== false) {
@ -142,7 +244,6 @@ set_time_limit(0);
Page::first()->update(['contact' => $contact]); Page::first()->update(['contact' => $contact]);
} }
$data['page'] = Page::select('home_message')->first(); $data['page'] = Page::select('home_message')->first();
if (strpos($data['page']->home_message, 'LittleLink Custom') !== false) { if (strpos($data['page']->home_message, 'LittleLink Custom') !== false) {
$home_message = ' $home_message = '
@ -179,7 +280,9 @@ set_time_limit(0);
$seeder = new ButtonSeeder(); $seeder = new ButtonSeeder();
$seeder->run(); $seeder->run();
} catch (exception $e) {} } catch (exception $e) {
session(['update_error' => $e->getMessage()]);
}
Schema::enableForeignKeyConstraints(); Schema::enableForeignKeyConstraints();
if (!Schema::hasColumn('users', 'auth_as')) { if (!Schema::hasColumn('users', 'auth_as')) {
@ -202,79 +305,109 @@ set_time_limit(0);
"name": "static_text", "name": "static_text",
"class": "form-control" "class": "form-control"
} }
]' ]',
]); ]);
DB::table('link_types')->updateOrInsert([ DB::table('link_types')->updateOrInsert([
'typename' => 'email', 'typename' => 'email',
'title' => 'E-Mail address', 'title' => 'E-Mail address',
'icon' => 'bi bi-envelope-fill', 'icon' => 'bi bi-envelope-fill',
'description' => 'Add an email that opens a system dialog to compose a new email.' 'description' => 'Add an email that opens a system dialog to compose a new email.',
]); ]);
DB::table('link_types')->updateOrInsert([ DB::table('link_types')->updateOrInsert([
'typename' => 'telephone', 'typename' => 'telephone',
'title' => 'Telephone number', 'title' => 'Telephone number',
'icon' => 'bi bi-telephone-fill', 'icon' => 'bi bi-telephone-fill',
'description' => 'Add a telephone number that opens a system dialog to initiate a phone call.' 'description' => 'Add a telephone number that opens a system dialog to initiate a phone call.',
]); ]);
DB::table('link_types')->updateOrInsert([ DB::table('link_types')->updateOrInsert([
'typename' => 'vcard', 'typename' => 'vcard',
'title' => 'Vcard', 'title' => 'Vcard',
'icon' => 'bi bi-person-square', 'icon' => 'bi bi-person-square',
'description' => 'Create or upload an electronic business card.' 'description' => 'Create or upload an electronic business card.',
]); ]);
} catch (exception $e) {} } catch (exception $e) {
session(['update_error' => $e->getMessage()]);
}
// Moves all previous images to the new path // Moves all previous images to the new path
try{if (is_dir(base_path('assets/img'))) { try {
if (is_dir(base_path('assets/img'))) {
$files = File::files(base_path('img')); $files = File::files(base_path('img'));
foreach ($files as $file) { foreach ($files as $file) {
$filename = $file->getFilename(); $filename = $file->getFilename();
$destination = base_path('assets/img/' . $filename); $destination = base_path('assets/img/' . $filename);
if (!File::exists($destination)) { if (!File::exists($destination)) {
if (!$file->isDir()) { if (!$file->isDir()) {
File::move($file, $destination);}}}} File::move($file, $destination);
}catch(exception $e) {} }
try{if (is_dir(base_path('assets/img/background-img'))) { }
}
}
} catch (exception $e) {
}
try {
if (is_dir(base_path('assets/img/background-img'))) {
$files = File::files(base_path('img/background-img')); $files = File::files(base_path('img/background-img'));
foreach ($files as $file) { foreach ($files as $file) {
$filename = $file->getFilename(); $filename = $file->getFilename();
$destination = base_path('assets/img/background-img/' . $filename); $destination = base_path('assets/img/background-img/' . $filename);
if (!File::exists($destination)) { if (!File::exists($destination)) {
if (!$file->isDir()) { if (!$file->isDir()) {
File::move($file, $destination);}}}} File::move($file, $destination);
}catch(exception $e) {} }
try{if (is_dir(base_path('littlelink/images'))) { }
}
}
} catch (exception $e) {
}
try {
if (is_dir(base_path('littlelink/images'))) {
$files = File::files(base_path('littlelink/images')); $files = File::files(base_path('littlelink/images'));
foreach ($files as $file) { foreach ($files as $file) {
$filename = $file->getFilename(); $filename = $file->getFilename();
$destination = base_path('assets/linkstack/images/' . $filename); $destination = base_path('assets/linkstack/images/' . $filename);
if (!File::exists($destination)) { if (!File::exists($destination)) {
if (!$file->isDir()) { if (!$file->isDir()) {
File::move($file, $destination);}}}} File::move($file, $destination);
}catch(exception $e) {} }
try{if (is_dir(base_path('littlelink/images'))) { }
}
}
} catch (exception $e) {
}
try {
if (is_dir(base_path('littlelink/images'))) {
$files = File::files(base_path('littlelink/images')); $files = File::files(base_path('littlelink/images'));
foreach ($files as $file) { foreach ($files as $file) {
$filename = $file->getFilename(); $filename = $file->getFilename();
$destination = base_path('assets/linkstack/images/' . $filename); $destination = base_path('assets/linkstack/images/' . $filename);
if (!File::exists($destination)) { if (!File::exists($destination)) {
if (!$file->isDir()) { if (!$file->isDir()) {
File::move($file, $destination);}}}} File::move($file, $destination);
}catch(exception $e) {} }
try{if (is_dir(base_path('studio/favicon/icons'))) { }
}
}
} catch (exception $e) {
}
try {
if (is_dir(base_path('studio/favicon/icons'))) {
$files = File::files(base_path('studio/favicon/icons')); $files = File::files(base_path('studio/favicon/icons'));
foreach ($files as $file) { foreach ($files as $file) {
$filename = $file->getFilename(); $filename = $file->getFilename();
$destination = base_path('assets/favicon/icons/' . $filename); $destination = base_path('assets/favicon/icons/' . $filename);
if (!File::exists($destination)) { if (!File::exists($destination)) {
if (!$file->isDir()) { if (!$file->isDir()) {
File::move($file, $destination);}}}} File::move($file, $destination);
}catch(exception $e) {} }
}
}
}
} catch (exception $e) {
}
// Changes saved profile images from littlelink_name to IDs. // Changes saved profile images from littlelink_name to IDs.
// This runs every time the updater runs. // This runs every time the updater runs.
@ -290,6 +423,10 @@ try{if (is_dir(base_path('studio/favicon/icons'))) {
if (File::exists($oldPath)) { if (File::exists($oldPath)) {
File::move($oldPath, $newPath); File::move($oldPath, $newPath);
}}} catch (exception $e) {} }
}
} catch (exception $e) {
session(['update_error' => $e->getMessage()]);
}
?> ?>

View File

@ -62,6 +62,10 @@
@endif @endif
@if ($_SERVER['QUERY_STRING'] === 'updating') @if ($_SERVER['QUERY_STRING'] === 'updating')
<div class="logo-container fadein">
<img class="logo-img" src="{{ asset('assets/linkstack/images/logo-loading.svg') }}" alt="Logo">
</div>
<h1 class="loadingtxt">{{ __('messages.Updating') }}</h1>
@php @php
set_time_limit(0); set_time_limit(0);
try { try {
@ -105,9 +109,15 @@
session(['update_error' => 'Fatal error. ' . $e->getMessage()]); session(['update_error' => 'Fatal error. ' . $e->getMessage()]);
} }
@endphp @endphp
@if (session()->has('update_error'))
<meta http-equiv="refresh" content="1; {{ url()->current() }}/?error" />
@else
<meta http-equiv="refresh" content="0; {{ url()->current() }}/?finishing" /> <meta http-equiv="refresh" content="0; {{ url()->current() }}/?finishing" />
@endif @endif
@endif
@if ($_SERVER['QUERY_STRING'] === 'backup') @if ($_SERVER['QUERY_STRING'] === 'backup')
@push('updater-head') @push('updater-head')
<meta http-equiv="refresh" content="2; URL={{ url()->current() }}/?backups" /> <meta http-equiv="refresh" content="2; URL={{ url()->current() }}/?backups" />
@ -184,17 +194,6 @@
@endif @endif
@endif @endif
@if (
$_SERVER['QUERY_STRING'] === 'updating' &&
(file_exists(base_path('backups/CANUPDATE')) || env('SKIP_UPDATE_BACKUP') == true))
<div class="logo-container fadein">
<img class="logo-img" src="{{ asset('assets/linkstack/images/logo-loading.svg') }}" alt="Logo">
</div>
<h1 class="loadingtxt">{{ __('messages.Updating') }}</h1>
@push('updater-head')
<meta http-equiv="refresh" content="2; URL={{ url()->current() }}/../updating" />
@endpush
@endif
@elseif(empty($_SERVER['QUERY_STRING'])) @elseif(empty($_SERVER['QUERY_STRING']))
<div class="logo-container fadein"> <div class="logo-container fadein">
<img class="logo-img" src="{{ asset('assets/linkstack/images/logo.svg') }}" alt="Logo"> <img class="logo-img" src="{{ asset('assets/linkstack/images/logo.svg') }}" alt="Logo">