From 5d7f2bf68c025294892936688c0be656fe731a59 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 4 Jun 2023 13:39:47 +0300 Subject: [PATCH] fix snap foreign keys deletion --- crontab/cleaner.php | 50 +++++++++++---------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/crontab/cleaner.php b/crontab/cleaner.php index 48bcdac..7a3e881 100644 --- a/crontab/cleaner.php +++ b/crontab/cleaner.php @@ -89,36 +89,23 @@ try { foreach ($db->getHostPageSnaps($hostPage->hostPageId) as $hostPageSnap) { - $snapFileLocalExists = (bool) $hostPageSnap->storageLocal; - $snapFileMegaExists = (bool) $hostPageSnap->storageMega; + if ($hostPageSnap->storageLocal) { - if ($snapFileLocalExists) { - - if (unlink('../storage/snap/hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip')) { - - $snapFileLocalExists = false; - } + unlink('../storage/snap/hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip'); } - if ($snapFileMegaExists) { + if ($hostPageSnap->storageMega) { $ftp = new Ftp(); if ($ftp->connect(MEGA_FTP_HOST, MEGA_FTP_PORT, null, null, MEGA_FTP_DIRECTORY)) { - - if ($ftp->delete('hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip')) { - - $snapFileMegaExists = false; - } + $ftp->delete('hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip'); } } - if (!$snapFileLocalExists && !$snapFileMegaExists) { - - $db->deleteHostPageSnapDownloads($hostPageSnap->hostPageSnapId); + $db->deleteHostPageSnapDownloads($hostPageSnap->hostPageSnapId); - $hostPagesSnapDeleted += $db->deleteHostPageSnap($hostPageSnap->hostPageSnapId); - } + $hostPagesSnapDeleted += $db->deleteHostPageSnap($hostPageSnap->hostPageSnapId); } // Delete host page @@ -145,36 +132,23 @@ try { foreach ($db->getHostPageSnaps($hostPage->hostPageId) as $hostPageSnap) { - $snapFileLocalExists = (bool) $hostPageSnap->storageLocal; - $snapFileMegaExists = (bool) $hostPageSnap->storageMega; - - if ($snapFileLocalExists) { + if ($hostPageSnap->storageLocal) { - if (unlink('../storage/snap/hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip')) { - - $snapFileLocalExists = false; - } + unlink('../storage/snap/hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip'); } - if ($snapFileMegaExists) { + if ($hostPageSnap->storageMega) { $ftp = new Ftp(); if ($ftp->connect(MEGA_FTP_HOST, MEGA_FTP_PORT, null, null, MEGA_FTP_DIRECTORY)) { - - if ($ftp->delete('hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip')) { - - $snapFileMegaExists = false; - } + $ftp->delete('hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip'); } } - if (!$snapFileLocalExists && !$snapFileMegaExists) { + $db->deleteHostPageSnapDownloads($hostPageSnap->hostPageSnapId); - $db->deleteHostPageSnapDownloads($hostPageSnap->hostPageSnapId); - - $hostPagesSnapDeleted += $db->deleteHostPageSnap($hostPageSnap->hostPageSnapId); - } + $hostPagesSnapDeleted += $db->deleteHostPageSnap($hostPageSnap->hostPageSnapId); } // Delete host page