debugging some issues

This commit is contained in:
Matthew Exon 2023-12-26 16:33:37 +00:00 committed by Matthew Exon
parent 0404f2155b
commit 95f4c67613

View file

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