From dc2d971ba062a015581bc0cf4b8e08c5fd880f00 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 16 Jun 2023 16:53:14 +0300 Subject: [PATCH] clean up banned pages extra data --- crontab/cleaner.php | 34 ++++++++++++++++++++++++++++++++++ library/mysql.php | 7 +++++++ 2 files changed, 41 insertions(+) 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);