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]);