Browse Source

autodelete failed snaps

main
ghost 1 year ago
parent
commit
443eaec64e
  1. 24
      crontab/cleaner.php
  2. 4
      library/mysql.php

24
crontab/cleaner.php

@ -271,6 +271,30 @@ try { @@ -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();

4
library/mysql.php

@ -417,9 +417,9 @@ class MySQL { @@ -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]);

Loading…
Cancel
Save