Merge pull request #19453 from demeritcowboy/translate
[civicrm-core.git] / CRM / Upgrade / Headless.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Perform an upgrade without using the web-frontend
14 */
15 class CRM_Upgrade_Headless {
16
17 /**
18 * Perform an upgrade without using the web-frontend
19 *
20 * @param bool $enablePrint
21 *
22 * @throws Exception
23 * @return array
24 * - with keys:
25 * - message: string, HTML-ish blob
26 */
27 public function run($enablePrint = TRUE) {
28 // lets get around the time limit issue if possible for upgrades
29 if (!ini_get('safe_mode')) {
30 set_time_limit(0);
31 }
32
33 $upgrade = new CRM_Upgrade_Form();
34 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
35
36 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
37 throw new Exception($error);
38 }
39
40 // Disable our SQL triggers
41 CRM_Core_DAO::dropTriggers();
42
43 // CRM-11156
44 $preUpgradeMessage = NULL;
45 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
46
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),
51 ]);
52 $queueResult = $queueRunner->runAll();
53 if ($queueResult !== TRUE) {
54 $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
55 CRM_Core_Error::debug_log_message($errorMessage);
56 if ($enablePrint) {
57 print ($errorMessage);
58 }
59 // FIXME test
60 throw $queueResult['exception'];
61 }
62
63 CRM_Upgrade_Form::doFinish();
64
65 $message = file_get_contents($postUpgradeMessageFile);
66 return [
67 'latestVer' => $latestVer,
68 'message' => $message,
69 'text' => CRM_Utils_String::htmlToText($message),
70 ];
71 }
72
73 }