/** * 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)); }
/** * 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; } }
/** * 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()); }