this is more correct

This commit is contained in:
Matthew Exon 2022-03-02 21:05:23 +01:00
parent c696cb174e
commit ec24589166

View file

@ -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']));
}
}