Compare commits

...

3 commits

Author SHA1 Message Date
Matthew Exon
29fce8b7af trying to get phototrack to work 2023-12-26 16:35:27 +00:00
Matthew Exon
a30d850ff1 some more robust mailstream stuff 2023-12-26 16:34:57 +00:00
Matthew Exon
2728f8a839 debugging some issues 2023-12-26 16:33:37 +00:00
3 changed files with 60 additions and 32 deletions

View file

@ -118,9 +118,28 @@ function mailstream_send_hook(array $data)
return;
}
if ($item['deleted']) {
Logger::debug('mailstream_send_hook skipping deleted item', ['guid' => $item['guid']]);
return;
}
$user = User::getById($item['uid']);
if (empty($user)) {
Logger::error('mailstream_send_hook could not fund user', ['uid' => $item['uid']]);
Logger::error('mailstream_send_hook could not find user', ['uid' => $item['uid']]);
return;
}
$contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
if (!DBA::isResult($contact)) {
Logger::error('mailstream_send_hook could not find contact', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
return;
}
if ($contact['blocked']) {
Logger::error('mailstream_send_hook contact is blocked', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
return;
}
if (array_key_exists('ignored', $contact) && $contact['ignored']) {
Logger::error('mailstream_send_hook contact is ignored', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
return;
}
@ -143,7 +162,6 @@ function mailstream_send_hook(array $data)
function mailstream_post_hook(array &$item)
{
mailstream_check_version();
Logger::debug('@@@ mailstream_post_hook', ['item-uid' => $item['uid']]);
if (!DI::pConfig()->get($item['uid'], 'mailstream', 'enabled')) {
Logger::debug('mailstream: not enabled for item ' . $item['id'] . ' uid ' . $item['uid']);

View file

@ -102,8 +102,8 @@ function phototrack_photo_use($photo, $table, $field, $id) {
}
}
function phototrack_check_field_url($a, $table, $field, $id, $url) {
Logger::info('@@@ phototrack_check_field_url table ' . $table . ' field ' . $field . ' id ' . $id . ' url ' . $url);
function phototrack_check_field_url($a, $table, $id_field, $field, $id, $url) {
Logger::info('@@@ phototrack_check_field_url table ' . $table . ' id_field ' . $id_field . ' field ' . $field . ' id ' . $id . ' url ' . $url);
$baseurl = DI::baseUrl()->get(true);
if (strpos($url, $baseurl) === FALSE) {
return;
@ -126,35 +126,32 @@ function phototrack_check_field_url($a, $table, $field, $id, $url) {
}
}
function phototrack_check_field_bbcode($a, $table, $field, $id, $value) {
function phototrack_check_field_bbcode($a, $table, $id_field, $field, $id, $value) {
Logger::info('@@@ phototrack_check_field_url table ' . $table . ' id_field ' . $id_field . ' field ' . $field . ' id ' . $id . ' value ' . $value);
$baseurl = DI::baseUrl()->get(true);
$matches = array();
preg_match_all("/\[img(\=([0-9]*)x([0-9]*))?\](.*?)\[\/img\]/ism", $value, $matches);
foreach ($matches[4] as $url) {
phototrack_check_field_url($a, $table, $field, $id, $url);
phototrack_check_field_url($a, $table, $id_field, $field, $id, $url);
}
}
function phototrack_post_local_end(&$a, &$item) {
phototrack_check_row($a, 'item', $item);
phototrack_check_row($a, 'item-content', $item);
phototrack_check_row($a, 'item', 'id', $item);
phototrack_check_row($a, 'item-content', 'id', $item);
}
function phototrack_post_remote_end(&$a, &$item) {
phototrack_check_row($a, 'item', $item);
phototrack_check_row($a, 'item-content', $item);
phototrack_check_row($a, 'item', 'id', $item);
phototrack_check_row($a, 'item-content', 'id', $item);
}
function phototrack_notifier_end($item) {
}
function phototrack_check_row($a, $table, $row) {
function phototrack_check_row($a, $table, $id_field, $row) {
switch ($table) {
case 'item':
$fields = array(
'body' => 'bbcode');
break;
case 'item-content':
case 'post-content':
$fields = array(
'body' => 'bbcode');
break;
@ -182,8 +179,8 @@ function phototrack_check_row($a, $table, $row) {
}
foreach ($fields as $field => $type) {
switch ($type) {
case 'bbcode': phototrack_check_field_bbcode($a, $table, $field, $row['id'], $row[$field]); break;
case 'url': phototrack_check_field_url($a, $table, $field, $row['id'], $row[$field]); break;
case 'bbcode': phototrack_check_field_bbcode($a, $table, $id_field, $field, $row['id'], $row[$field]); break;
case 'url': phototrack_check_field_url($a, $table, $id_field, $field, $row['id'], $row[$field]); break;
}
}
phototrack_finished_row($table, $row['id']);
@ -197,15 +194,15 @@ function phototrack_batch_size() {
return PHOTOTRACK_DEFAULT_BATCH_SIZE;
}
function phototrack_search_table($a, $table) {
function phototrack_search_table($a, $table, $id_field) {
$batch_size = phototrack_batch_size();
$rows = DBA::p("SELECT `$table`.* FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.id ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) ) ORDER BY phototrack_row_check.checked LIMIT $batch_size");
$rows = DBA::p("SELECT `$table`.* FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.$id_field ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) ) ORDER BY phototrack_row_check.checked LIMIT $batch_size");
if (DBA::isResult($rows)) {
while ($row = DBA::fetch($rows)) {
phototrack_check_row($a, $table, $row);
phototrack_check_row($a, $table, $id_field, $row);
}
}
$r = DBA::p("SELECT COUNT(*) FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.id ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) )");
$r = DBA::p("SELECT COUNT(*) FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.$id_field ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) )");
Logger::info("@@@ phototrack_search_table " . print_r(DBA::fetch($r)));
$remaining = DBA::fetch($r)['count'];
Logger::info('phototrack: searched ' . DBA::numRows($rows) . ' rows in table ' . $table . ', ' . $remaining . ' still remaining to search');
@ -230,22 +227,23 @@ function phototrack_cron_time() {
return false;
}
}
Logger::debug('@@@ phototrack: search interval reached last ' . $last . ' search interval ' . $search_interval);
return true;
}
function phototrack_cron($a, $b) {
return; // @@@ something is broken
if (!phototrack_cron_time()) {
return;
}
DI::config()->set('phototrack', 'last_search', time());
$remaining = 0;
$remaining += phototrack_search_table($a, 'item');
$remaining += phototrack_search_table($a, 'item-content');
$remaining += phototrack_search_table($a, 'contact');
$remaining += phototrack_search_table($a, 'fcontact');
$remaining += phototrack_search_table($a, 'fsuggest');
$remaining += phototrack_search_table($a, 'gcontact');
$remaining += phototrack_search_table($a, 'post-content', 'uri-id');
$remaining += phototrack_search_table($a, 'contact', 'id');
$remaining += phototrack_search_table($a, 'fcontact', 'id');
$remaining += phototrack_search_table($a, 'fsuggest', 'id');
$remaining += phototrack_search_table($a, 'gcontact', 'id');
DI::config()->set('phototrack', 'remaining_items', $remaining);
if ($remaining === 0) {
@ -266,7 +264,7 @@ function phototrack_tidy() {
Logger::info('phototrack_tidy: deleted ' . DBA::numRows($rows) . ' photos');
}
DBA::e('DROP TABLE `phototrack-temp`');
$rows = DBA::p('SELECT id FROM phototrack_photo_use WHERE checked < DATE_SUB(NOW(), INTERVAL 14 DAY)');
$rows = DBA::p('SELECT id FROM phototrack_photo_use WHERE checked < DATE_SUB(NOW(), INTERVAL 2 MONTH)');
foreach ($rows as $row) {
DBA::e( 'DELETE FROM phototrack_photo_use WHERE id = ' . $row['id']);
}

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