Exemplo n.º 1
0
 /**
  * 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));
 }
Exemplo n.º 2
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  */
 public function log($level, $message, array $context = array())
 {
     // FIXME: This flattens a $context a bit prematurely. When integrating
     // with external/CMS logs, we should pass through $context.
     if (!empty($context)) {
         if (isset($context['exception'])) {
             $context['exception'] = CRM_Core_Error::formatTextException($context['exception']);
         }
         $message .= "\n" . print_r($context, 1);
     }
     CRM_Core_Error::debug_log_message($message, FALSE, '', $this->map[$level]);
 }
Exemplo n.º 3
0
 /**
  * Print an unhandled exception
  *
  * @param $e
  */
 function reportException(Exception $e)
 {
     CRM_Core_Error::debug_var('CRM_Queue_ErrorPolicy_reportException', CRM_Core_Error::formatTextException($e));
     $response = array('is_error' => 1, 'is_continue' => 0);
     $config = CRM_Core_Config::singleton();
     if ($config->backtrace || CRM_Core_Config::isUpgradeMode()) {
         $response['exception'] = CRM_Core_Error::formatHtmlException($e);
     } else {
         $response['exception'] = htmlentities($e->getMessage());
     }
     global $activeQueueRunner;
     if (is_object($activeQueueRunner)) {
         $response['last_task_title'] = $activeQueueRunner->lastTaskTitle;
     }
     CRM_Utils_JSON::output($response);
 }
Exemplo n.º 4
0
 /**
  * Performing any view-layer filtering on result and send to client.
  */
 static function _return($op, $result)
 {
     if ($result['is_error']) {
         if (is_object($result['exception'])) {
             CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", CRM_Core_Error::formatTextException($result['exception']));
             $config = CRM_Core_Config::singleton();
             if ($config->backtrace || CRM_Core_Config::isUpgradeMode()) {
                 $result['exception'] = CRM_Core_Error::formatHtmlException($result['exception']);
             } else {
                 $result['exception'] = $result['exception']->getMessage();
             }
         } else {
             CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", $result);
         }
     }
     CRM_Utils_JSON::output($result);
 }
Exemplo n.º 5
0
 /**
  * Override to run the test and assert its state.
  * @return mixed
  * @throws \Exception
  * @throws \PHPUnit_Framework_IncompleteTest
  * @throws \PHPUnit_Framework_SkippedTest
  */
 protected function runTest()
 {
     try {
         return parent::runTest();
     } catch (PEAR_Exception $e) {
         // PEAR_Exception has metadata in funny places, and PHPUnit won't log it nicely
         throw new Exception(\CRM_Core_Error::formatTextException($e), $e->getCode());
     }
 }