コード例 #1
0
ファイル: Headless.php プロジェクト: kcristiano/civicrm-core
 /**
  * Perform an upgrade without using the web-frontend
  *
  * @param bool $enablePrint
  *
  * @throws Exception
  * @return array, with keys:
  *   - message: string, HTML-ish blob
  */
 public function run($enablePrint = TRUE)
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $upgrade = new CRM_Upgrade_Form();
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
         throw new Exception($error);
     }
     // Disable our SQL triggers
     CRM_Core_DAO::dropTriggers();
     // CRM-11156
     $preUpgradeMessage = NULL;
     $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
     $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade');
     $queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile)));
     $queueResult = $queueRunner->runAll();
     if ($queueResult !== TRUE) {
         $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
         CRM_Core_Error::debug_log_message($errorMessage);
         if ($enablePrint) {
             print $errorMessage;
         }
         throw $queueResult['exception'];
         // FIXME test
     }
     CRM_Upgrade_Form::doFinish();
     $message = file_get_contents($postUpgradeMessageFile);
     return array('latestVer' => $latestVer, 'message' => $message, 'text' => CRM_Utils_String::htmlToText($message));
 }
コード例 #2
0
 function run()
 {
     $queue = CRM_Core_Extensions_Upgrades::createQueue();
     $runner = new CRM_Queue_Runner(array('title' => ts('Database Upgrades'), 'queue' => $queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, 'onEnd' => array('CRM_Admin_Page_ExtensionsUpgrade', 'onEnd'), 'onEndUrl' => CRM_Utils_System::url(self::END_URL, self::END_PARAMS)));
     CRM_Core_Error::debug_log_message('CRM_Admin_Page_ExtensionsUpgrade: Start upgrades');
     $runner->runAllViaWeb();
     // does not return
 }
コード例 #3
0
 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
 }
コード例 #4
0
 function run()
 {
     $queue = CRM_Queue_Service::singleton()->create(array('type' => 'Sql', 'name' => self::QUEUE_NAME, 'reset' => TRUE));
     for ($i = 0; $i < 5; $i++) {
         $queue->createItem(new CRM_Queue_Task(array('CRM_Demoqueue_Page_DemoQueue', 'doMyWork'), array($i, "Task {$i} takes {$i} second(s)"), "Task {$i}"));
         if ($i == 2) {
             $queue->createItem(new CRM_Queue_Task(array('CRM_Demoqueue_Page_DemoQueue', 'addMoreWork'), array(), "Add More Work"));
         }
     }
     $runner = new CRM_Queue_Runner(array('title' => ts('Demo Queue Runner'), 'queue' => $queue, 'onEnd' => array('CRM_Demoqueue_Page_DemoQueue', 'onEnd'), 'onEndUrl' => CRM_Utils_System::url('civicrm/demo-queue/done')));
     $runner->runAllViaWeb();
     // does not return
 }
コード例 #5
0
/**
 * Upgrade an extension - runs upgrade_N hooks and system.flush.
 *
 * @return array
 *   API result
 */
function civicrm_api3_extension_upgrade()
{
    CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
    $queue = CRM_Extension_Upgrades::createQueue();
    $runner = new CRM_Queue_Runner(array('title' => 'Extension Upgrades', 'queue' => $queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT));
    try {
        $result = $runner->runAll();
    } catch (CRM_Extension_Exception $e) {
        return civicrm_api3_create_error($e->getMessage());
    }
    if ($result === TRUE) {
        return civicrm_api3_create_success();
    } else {
        return $result;
    }
}
コード例 #6
0
function civicrm_api3_civi_mailchimp_sync($params)
{
    CRM_CiviMailchimp_BAO_SyncLog::deleteOldMessages();
    $records_to_process = $params['records_to_process_per_run'];
    $queue = CRM_Queue_Service::singleton()->create(array('type' => 'Sql', 'name' => 'mailchimp-sync', 'reset' => FALSE));
    if ($queue->numberOfItems() > 0) {
        $runner = new CRM_Queue_Runner(array('title' => ts('Sync Contacts to Mailchimp'), 'queue' => $queue));
        $continue_to_next_item = TRUE;
        $records_processed = 0;
        while ($continue_to_next_item && $records_processed < $records_to_process) {
            $record = $runner->runNext();
            if ($record['is_error']) {
                // Get the current Queue Item being worked on to allow for better error
                // reporting and logging.
                $query = "\n          SELECT\n            id,\n            data\n          FROM\n            civicrm_queue_item\n          WHERE\n            queue_name = 'mailchimp-sync'\n          ORDER BY\n            weight ASC,\n            id ASC\n          LIMIT 1\n        ";
                $item = CRM_Core_DAO::executeQuery($query);
                while ($item->fetch()) {
                    $item_data = unserialize($item->data);
                    $message = "[{$item_data->arguments[0]}] There was an error syncing contacts to Mailchimp.";
                    $exception_name = '';
                    if (!empty($record['exception'])) {
                        $exception_name = get_class($record['exception']);
                        $message = "[{$item_data->arguments[0]}] {$exception_name}: {$record['exception']->getMessage()}.";
                    }
                    $message .= " Mailchimp List ID: {$item_data->arguments[1]}. {$records_processed} records were successfully synced before this error.";
                    $error = array('code' => $exception_name, 'message' => $message, 'exception' => $record['exception']);
                    CRM_Core_Error::debug_var('Fatal Error Details', $error);
                    CRM_Core_Error::backtrace('backTrace', TRUE);
                    CRM_CiviMailchimp_BAO_SyncLog::saveMessage('error', 'civicrm_to_mailchimp', $message, $item_data, $item->id);
                    return civicrm_api3_create_error($message);
                }
            }
            $continue_to_next_item = $record['is_continue'];
            $records_processed++;
        }
        $message = ts('%1 records were successfully synced to Mailchimp.', array(1 => $records_processed));
        CRM_CiviMailchimp_BAO_SyncLog::saveMessage('success', 'civicrm_to_mailchimp', $message);
        return civicrm_api3_create_success($records_processed);
    }
}
コード例 #7
0
ファイル: AJAX.php プロジェクト: prashantgajare/civicrm-core
 /**
  * Run the next task and return status information
  *
  * @return array(is_error => bool, is_continue => bool, numberOfItems => int, exception => htmlString)
  */
 static function onEnd()
 {
     $errorPolicy = new CRM_Queue_ErrorPolicy();
     $errorPolicy->call(function () {
         global $activeQueueRunner;
         $qrid = CRM_Utils_Request::retrieve('qrid', 'String', CRM_Core_DAO::$_nullObject, TRUE, NULL, 'POST');
         $activeQueueRunner = CRM_Queue_Runner::instance($qrid);
         if (!is_object($activeQueueRunner)) {
             throw new Exception('Queue runner must be configured before execution. - onEnd');
         }
         $result = $activeQueueRunner->handleEnd(FALSE);
         CRM_Queue_Page_AJAX::_return('onEnd', $result);
     });
 }
コード例 #8
0
 /**
  * Process delayed actions
  *
  * @param int $maxRunTime
  * @return array
  */
 public static function processDelayedActions($maxRunTime = 30)
 {
     $queue = CRM_Queue_Service::singleton()->create(array('type' => 'Civirules', 'name' => self::QUEUE_NAME, 'reset' => false));
     $returnValues = array();
     //retrieve the queue
     $runner = new CRM_Queue_Runner(array('title' => ts('Process delayed civirules actions'), 'queue' => $queue, 'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE));
     $stopTime = time() + $maxRunTime;
     //stop executing next item after 30 seconds
     while (time() < $stopTime && $queue->numberOfItems() > 0) {
         $result = $runner->runNext(false);
         $returnValues[] = $result;
         if (!$result['is_continue']) {
             break;
         }
     }
     return $returnValues;
 }
コード例 #9
0
 /**
  *
  * POST Param 'qrid': string, usually the name of the queue
  */
 function run()
 {
     $qrid = CRM_Utils_Request::retrieve('qrid', 'String', $this, TRUE);
     $runner = CRM_Queue_Runner::instance($qrid);
     // dpm(array( 'action' => 'CRM_Queue_Page_Runner::run()', 'session' => $_SESSION, 'runner' => $runner, 'qrid' => $qrid ));
     if (!is_object($runner)) {
         CRM_Core_Error::fatal('Queue runner must be configured before execution.');
     }
     CRM_Utils_System::setTitle($runner->title);
     $this->assign('queueRunnerData', array('qrid' => $runner->qrid, 'runNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/runNext', NULL, FALSE, NULL, FALSE), 'skipNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/skipNext', NULL, FALSE, NULL, FALSE), 'onEndAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/onEnd', NULL, FALSE, NULL, FALSE), 'completed' => 0, 'numberOfItems' => $runner->queue->numberOfItems(), 'buttons' => $runner->buttons));
     if ($runner->isMinimal) {
         $smarty = CRM_Core_Smarty::singleton();
         $content = $smarty->fetch('CRM/Queue/Page/Runner.tpl');
         echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print, FALSE, TRUE);
     } else {
         parent::run();
     }
 }
コード例 #10
0
ファイル: Runner.php プロジェクト: kcristiano/civicrm-core
 /**
  *
  * POST Param 'qrid': string, usually the name of the queue
  */
 public function run()
 {
     $qrid = CRM_Utils_Request::retrieve('qrid', 'String', $this, TRUE);
     $runner = CRM_Queue_Runner::instance($qrid);
     if (!is_object($runner)) {
         CRM_Core_Error::fatal('Queue runner must be configured before execution.');
     }
     CRM_Utils_System::setTitle($runner->title);
     $this->assign('queueRunnerData', array('qrid' => $runner->qrid, 'runNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/runNext', NULL, FALSE, NULL, FALSE), 'skipNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/skipNext', NULL, FALSE, NULL, FALSE), 'onEndAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/onEnd', NULL, FALSE, NULL, FALSE), 'completed' => 0, 'numberOfItems' => $runner->queue->numberOfItems(), 'buttons' => $runner->buttons));
     if ($runner->isMinimal) {
         // Render page header
         if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) {
             CRM_Utils_System::addHTMLHead($region->render(''));
         }
         $smarty = CRM_Core_Smarty::singleton();
         $content = $smarty->fetch('CRM/Queue/Page/Runner.tpl');
         echo CRM_Utils_System::theme($content, $this->_print, TRUE);
     } else {
         parent::run();
     }
 }
コード例 #11
0
ファイル: RunnerTest.php プロジェクト: nielosz/civicrm-core
 /**
  * Run a series of tasks; when one returns false,
  * abort processing and return it to the queue.
  */
 public function testRunAll_Abort_False()
 {
     // prepare a list of tasks with an error in the middle
     $this->queue->createItem(new CRM_Queue_Task(array('CRM_Queue_RunnerTest', '_recordValue'), array('a'), 'Add "a"'));
     $this->queue->createItem(new CRM_Queue_Task(array('CRM_Queue_RunnerTest', '_returnFalse'), array(), 'Return false'));
     $this->queue->createItem(new CRM_Queue_Task(array('CRM_Queue_RunnerTest', '_recordValue'), array('c'), 'Add "c"'));
     // run the list of tasks
     $runner = new CRM_Queue_Runner(array('queue' => $this->queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT));
     $this->assertEquals(self::$_recordedValues, array());
     $this->assertEquals(3, $this->queue->numberOfItems());
     $result = $runner->runAll();
     $this->assertEquals(1, $result['is_error']);
     // nothing from 'c'
     $this->assertEquals(self::$_recordedValues, array('a'));
     // 'b' and 'c' remain
     $this->assertEquals(2, $this->queue->numberOfItems());
 }
コード例 #12
0
ファイル: Upgrade.php プロジェクト: rameshrr99/civicrm-core
 /**
  * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner
  */
 public function runBegin()
 {
     $upgrade = new CRM_Upgrade_Form();
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
         CRM_Core_Error::fatal($error);
     }
     $config = CRM_Core_Config::singleton();
     $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful!') . '</span>';
     // lets drop all the triggers here
     CRM_Core_DAO::dropTriggers();
     $this->set('isUpgradePending', TRUE);
     // Persistent message storage across upgrade steps. TODO: Use structured message store
     // Note: In clustered deployments, this file must be accessible by all web-workers.
     $this->set('postUpgradeMessageFile', CRM_Utils_File::tempnam('civicrm-post-upgrade'));
     file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage);
     $queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')), 'isMinimal' => TRUE, 'pathPrefix' => 'civicrm/upgrade/queue', 'onEndUrl' => CRM_Utils_System::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE), 'buttons' => array('retry' => $config->debug, 'skip' => $config->debug)));
     $queueRunner->runAllViaWeb();
     CRM_Core_Error::fatal(ts('Upgrade failed to redirect'));
 }
コード例 #13
0
 function postProcess()
 {
     $current_status_ids = array();
     $dao = CRM_Core_DAO::executeQuery("SELECT id from civicrm_membership_status where is_current_member = 1");
     while ($dao->fetch()) {
         $current_status_ids[] = $dao->id;
     }
     $formValues = $this->exportValues();
     if (!isset($formValues['member_status_id'])) {
         $formValues['member_status_id'] = array();
     }
     $birth_date_from = CRM_Utils_Date::processDate($formValues['birth_date_from']);
     $birth_date_to = CRM_Utils_Date::processDate($formValues['birth_date_to']);
     $selector = new CRM_Rood_UpgradeSelector();
     $original_where = $selector->getWhere();
     $selector->setData($formValues['rood_mtype'], array_keys($formValues['member_status_id']), $birth_date_from, $birth_date_to);
     $selector->store();
     $where = $selector->getWhere();
     $count = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*)\n      FROM civicrm_membership\n      INNER JOIN civicrm_contact ON civicrm_membership.contact_id = civicrm_contact.id\n      LEFT JOIN civicrm_membership sp_membership ON civicrm_contact.id = sp_membership.contact_id AND sp_membership.membership_type_id = '{$formValues['sp_mtype']}' AND sp_membership.status_id IN (" . implode(', ', $current_status_ids) . ")\n      " . $where . " AND sp_membership.id is null");
     $this->assign('found', $count);
     if ($where == $original_where && isset($_POST['continue']) && !empty($_POST['continue'])) {
         $queue = CRM_Queue_Service::singleton()->create(array('type' => 'Sql', 'name' => 'nl.sp.rood.upgrade', 'reset' => TRUE));
         $dao = CRM_Core_DAO::executeQuery("SELECT civicrm_membership.id\n       FROM civicrm_membership\n      INNER JOIN civicrm_contact ON civicrm_membership.contact_id = civicrm_contact.id\n      LEFT JOIN civicrm_membership sp_membership ON civicrm_contact.id = sp_membership.contact_id AND sp_membership.membership_type_id = '{$formValues['sp_mtype']}' AND sp_membership.status_id IN (" . implode(', ', $current_status_ids) . ")\n      " . $where . " AND sp_membership.id is null\n      ");
         $i = 1;
         while ($dao->fetch()) {
             $title = ts('Upgrade Rood lidmaatschappen %1 van %2', array(1 => $i, 2 => $count));
             //create a task without parameters
             $task = new CRM_Queue_Task(array('CRM_Rood_MembershipUpgrade', 'UpgradeFromQueue'), array($dao->id, $formValues), $title);
             //now add this task to the queue
             $queue->createItem($task);
             $i++;
         }
         $runner = new CRM_Queue_Runner(array('title' => ts('Upgrade rood lidmaatschappen'), 'queue' => $queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, 'onEnd' => array('CRM_Rood_Form_UpgradeRoodMembership', 'onEnd'), 'onEndUrl' => CRM_Utils_System::url('civicrm/member/upgrade_rood', 'reset=1')));
         $runner->runAllViaWeb();
         // does not return
     }
 }
コード例 #14
0
 /**
  * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner
  */
 function runBegin()
 {
     $upgrade = new CRM_Upgrade_Form();
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
         CRM_Core_Error::fatal($error);
     }
     $config = CRM_Core_Config::singleton();
     // This could be removed in later rev
     if ($currentVer == '2.1.6') {
         // also cleanup the templates_c directory
         $config->cleanupCaches();
     }
     // end of hack
     $postUpgradeMessage = ts('CiviCRM upgrade was successful.');
     // Persistent message storage across upgrade steps. TODO: Use structured message store
     // Note: In clustered deployments, this file must be accessible by all web-workers.
     $this->set('postUpgradeMessageFile', CRM_Utils_File::tempnam('civicrm-post-upgrade'));
     file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage);
     $queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')), 'isMinimal' => TRUE, 'pathPrefix' => 'civicrm/upgrade/queue', 'onEndUrl' => CRM_Utils_System::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE), 'buttons' => array('retry' => $config->debug, 'skip' => $config->debug)));
     $queueRunner->runAllViaWeb();
     CRM_Core_Error::fatal(ts('Upgrade failed to redirect'));
 }