Browse Source

cover snap deletion in transaction

main
ghost 1 year ago
parent
commit
1e664ba4cd
  1. 36
      cli/yggo.php

36
cli/yggo.php

@ -71,7 +71,7 @@ switch ($argv[1]) {
foreach ($db->getHostPageSnaps($hostPage->hostPageId) as $hostPageSnap) { foreach ($db->getHostPageSnaps($hostPage->hostPageId) as $hostPageSnap) {
// Define variables // Define variables
$snapFileExists = false; $snapFilesExists = false;
$snapPath = chunk_split($hostPage->hostPageId, 1, '/'); $snapPath = chunk_split($hostPage->hostPageId, 1, '/');
@ -91,7 +91,7 @@ switch ($argv[1]) {
if (file_exists($filename)) { if (file_exists($filename)) {
$snapFileExists = true; $snapFilesExists = true;
if (!$db->getHostPageSnapStorageByCRC32Name($hostPageSnap->hostPageSnapId, $crc32name)) { if (!$db->getHostPageSnapStorageByCRC32Name($hostPageSnap->hostPageSnapId, $crc32name)) {
@ -117,7 +117,7 @@ switch ($argv[1]) {
if ($ftp->size($filename)) { if ($ftp->size($filename)) {
$snapFileExists = true; $snapFilesExists = true;
if (!$db->getHostPageSnapStorageByCRC32Name($hostPageSnap->hostPageSnapId, $crc32name)) { if (!$db->getHostPageSnapStorageByCRC32Name($hostPageSnap->hostPageSnapId, $crc32name)) {
@ -139,7 +139,8 @@ switch ($argv[1]) {
} }
} }
if (!$snapFileExists) { // Snap FS relation does not exist, add registry item to the delete queue
if (!$snapFilesExists) {
$hostPageSnapsTrashQueue[] = $hostPageSnap->hostPageSnapId; $hostPageSnapsTrashQueue[] = $hostPageSnap->hostPageSnapId;
@ -155,16 +156,29 @@ switch ($argv[1]) {
foreach ($hostPageSnapsTrashQueue as $hostPageSnapId) { foreach ($hostPageSnapsTrashQueue as $hostPageSnapId) {
CLI::warning(sprintf(_('delete snap index: #%s;'), $hostPageSnapId)); try {
// Clear queued snap registry $db->beginTransaction();
foreach ($db->getHostPageSnapStorages($hostPageSnapId) as $hostPageSnapStorage) {
$db->deleteHostPageSnapDownloads($hostPageSnapStorage->hostPageSnapStorageId); CLI::warning(sprintf(_('delete snap index: #%s;'), $hostPageSnapId));
}
// Clear queued snap registry
foreach ($db->getHostPageSnapStorages($hostPageSnapId) as $hostPageSnapStorage) {
$db->deleteHostPageSnapDownloads($hostPageSnapStorage->hostPageSnapStorageId);
}
$db->deleteHostPageSnapStorages($hostPageSnapId);
$db->deleteHostPageSnap($hostPageSnapId);
$db->deleteHostPageSnapStorages($hostPageSnapId); $db->commit();
$db->deleteHostPageSnap($hostPageSnapId);
} catch(Exception $e) {
$db->rollBack();
var_dump($e);
}
} }
CLI::success(_('snap index trash queue deleted!')); CLI::success(_('snap index trash queue deleted!'));

Loading…
Cancel
Save