Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
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 | * | |
77b97be7 EM |
20 | * @param bool $enablePrint |
21 | * | |
77b97be7 | 22 | * @throws Exception |
3655bea4 SL |
23 | * @return array |
24 | * - with keys: | |
6a488035 | 25 | * - message: string, HTML-ish blob |
6a488035 | 26 | */ |
00be9182 | 27 | public function run($enablePrint = TRUE) { |
4d03ddb9 | 28 | set_time_limit(0); |
6a488035 TO |
29 | |
30 | $upgrade = new CRM_Upgrade_Form(); | |
31 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
32 | ||
33 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
34 | throw new Exception($error); | |
35 | } | |
36 | ||
37 | // Disable our SQL triggers | |
38 | CRM_Core_DAO::dropTriggers(); | |
39 | ||
40 | // CRM-11156 | |
41 | $preUpgradeMessage = NULL; | |
42 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); | |
43 | ||
44 | $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade'); | |
be2fb01f | 45 | $queueRunner = new CRM_Queue_Runner([ |
353ffa53 TO |
46 | 'title' => ts('CiviCRM Upgrade Tasks'), |
47 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile), | |
be2fb01f | 48 | ]); |
6a488035 TO |
49 | $queueResult = $queueRunner->runAll(); |
50 | if ($queueResult !== TRUE) { | |
51 | $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']); | |
52 | CRM_Core_Error::debug_log_message($errorMessage); | |
53 | if ($enablePrint) { | |
e418776c TO |
54 | print ($errorMessage); |
55 | } | |
3655bea4 SL |
56 | // FIXME test |
57 | throw $queueResult['exception']; | |
6a488035 TO |
58 | } |
59 | ||
60 | CRM_Upgrade_Form::doFinish(); | |
61 | ||
6998c39d | 62 | $message = file_get_contents($postUpgradeMessageFile); |
be2fb01f | 63 | return [ |
6a488035 | 64 | 'latestVer' => $latestVer, |
6998c39d ARW |
65 | 'message' => $message, |
66 | 'text' => CRM_Utils_String::htmlToText($message), | |
be2fb01f | 67 | ]; |
6a488035 | 68 | } |
96025800 | 69 | |
6a488035 | 70 | } |