3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Perform an upgrade without using the web-frontend
15 class CRM_Upgrade_Headless
{
18 * Perform an upgrade without using the web-frontend
20 * @param bool $enablePrint
25 * - message: string, HTML-ish blob
27 public function run($enablePrint = TRUE) {
30 $upgrade = new CRM_Upgrade_Form();
31 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
33 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
34 throw new Exception($error);
37 // Disable our SQL triggers
38 CRM_Core_DAO
::dropTriggers();
41 $preUpgradeMessage = NULL;
42 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
44 $postUpgradeMessageFile = CRM_Utils_File
::tempnam('civicrm-post-upgrade');
45 $queueRunner = new CRM_Queue_Runner([
46 'title' => ts('CiviCRM Upgrade Tasks'),
47 'queue' => CRM_Upgrade_Form
::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile),
49 $queueResult = $queueRunner->runAll();
50 if ($queueResult !== TRUE) {
51 $errorMessage = CRM_Core_Error
::formatTextException($queueResult['exception']);
52 CRM_Core_Error
::debug_log_message($errorMessage);
54 print ($errorMessage);
57 throw $queueResult['exception'];
60 CRM_Upgrade_Form
::doFinish();
62 $message = file_get_contents($postUpgradeMessageFile);
64 'latestVer' => $latestVer,
65 'message' => $message,
66 'text' => CRM_Utils_String
::htmlToText($message),