Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 |
6a488035 TO |
39 | * @return array, with keys: |
40 | * - message: string, HTML-ish blob | |
6a488035 | 41 | */ |
00be9182 | 42 | public function run($enablePrint = TRUE) { |
6a488035 TO |
43 | // lets get around the time limit issue if possible for upgrades |
44 | if (!ini_get('safe_mode')) { | |
45 | set_time_limit(0); | |
46 | } | |
47 | ||
48 | $upgrade = new CRM_Upgrade_Form(); | |
49 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
50 | ||
51 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
52 | throw new Exception($error); | |
53 | } | |
54 | ||
55 | // Disable our SQL triggers | |
56 | CRM_Core_DAO::dropTriggers(); | |
57 | ||
58 | // CRM-11156 | |
59 | $preUpgradeMessage = NULL; | |
60 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); | |
61 | ||
62 | $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade'); | |
63 | $queueRunner = new CRM_Queue_Runner(array( | |
353ffa53 TO |
64 | 'title' => ts('CiviCRM Upgrade Tasks'), |
65 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile), | |
66 | )); | |
6a488035 TO |
67 | $queueResult = $queueRunner->runAll(); |
68 | if ($queueResult !== TRUE) { | |
69 | $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']); | |
70 | CRM_Core_Error::debug_log_message($errorMessage); | |
71 | if ($enablePrint) { | |
e418776c TO |
72 | print ($errorMessage); |
73 | } | |
6a488035 TO |
74 | throw $queueResult['exception']; // FIXME test |
75 | } | |
76 | ||
77 | CRM_Upgrade_Form::doFinish(); | |
78 | ||
6998c39d | 79 | $message = file_get_contents($postUpgradeMessageFile); |
6a488035 TO |
80 | return array( |
81 | 'latestVer' => $latestVer, | |
6998c39d ARW |
82 | 'message' => $message, |
83 | 'text' => CRM_Utils_String::htmlToText($message), | |
6a488035 TO |
84 | ); |
85 | } | |
96025800 | 86 | |
6a488035 | 87 | } |