/** * @return CRM_Chapters_UpdateQueue */ public static function singleton() { if (!self::$singleton) { self::$singleton = new CRM_Chapters_UpdateQueue(); } return self::$singleton; }
function run() { //retrieve the queue $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, 0); $queue = CRM_Chapters_UpdateQueue::singleton()->getQueue(); $runner = new CRM_Queue_Runner(array('title' => ts('Update contacts'), 'queue' => $queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, 'onEnd' => array('CRM_Chapters_Page_UpdateAllContacts', 'onEnd'), 'onEndUrl' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&selectedChild=tab_automatch_chapters&cid=' . $cid, true, null, false))); $runner->runAllViaWeb(); // does not return }
protected function updateAllContacts() { $queue = CRM_Chapters_UpdateQueue::singleton()->getQueue(); $max_contacts = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM civicrm_contact WHERE is_deleted = 0"); for ($i = 0; $i < $max_contacts; $i = $i + 500) { //create a task without parameters $task = new CRM_Queue_Task(array('CRM_Chapters_Matcher', 'updateAllContacts'), array($i, 500)); //now add this task to the queue $queue->createItem($task); } $redirectUrl = CRM_Utils_System::url('civicrm/chapters/update_all_contacts', 'reset=1&cid=' . $this->contact_id, TRUE); CRM_Utils_System::redirect($redirectUrl); }