function send($operations = null)
 {
     if (null == $operations) {
         // We're processing the entire queue, which needs to be stored as we go (maybe it doesn't but let's be safe)
         $operations = $this->operations;
         $store = true;
     } else {
         // We're processing specific ops we just created.
         // We don't need to have their timestamps stored (don't need to be locked, no other process knows about them)
         $store = false;
     }
     if (!count($operations)) {
         return false;
     }
     if (get_option('id_lock_queue') && get_option('id_lock_queue') > time()) {
         return false;
     }
     // Filter out/limit requests
     $count = 0;
     $send = array();
     $hold = array();
     foreach ($operations as $op) {
         // Got enough requests for this time?
         // Sent less than 30s ago?
         if ($count >= 10 || !empty($op->running) && time() - $op->running < 30) {
             $hold[] = $op;
             continue;
         }
         // Refresh comment data for certain requests
         if (!empty($op->action) && in_array($op->action, array('save_comment', 'comment_status')) && !empty($op->data) && isset($op->data['comment_id']) && (substr(gmdate('Y-m-d H:i:s'), 0, 18) != substr($op->time_gmt, 0, 18) || empty($op->data['comment_text']))) {
             // Reload if not from this minute or if no comment text
             $comment = new id_comment(array('comment_ID' => $op->data['comment_id']));
             $comment->loadFromWP();
             $data = $comment->export();
             $op->data = $data;
         }
         // Send this one along with a timestamp to avoid doubling up
         $op->running = time();
         $send[] = $op;
         $count++;
     }
     // Update queue to save timestamps
     $this->needs_save = true;
     $this->operations = array_merge($hold, $send);
     $fields = array('appKey' => ID_APPKEY, 'blogKey' => get_option('id_blogKey'), 'blogid' => get_option('id_blogID'), 'operations' => json_encode($send));
     // Store if necessary
     if ($store) {
         $this->store();
     }
     if (!count($send)) {
         return false;
     }
     return id_http_query($this->url . '?blogid=' . urlencode(get_option('id_blogID')), $fields, 'POST');
 }
Пример #2
0
 function send($operations = null)
 {
     if (null == $operations) {
         $operations = $this->operations;
     }
     if (!count($operations)) {
         return false;
     }
     if (get_option('id_lock_queue') && get_option('id_lock_queue') > time()) {
         return false;
     }
     // Filter out/limit requests
     $count = 0;
     $send = array();
     $hold = array();
     foreach ($operations as $op) {
         // Got enough requests for this time?
         // Sent less than 30s ago?
         if ($count >= 10 || !empty($op->running) && time() - $op->running < 30) {
             $hold[] = $op;
             continue;
         }
         // Refresh comment data for certain requests
         if (!empty($op->action) && in_array($op->action, array('save_comment', 'comment_status')) && !empty($op->data) && isset($op->data['comment_id']) && substr(gmdate('Y-m-d H:i:s'), 0, 18) != substr($op->time_gmt, 0, 18)) {
             $comment = new id_comment(array('comment_ID' => $op->data['comment_id']));
             $comment->loadFromWP();
             $data = $comment->export();
             $op->data = $data;
         }
         // Send this one along with a timestamp to avoid doubling up
         $op->running = time();
         $send[] = $op;
         $count++;
     }
     // Update queue to save timestamps
     $this->needs_save = true;
     $this->operations = array_merge($hold, $send);
     $this->store();
     $fields = array('appKey' => ID_APPKEY, 'blogKey' => get_option('id_blogKey'), 'blogid' => get_option('id_blogID'), 'operations' => json_encode($send));
     return id_http_query($this->url . '?blogid=' . urlencode(get_option('id_blogID')), $fields, 'POST');
 }