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) {
28 // lets get around the time limit issue if possible for upgrades
29 if (!ini_get('safe_mode')) {
33 $upgrade = new CRM_Upgrade_Form();
34 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
36 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
37 throw new Exception($error);
40 // Disable our SQL triggers
41 CRM_Core_DAO
::dropTriggers();
44 $preUpgradeMessage = NULL;
45 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
47 $postUpgradeMessageFile = CRM_Utils_File
::tempnam('civicrm-post-upgrade');
48 $queueRunner = new CRM_Queue_Runner([
49 'title' => ts('CiviCRM Upgrade Tasks'),
50 'queue' => CRM_Upgrade_Form
::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile),
52 $queueResult = $queueRunner->runAll();
53 if ($queueResult !== TRUE) {
54 $errorMessage = CRM_Core_Error
::formatTextException($queueResult['exception']);
55 CRM_Core_Error
::debug_log_message($errorMessage);
57 print ($errorMessage);
60 throw $queueResult['exception'];
63 CRM_Upgrade_Form
::doFinish();
65 $message = file_get_contents($postUpgradeMessageFile);
67 'latestVer' => $latestVer,
68 'message' => $message,
69 'text' => CRM_Utils_String
::htmlToText($message),