Browse Source

clean up banned pages extra data

main
ghost 2 years ago
parent
commit
dc2d971ba0
  1. 34
      crontab/cleaner.php
  2. 7
      library/mysql.php

34
crontab/cleaner.php

@ -217,6 +217,40 @@ try {
// Reset banned pages // Reset banned pages
$hostPagesBansRemoved += $db->resetBannedHostPages(time() - CLEAN_PAGE_BAN_SECONDS_OFFSET); $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 // Delete page description history
$hostPagesDescriptionsDeleted += $db->deleteHostPageDescriptionsByTimeAdded(time() - CLEAN_PAGE_DESCRIPTION_OFFSET); $hostPagesDescriptionsDeleted += $db->deleteHostPageDescriptionsByTimeAdded(time() - CLEAN_PAGE_DESCRIPTION_OFFSET);

7
library/mysql.php

@ -502,6 +502,13 @@ class MySQL {
return $query->fetchAll(); 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) { public function resetBannedHostPages(int $timeOffset) {
$query = $this->_db->prepare('UPDATE `hostPage` SET `timeBanned` = NULL WHERE `timeBanned` IS NOT NULL AND `timeBanned` < ' . (int) $timeOffset); $query = $this->_db->prepare('UPDATE `hostPage` SET `timeBanned` = NULL WHERE `timeBanned` IS NOT NULL AND `timeBanned` < ' . (int) $timeOffset);

Loading…
Cancel
Save