Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * Perform an upgrade without using the web-frontend | |
30 | */ | |
31 | class CRM_Upgrade_Headless { | |
32 | ||
33 | /** | |
34 | * Perform an upgrade without using the web-frontend | |
35 | * | |
77b97be7 EM |
36 | * @param bool $enablePrint |
37 | * | |
77b97be7 | 38 | * @throws Exception |
3655bea4 SL |
39 | * @return array |
40 | * - with keys: | |
6a488035 | 41 | * - message: string, HTML-ish blob |
6a488035 | 42 | */ |
00be9182 | 43 | public function run($enablePrint = TRUE) { |
6a488035 TO |
44 | // lets get around the time limit issue if possible for upgrades |
45 | if (!ini_get('safe_mode')) { | |
46 | set_time_limit(0); | |
47 | } | |
48 | ||
49 | $upgrade = new CRM_Upgrade_Form(); | |
50 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
51 | ||
52 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
53 | throw new Exception($error); | |
54 | } | |
55 | ||
56 | // Disable our SQL triggers | |
57 | CRM_Core_DAO::dropTriggers(); | |
58 | ||
59 | // CRM-11156 | |
60 | $preUpgradeMessage = NULL; | |
61 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); | |
62 | ||
63 | $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade'); | |
be2fb01f | 64 | $queueRunner = new CRM_Queue_Runner([ |
353ffa53 TO |
65 | 'title' => ts('CiviCRM Upgrade Tasks'), |
66 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile), | |
be2fb01f | 67 | ]); |
6a488035 TO |
68 | $queueResult = $queueRunner->runAll(); |
69 | if ($queueResult !== TRUE) { | |
70 | $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']); | |
71 | CRM_Core_Error::debug_log_message($errorMessage); | |
72 | if ($enablePrint) { | |
e418776c TO |
73 | print ($errorMessage); |
74 | } | |
3655bea4 SL |
75 | // FIXME test |
76 | throw $queueResult['exception']; | |
6a488035 TO |
77 | } |
78 | ||
79 | CRM_Upgrade_Form::doFinish(); | |
80 | ||
6998c39d | 81 | $message = file_get_contents($postUpgradeMessageFile); |
be2fb01f | 82 | return [ |
6a488035 | 83 | 'latestVer' => $latestVer, |
6998c39d ARW |
84 | 'message' => $message, |
85 | 'text' => CRM_Utils_String::htmlToText($message), | |
be2fb01f | 86 | ]; |
6a488035 | 87 | } |
96025800 | 88 | |
6a488035 | 89 | } |