diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 2c6b6138..b3973dda 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -118,28 +118,9 @@ 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 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']]); + Logger::error('mailstream_send_hook could not fund user', ['uid' => $item['uid']]); return; } @@ -162,6 +143,7 @@ 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']); diff --git a/phototrack/phototrack.php b/phototrack/phototrack.php index 97fde076..0ede2a1c 100644 --- a/phototrack/phototrack.php +++ b/phototrack/phototrack.php @@ -102,8 +102,8 @@ function phototrack_photo_use($photo, $table, $field, $id) { } } -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); +function phototrack_check_field_url($a, $table, $field, $id, $url) { + Logger::info('@@@ phototrack_check_field_url table ' . $table . ' field ' . $field . ' id ' . $id . ' url ' . $url); $baseurl = DI::baseUrl()->get(true); if (strpos($url, $baseurl) === FALSE) { return; @@ -126,32 +126,35 @@ function phototrack_check_field_url($a, $table, $id_field, $field, $id, $url) { } } -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); +function phototrack_check_field_bbcode($a, $table, $field, $id, $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, $id_field, $field, $id, $url); + phototrack_check_field_url($a, $table, $field, $id, $url); } } function phototrack_post_local_end(&$a, &$item) { - phototrack_check_row($a, 'item', 'id', $item); - phototrack_check_row($a, 'item-content', 'id', $item); + phototrack_check_row($a, 'item', $item); + phototrack_check_row($a, 'item-content', $item); } function phototrack_post_remote_end(&$a, &$item) { - phototrack_check_row($a, 'item', 'id', $item); - phototrack_check_row($a, 'item-content', 'id', $item); + phototrack_check_row($a, 'item', $item); + phototrack_check_row($a, 'item-content', $item); } function phototrack_notifier_end($item) { } -function phototrack_check_row($a, $table, $id_field, $row) { +function phototrack_check_row($a, $table, $row) { switch ($table) { - case 'post-content': + case 'item': + $fields = array( + 'body' => 'bbcode'); + break; + case 'item-content': $fields = array( 'body' => 'bbcode'); break; @@ -179,8 +182,8 @@ function phototrack_check_row($a, $table, $id_field, $row) { } foreach ($fields as $field => $type) { switch ($type) { - 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; + 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; } } phototrack_finished_row($table, $row['id']); @@ -194,15 +197,15 @@ function phototrack_batch_size() { return PHOTOTRACK_DEFAULT_BATCH_SIZE; } -function phototrack_search_table($a, $table, $id_field) { +function phototrack_search_table($a, $table) { $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_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"); + $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"); if (DBA::isResult($rows)) { while ($row = DBA::fetch($rows)) { - phototrack_check_row($a, $table, $id_field, $row); + phototrack_check_row($a, $table, $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_field ) 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 ) 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'); @@ -227,23 +230,22 @@ 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, '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'); + $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'); DI::config()->set('phototrack', 'remaining_items', $remaining); if ($remaining === 0) { @@ -264,7 +266,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 2 MONTH)'); + $rows = DBA::p('SELECT id FROM phototrack_photo_use WHERE checked < DATE_SUB(NOW(), INTERVAL 14 DAY)'); foreach ($rows as $row) { DBA::e( 'DELETE FROM phototrack_photo_use WHERE id = ' . $row['id']); } diff --git a/retriever/retriever.php b/retriever/retriever.php index 4d9ae127..37715126 100644 --- a/retriever/retriever.php +++ b/retriever/retriever.php @@ -143,7 +143,6 @@ $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'), @@ -182,7 +181,6 @@ 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'); } /** @@ -191,11 +189,9 @@ 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)); @@ -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]); retriever_check_item_completed($item); } - Logger::debug('@@@ retriever_clean_up_completed_resources finished'); } /** @@ -381,9 +376,7 @@ 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); - if ($retriever_rule) { - retriever_apply_completed_resource_to_item($retriever_rule, $item, $resource); - } + 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); @@ -746,7 +739,7 @@ function retrieve_images(array &$item) { if (!$url) { continue; } - if (strpos($url, (string)(DI::baseUrl())) === FALSE) { + if (strpos($url, DI::baseUrl()) === FALSE) { $resource = add_retriever_resource($url, $item['uid'], $item['contact-id'], true); if (!$resource['completed']) { add_retriever_item($item, $resource); @@ -831,12 +824,7 @@ 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; } - 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; - } + $photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, 0, 0, "", "", "", "", $desc); $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']);