From b9e89e044592710bc2a2aad8ca110125a893958c Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Wed, 2 Mar 2022 21:05:23 +0100 Subject: [PATCH] this is more correct --- retriever/retriever.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/retriever/retriever.php b/retriever/retriever.php index 8083dcf7..8755dc92 100644 --- a/retriever/retriever.php +++ b/retriever/retriever.php @@ -174,11 +174,11 @@ function retriever_clean_up_completed_resources($max_items) { // TODO: figure out how to do this with DBA module $r = DBA::p('SELECT retriever_resource.`id` as resource, retriever_item.`id` as item FROM retriever_resource, retriever_item, retriever_rule WHERE retriever_item.`finished` = 0 AND retriever_item.`resource` = retriever_resource.`id` AND retriever_resource.`completed` IS NOT NULL AND retriever_item.`contact-id` = retriever_rule.`contact-id` AND retriever_item.`item-uid` = retriever_rule.`uid` LIMIT %d', intval($max_items)); - if (!$r) { - $r = array(); + if (!DBA::isResult($r)) { + return; } - Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . count($r)); - foreach ($r as $rr) { + Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . DBA::numRows($r)); + while ($rr = DBA::fetch($r)) { $retriever_item = DBA::selectFirst('retriever_item', [], ['id' => intval($rr['item'])]); if (!DBA::isResult($retriever_item)) { Logger::warning('retriever_clean_up_completed_resources: no retriever item with id ' . $rr['item']); @@ -210,11 +210,11 @@ function retriever_tidy() { DBA::delete('retriever_resource', ['completed IS NULL AND created < DATE_SUB(now(), INTERVAL 3 MONTH)']); $r = DBA::p("SELECT retriever_item.id FROM retriever_item LEFT OUTER JOIN retriever_resource ON (retriever_item.resource = retriever_resource.id) WHERE retriever_resource.id is null"); - if (!DBA::isResult($r)) { - return; - } - Logger::info('retriever_tidy: found ' . count($r) . ' retriever_items with no retriever_resource'); - foreach ($r as $rr) { + if (!DBA::isResult($r)) { + return; + } + Logger::info('retriever_tidy: found ' . DBA::numRows($r) . ' retriever_items with no retriever_resource'); + while ($rr = DBA::fetch($r)) { DBA::e('DELETE FROM retriever_item WHERE id = %d', intval($rr['id'])); } }