/** * Add a new item to the queue. * * @param mixed $data * Serializable PHP object or array. * @param array $options * Queue-dependent options; for example, if this is a * priority-queue, then $options might specify the item's priority. */ public function createItem($data, $options = array()) { $dao = new CRM_Queue_DAO_QueueItem(); $dao->queue_name = $this->getName(); $dao->submit_time = CRM_Utils_Time::getTime('YmdHis'); $dao->data = serialize($data); $dao->weight = CRM_Utils_Array::value('weight', $options, 0); $dao->save(); }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['queue_item'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * Save an action into a queue for delayed processing * * @param \DateTime $delayTo * @param \CRM_Civirules_Action $action * @param \CRM_Civirules_TriggerData_TriggerData $triggerData */ protected static function delayAction(DateTime $delayTo, CRM_Civirules_Action $action, CRM_Civirules_TriggerData_TriggerData $triggerData) { $queue = CRM_Queue_Service::singleton()->create(array('type' => 'Civirules', 'name' => self::QUEUE_NAME, 'reset' => false)); //create a task with the action and eventData as parameters $task = new CRM_Queue_Task(array('CRM_Civirules_Engine', 'executeDelayedAction'), array($action, $triggerData)); //save the task with a delay $dao = new CRM_Queue_DAO_QueueItem(); $dao->queue_name = $queue->getName(); $dao->submit_time = CRM_Utils_Time::getTime('YmdHis'); $dao->data = serialize($task); $dao->weight = 0; //weight, normal priority $dao->release_time = $delayTo->format('YmdHis'); $dao->save(); }