Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed Apr 26, 2024
1 parent 4a76db5 commit ee17d52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
24 changes: 6 additions & 18 deletions endpoints/db/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -80,7 +68,7 @@

echo json_encode([
"success" => true,
"message" => "File uploaded and wallos.db exists"
"message" => translate("success", $i18n)
]);
} else {
die(json_encode([
Expand Down
7 changes: 4 additions & 3 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ee17d52

Please sign in to comment.