Ejemplo n.º 1
0
function mailstream_cron($a, $b)
{
    // Only process items older than an hour in cron.  This is because
    // we want to give mailstream_post_remote_hook a fair chance to
    // send the email itself before cron jumps in.  Only if
    // mailstream_post_remote_hook fails for some reason will this get
    // used, and in that case it's worth holding off a bit anyway.
    $ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `item`.`id` FROM `mailstream_item` JOIN `item` ON (`mailstream_item`.`uid` = `item`.`uid` AND `mailstream_item`.`uri` = `item`.`uri` AND `mailstream_item`.`contact-id` = `item`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `item`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100");
    logger('mailstream_cron processing ' . count($ms_item_ids) . ' items', LOGGER_DEBUG);
    foreach ($ms_item_ids as $ms_item_id) {
        if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) {
            logger('mailstream_cron: Item ' . $ms_item_id['id'] . ' URI ' . $ms_item_id['uri'] . ' has no message-id', LOGGER_NORMAL);
        }
        $items = q('SELECT * FROM `item` WHERE `id` = %d', $ms_item_id['id']);
        $item = $items[0];
        $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($item['uid']));
        $user = $users[0];
        if ($user && $item) {
            mailstream_send($a, $ms_item_id['message-id'], $item, $user);
        } else {
            logger('mailstream_cron: Unable to find item ' . $ms_item_id['id'], LOGGER_NORMAL);
            q("UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = %d", intval($ms_item['message-id']));
        }
    }
    mailstream_tidy();
}
Ejemplo n.º 2
0
function mailstream_cron($a, $b)
{
    $ms_items = q("SELECT * FROM `mailstream_item` WHERE `completed` IS NULL LIMIT 100");
    logger('mailstream_cron processing ' . count($ms_items) . ' items', LOGGER_DEBUG);
    foreach ($ms_items as $ms_item) {
        $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `contact-id` = %d", intval($ms_item['uid']), dbesc($ms_item['uri']), intval($ms_item['contact-id']));
        $item = $items[0];
        $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($ms_item['uid']));
        $user = $users[0];
        if ($user && $item) {
            mailstream_send($a, $ms_item, $item, $user);
        } else {
            logger('mailstream_cron: Unable to find item ' . $ms_item['uri'], LOGGER_NORMAL);
            q("UPDATE `mailstream_item` SET `completed` = now() WHERE `id` = %d", intval($ms_item['id']));
        }
    }
    mailstream_tidy();
}