/** * Get an item to process. * * @return mixed False if no item to proceed. */ public static function getItem() { $item = false; $db = Pluf::db(); $db->begin(); // In a transaction to not process the same item at // the same time from to processes. $gqueue = new Pluf_Queue(); $items = $gqueue->getList(array('filter' => $db->qn('lock') . '=0', 'order' => 'creation_dtime ASC')); if ($items->count() > 0) { $item = $items[0]; $item->lock = 1; $item->update(); } $db->commit(); if ($item === false) { return false; } // try to get the corresponding object $obj = Pluf::factory($item->model_class, $item->model_id); if ($obj->id != $item->model_id) { $obj = null; } return array('queue' => $item, 'item' => $obj); }
/** * Add an object to the queue. * * @param Pluf_Model Your model * @param string Action for the object */ public static function addTo($object, $action = '') { $q = new Pluf_Queue(); $q->model_class = $object->_model; $q->model_id = $object->id; $q->lock = 0; $q->action = $action; $q->create(); }