]> git.mxchange.org Git - friendica.git/blobdiff - include/queue.php
better (more consistent) handling of ostatus contacts
[friendica.git] / include / queue.php
index ff280cb53b006f90e6d5d000ef808fbd3626f607..fb65d5c25bcbaf88e91815a98c2f9a11259a0473 100644 (file)
@@ -1,20 +1,6 @@
 <?php
 require_once("boot.php");
-
-function update_queue_time($id) {
-       logger('queue: requeue item ' . $id);
-       q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d LIMIT 1",
-               dbesc(datetime_convert()),
-               intval($id)
-       );
-}
-
-function remove_queue_item($id) {
-       logger('queue: remove queue item ' . $id);
-       q("DELETE FROM `queue` WHERE `id` = %d LIMIT 1",
-               intval($id)
-       );
-}
+require_once('include/queue_fn.php');
 
 function queue_run($argv, $argc){
   global $a, $db;
@@ -36,8 +22,13 @@ function queue_run($argv, $argc){
        require_once('include/items.php');
        require_once('include/bbcode.php');
 
+       load_config('config');
+       load_config('system');
+
        $a->set_baseurl(get_config('system','url'));
 
+       load_hooks();
+
        $deadguys = array();
 
        logger('queue: start');
@@ -58,17 +49,26 @@ function queue_run($argv, $argc){
        if(! count($r)){
                return;
        }
+
+       call_hooks('queue_predeliver', $a, $r);
+
+
        // delivery loop
 
        require_once('include/salmon.php');
 
        foreach($r as $q_item) {
-               $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
+
+               // queue_predeliver hooks may have changed the queue db details, 
+               // so check again if this entry still needs processing
+
+               $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
                        intval($q_item['id'])
                );
                if(! count($qi))
                        continue;
 
+
                $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
                        intval($qi[0]['cid'])
                );
@@ -121,7 +121,6 @@ function queue_run($argv, $argc){
                                }
                                break;
                        default:
-                               $a = get_app();
                                $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
                                call_hooks('queue_deliver', $a, $params);