diff --git a/crontab/cleaner.php b/crontab/cleaner.php index d736f77..29d8fe8 100644 --- a/crontab/cleaner.php +++ b/crontab/cleaner.php @@ -217,6 +217,40 @@ try { // Reset banned pages $hostPagesBansRemoved += $db->resetBannedHostPages(time() - CLEAN_PAGE_BAN_SECONDS_OFFSET); + // Clean up banned pages extra data + foreach ($db->getHostPagesBanned() as $hostPageBanned) { + + // Delete host page descriptions + $hostPagesDescriptionsDeleted += $db->deleteHostPageDescriptions($hostPageBanned->hostPageId); + + // Delete host page refs data + $hostPagesToHostPageDeleted += $db->deleteHostPageToHostPage($hostPageBanned->hostPageId); + + // Delete host page snaps + $snapFilePath = chunk_split($hostPageBanned->hostPageId, 1, '/'); + + foreach ($db->getHostPageSnaps($hostPageBanned->hostPageId) as $hostPageSnap) { + + if ($hostPageSnap->storageLocal) { + + unlink('../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); + } + } + // Delete page description history $hostPagesDescriptionsDeleted += $db->deleteHostPageDescriptionsByTimeAdded(time() - CLEAN_PAGE_DESCRIPTION_OFFSET); diff --git a/library/mysql.php b/library/mysql.php index c46674d..01ced4b 100644 --- a/library/mysql.php +++ b/library/mysql.php @@ -502,6 +502,13 @@ class MySQL { return $query->fetchAll(); } + public function getHostPagesBanned() { + + $query = $this->_db->query('SELECT * FROM `hostPage` WHERE `timeBanned` IS NOT NULL'); + + return $query->fetchAll(); + } + public function resetBannedHostPages(int $timeOffset) { $query = $this->_db->prepare('UPDATE `hostPage` SET `timeBanned` = NULL WHERE `timeBanned` IS NOT NULL AND `timeBanned` < ' . (int) $timeOffset);