From ee17d52f8951f0f19ee7f23bcdf391f195f4a2b8 Mon Sep 17 00:00:00 2001 From: Miguel Ribeiro Date: Fri, 26 Apr 2024 14:20:09 +0200 Subject: [PATCH] cleanup --- endpoints/db/restore.php | 24 ++++++------------------ scripts/settings.js | 7 ++++--- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/endpoints/db/restore.php b/endpoints/db/restore.php index ff66eb427..bba2c1624 100644 --- a/endpoints/db/restore.php +++ b/endpoints/db/restore.php @@ -15,51 +15,39 @@ $fileError = $file['error']; if ($fileError === 0) { - // Handle the uploaded file here - // The uploaded file will be stored as restore.zip $fileDestination = '../../.tmp/restore.zip'; move_uploaded_file($fileTmpName, $fileDestination); - // Unzip the uploaded file $zip = new ZipArchive(); if ($zip->open($fileDestination) === true) { $zip->extractTo('../../.tmp/restore/'); $zip->close(); + } else { + die(json_encode([ + "success" => false, + "message" => "Failed to extract the uploaded file" + ])); } - // Check if wallos.db file exists in the restore folder if (file_exists('../../.tmp/restore/wallos.db')) { - // Replace the wallos.db file in the db directory with the wallos.db file in the restore directory if (file_exists('../../db/wallos.db')) { unlink('../../db/wallos.db'); } rename('../../.tmp/restore/wallos.db', '../../db/wallos.db'); - // Check if restore/logos/ directory exists if (file_exists('../../.tmp/restore/logos/')) { - // Delete the files and folders in the uploaded logos directory $dir = '../../images/uploads/logos/'; - - // Create recursive directory iterator $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); - - // Create recursive iterator iterator in Child First Order $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); - // For each item in the recursive iterator foreach ( $ri as $file ) { - // If the item is a directory if ( $file->isDir() ) { - // Remove the directory rmdir($file->getPathname()); } else { - // If the item is a file - // Remove the file unlink($file->getPathname()); } } - // Copy the contents of restore/logos/ directory to the ../../images/uploads/logos/ directory $dir = new RecursiveDirectoryIterator('../../.tmp/restore/logos/'); $ite = new RecursiveIteratorIterator($dir); $allowedExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp']; @@ -80,7 +68,7 @@ echo json_encode([ "success" => true, - "message" => "File uploaded and wallos.db exists" + "message" => translate("success", $i18n) ]); } else { die(json_encode([ diff --git a/scripts/settings.js b/scripts/settings.js index 8a566d3b7..9b1649ba7 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -1049,12 +1049,13 @@ function restoreDB() { .then(response => response.json()) .then(data => { if (data.success) { - console.log('Database restored successfully'); + showSuccessMessage(data.message) + window.location.href = 'logout.php'; } else { - console.error('Failed to restore database:', data.message); + showErrorMessage(data.message); } }) - .catch(error => console.error('Error:', error)); + .catch(error => showErrorMessage('Error:', error)); } function saveCategorySorting() {