adaptation for 2024.03

This commit is contained in:
Matthew Exon 2024-05-26 13:23:00 +01:00
parent bbc2632a93
commit f84d5308f6

View file

@ -143,7 +143,6 @@ $retriever_item_count = 0;
* @param int $max_items Maximum number of items to retrieve in this call * @param int $max_items Maximum number of items to retrieve in this call
*/ */
function retriever_retrieve_items(int $max_items) { function retriever_retrieve_items(int $max_items) {
Logger::debug('@@@ retriever_retrieve_items started');
global $retriever_item_count; global $retriever_item_count;
$retriever_schedule = array(array(1,'minute'), $retriever_schedule = array(array(1,'minute'),
@ -166,7 +165,7 @@ function retriever_retrieve_items(int $max_items) {
$retrieve_items = $max_items - $retriever_item_count; $retrieve_items = $max_items - $retriever_item_count;
do { do {
Logger::debug('retriever_retrieve_items: asked for maximum ' . $max_items . ', already retrieved ' . intval($retriever_item_count) . ', retrieve ' . $retrieve_items); Logger::debug('retriever_retrieve_items: asked for maximum ' . $max_items . ', already retrieved ' . intval($retriever_item_count) . ', retrieve ' . $retrieve_items);
$retriever_resources = DBA::selectToArray('retriever_resource', [], ['`completed` IS NULL AND (`last-try` IS NULL OR ' . implode($schedule_clauses, ' OR ') . ')'], ['order' => ['last-try' => 0], 'limit' => $retrieve_items]); $retriever_resources = DBA::selectToArray('retriever_resource', [], ['`completed` IS NULL AND (`last-try` IS NULL OR ' . implode(' OR ', $schedule_clauses) . ')'], ['order' => ['last-try' => 0], 'limit' => $retrieve_items]);
if (!is_array($retriever_resources)) { if (!is_array($retriever_resources)) {
break; break;
} }
@ -182,7 +181,6 @@ function retriever_retrieve_items(int $max_items) {
} }
while ($retrieve_items > 0); while ($retrieve_items > 0);
Logger::debug('retriever_retrieve_items: finished retrieving items'); Logger::debug('retriever_retrieve_items: finished retrieving items');
Logger::debug('@@@ retriever_retrieve_items finished');
} }
/** /**
@ -191,11 +189,9 @@ function retriever_retrieve_items(int $max_items) {
* @param int $max_items Maximum number of items to retrieve in this call * @param int $max_items Maximum number of items to retrieve in this call
*/ */
function retriever_clean_up_completed_resources(int $max_items) { function retriever_clean_up_completed_resources(int $max_items) {
Logger::debug('@@@ retriever_clean_up_completed_resources started');
// TODO: figure out how to do this with DBA module // 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 $max_items"); $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 $max_items");
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
Logger::debug('@@@ retriever_clean_up_completed_resources nothing to do');
return; return;
} }
Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . DBA::numRows($r)); Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . DBA::numRows($r));
@ -221,7 +217,6 @@ function retriever_clean_up_completed_resources(int $max_items) {
DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]); DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]);
retriever_check_item_completed($item); retriever_check_item_completed($item);
} }
Logger::debug('@@@ retriever_clean_up_completed_resources finished');
} }
/** /**
@ -699,9 +694,6 @@ function retriever_get_body(array $item) {
Logger::warning('retriever_get_body: item-content uri-id ' . $item['uri-id'] . ' has no body'); Logger::warning('retriever_get_body: item-content uri-id ' . $item['uri-id'] . ' has no body');
return $item['body']; return $item['body'];
} }
if ($content['body'] != $item['body']) {
Logger::warning('@@@ this is probably bad @@@ content: ' . $content['body'] . ' @@@ item: ' . $item['body']);
}
return $content['body']; return $content['body'];
} }
@ -783,7 +775,7 @@ function retriever_check_item_completed(array &$item)
* @param array $resource The resource that has just been completed * @param array $resource The resource that has just been completed
*/ */
function retriever_apply_completed_resource_to_item(array $retriever, array &$item, array $resource) { function retriever_apply_completed_resource_to_item(array $retriever, array &$item, array $resource) {
Logger::debug('retriever_apply_completed_resource_to_item: retriever ' . ($retriever ? $retriever['id'] : 'none') . ' resource ' . $resource['url'] . ' plink ' . $item['plink']); Logger::debug('retriever_apply_completed_resource_to_item', ['retriever' => $retriever ? $retriever['id'] : 'none', 'resource' => $resource['url'], 'plink' => $item['plink']]);
if (strpos($resource['type'], 'image') !== false) { if (strpos($resource['type'], 'image') !== false) {
retriever_transform_images($item, $resource); retriever_transform_images($item, $resource);
} }
@ -832,7 +824,7 @@ function retriever_transform_images(array &$item, array $resource) {
return; return;
} }
try { try {
$photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, 0, 0, "", "", "", "", $desc); $photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, $scale, Photo::DEFAULT, '', '', '', '', $desc);
} catch (Exception $e) { } catch (Exception $e) {
Logger::error('retriever_transform_images: unable to store photo ' . $resource['url'] . ' error: ' . $e->getMessage()); Logger::error('retriever_transform_images: unable to store photo ' . $resource['url'] . ' error: ' . $e->getMessage());
return; return;