From 443eaec64eb046af97412a5bbfc8325c9a5243a7 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 7 Jul 2023 12:30:07 +0300 Subject: [PATCH] autodelete failed snaps --- crontab/cleaner.php | 24 ++++++++++++++++++++++++ library/mysql.php | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crontab/cleaner.php b/crontab/cleaner.php index 286eefd..701d3a5 100644 --- a/crontab/cleaner.php +++ b/crontab/cleaner.php @@ -271,6 +271,30 @@ try { $logsCleanerDeleted += $db->deleteLogCleaner(time() - CLEAN_LOG_SECONDS_OFFSET); $logsCrawlerDeleted += $db->deleteLogCrawler(time() - CRAWL_LOG_SECONDS_OFFSET); + // Delete failed snaps + $snapFilePath = chunk_split($hostPage->hostPageId, 1, '/'); + + foreach ($db->getHostPageSnaps($hostPage->hostPageId, false, false, 'AND') as $hostPageSnap) { + + if ($hostPageSnap->storageLocal) { + + unlink(__DIR__ . '/../storage/snap/hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip'); + } + + if ($hostPageSnap->storageMega) { + + $ftp = new Ftp(); + + if ($ftp->connect(MEGA_FTP_HOST, MEGA_FTP_PORT, null, null, MEGA_FTP_DIRECTORY)) { + $ftp->delete('hp/' . $snapFilePath . $hostPageSnap->timeAdded . '.zip'); + } + } + + $db->deleteHostPageSnapDownloads($hostPageSnap->hostPageSnapId); + + $hostPagesSnapDeleted += $db->deleteHostPageSnap($hostPageSnap->hostPageSnapId); + } + // Commit results $db->commit(); diff --git a/library/mysql.php b/library/mysql.php index c12f73d..8733e13 100644 --- a/library/mysql.php +++ b/library/mysql.php @@ -417,9 +417,9 @@ class MySQL { return $query->fetch()->total; } - public function getHostPageSnaps(int $hostPageId, bool $storageLocal = true, bool $storageMega = true) { + public function getHostPageSnaps(int $hostPageId, bool $storageLocal = true, bool $storageMega = true, string $condition = 'OR') { - $query = $this->_db->prepare('SELECT * FROM `hostPageSnap` WHERE `hostPageId` = ? AND (`storageLocal` = ? OR `storageMega` = ?) ORDER BY `timeAdded` DESC'); + $query = $this->_db->prepare('SELECT * FROM `hostPageSnap` WHERE `hostPageId` = ? AND (`storageLocal` = ? ' . ($condition == 'OR' ? 'OR' : 'AND') . ' `storageMega` = ?) ORDER BY `timeAdded` DESC'); $query->execute([$hostPageId, $storageLocal, $storageMega]);