From 95f4c67613440870f1515f4f9c6333d523402707 Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Tue, 26 Dec 2023 16:33:37 +0000 Subject: [PATCH] debugging some issues --- retriever/retriever.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/retriever/retriever.php b/retriever/retriever.php index 37715126..4d9ae127 100644 --- a/retriever/retriever.php +++ b/retriever/retriever.php @@ -143,6 +143,7 @@ $retriever_item_count = 0; * @param int $max_items Maximum number of items to retrieve in this call */ function retriever_retrieve_items(int $max_items) { + Logger::debug('@@@ retriever_retrieve_items started'); global $retriever_item_count; $retriever_schedule = array(array(1,'minute'), @@ -181,6 +182,7 @@ function retriever_retrieve_items(int $max_items) { } while ($retrieve_items > 0); Logger::debug('retriever_retrieve_items: finished retrieving items'); + Logger::debug('@@@ retriever_retrieve_items finished'); } /** @@ -189,9 +191,11 @@ function retriever_retrieve_items(int $max_items) { * @param int $max_items Maximum number of items to retrieve in this call */ 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 $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)) { + Logger::debug('@@@ retriever_clean_up_completed_resources nothing to do'); return; } Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . DBA::numRows($r)); @@ -217,6 +221,7 @@ function retriever_clean_up_completed_resources(int $max_items) { DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]); retriever_check_item_completed($item); } + Logger::debug('@@@ retriever_clean_up_completed_resources finished'); } /** @@ -376,7 +381,9 @@ function retriever_item_completed(string $retriever_item_id, array $resource) { // Note: the retriever might be null. Doesn't matter. $retriever_rule = get_retriever_rule($retriever_item['contact-id'], $retriever_item['item-uid'], false); - retriever_apply_completed_resource_to_item($retriever_rule, $item, $resource); + if ($retriever_rule) { + retriever_apply_completed_resource_to_item($retriever_rule, $item, $resource); + } DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]); retriever_check_item_completed($item); @@ -739,7 +746,7 @@ function retrieve_images(array &$item) { if (!$url) { continue; } - if (strpos($url, DI::baseUrl()) === FALSE) { + if (strpos($url, (string)(DI::baseUrl())) === FALSE) { $resource = add_retriever_resource($url, $item['uid'], $item['contact-id'], true); if (!$resource['completed']) { add_retriever_item($item, $resource); @@ -824,7 +831,12 @@ function retriever_transform_images(array &$item, array $resource) { Logger::warning('retriever_transform_images: invalid image found at URL ' . $resource['url'] . ' for item ' . $item['id']); return; } - $photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, 0, 0, "", "", "", "", $desc); + try { + $photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, 0, 0, "", "", "", "", $desc); + } catch (Exception $e) { + Logger::error('retriever_transform_images: unable to store photo ' . $resource['url'] . ' error: ' . $e->getMessage()); + return; + } $new_url = DI::baseUrl() . '/photo/' . $rid . '-0.' . $image->getExt(); if (!strlen($new_url)) { Logger::warning('retriever_transform_images: no replacement URL for image ' . $resource['url']);