From 30a81ca6fba93c9e21f59bb3b4f6cb3ce14df426 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 30 Jul 2023 17:42:36 +0300 Subject: [PATCH] delete snaps from registry when not found in the any of storage available --- cli/yggo.php | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/cli/yggo.php b/cli/yggo.php index b41d5a2..dc7d9b6 100644 --- a/cli/yggo.php +++ b/cli/yggo.php @@ -62,8 +62,6 @@ switch ($argv[1]) { // Scan for new files/storages CLI::notice(_('scan database registry for missed snap files...')); - $hostPageSnapsTrashQueue = []; - foreach ($db->getHosts() as $host) { foreach ($db->getHostPages($host->hostId) as $hostPage) { @@ -107,6 +105,7 @@ switch ($argv[1]) { } break; + case 'ftp': $ftp = new Ftp(); @@ -139,49 +138,35 @@ switch ($argv[1]) { } } - // Snap FS relation does not exist, add registry item to the delete queue + // Files not exists if (!$snapFilesExists) { - $hostPageSnapsTrashQueue[] = $hostPageSnap->hostPageSnapId; + // Delete snap from registry + try { - CLI::danger(sprintf(_('trash snap index: #%s file: %s not found in the any of storage;'), $hostPageSnap->hostPageSnapId, $filename)); - } - } - } - } + $db->beginTransaction(); - if ($hostPageSnapsTrashQueue && isset($argv[3]) && $argv[3] == 'purge') { + foreach ($db->getHostPageSnapStorages($hostPageSnapId) as $hostPageSnapStorage) { - CLI::notice(_('snap index deletion queue begin...')); + $db->deleteHostPageSnapDownloads($hostPageSnapStorage->hostPageSnapStorageId); + } - foreach ($hostPageSnapsTrashQueue as $hostPageSnapId) { + $db->deleteHostPageSnapStorages($hostPageSnapId); + $db->deleteHostPageSnap($hostPageSnapId); - try { + CLI::danger(sprintf(_('delete snap index: #%s file: %s not found in the any of storage;'), $hostPageSnap->hostPageSnapId, $filename)); - $db->beginTransaction(); + $db->commit(); - CLI::warning(sprintf(_('delete snap index: #%s;'), $hostPageSnapId)); + } catch(Exception $e) { - // Clear queued snap registry - foreach ($db->getHostPageSnapStorages($hostPageSnapId) as $hostPageSnapStorage) { + $db->rollBack(); - $db->deleteHostPageSnapDownloads($hostPageSnapStorage->hostPageSnapStorageId); + var_dump($e); + } } - - $db->deleteHostPageSnapStorages($hostPageSnapId); - $db->deleteHostPageSnap($hostPageSnapId); - - $db->commit(); - - } catch(Exception $e) { - - $db->rollBack(); - - var_dump($e); } } - - CLI::success(_('snap index trash queue deleted!')); } CLI::notice(_('optimize database tables...')); @@ -359,7 +344,7 @@ CLI::default('available options:'); CLI::default(' help - this message'); CLI::default(' crawl - execute crawler step in the crontab queue'); CLI::default(' clean - execute cleaner step in the crontab queue'); -CLI::default(' snap reindex [purge] - sync DB/FS relations. optionally delete unrelated DB/FS items'); +CLI::default(' snap reindex - sync DB/FS relations'); CLI::default(' hostPage rank reindex - generate rank indexes in hostPage table'); CLI::default(' hostPageDom generate [selectors] - make hostPageDom index based on related hostPage.data field'); CLI::default(' hostPageDom truncate - flush hostPageDom table');