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 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Upgrade_Page_Upgrade extends CRM_Core_Page { | |
e8e8f3ad | 18 | |
19 | /** | |
20 | * Pre-process. | |
21 | */ | |
00be9182 | 22 | public function preProcess() { |
6a488035 TO |
23 | parent::preProcess(); |
24 | } | |
25 | ||
70599df6 | 26 | /** |
27 | * Run upgrade. | |
28 | * | |
29 | * @throws \Exception | |
30 | */ | |
00be9182 | 31 | public function run() { |
6a488035 TO |
32 | // lets get around the time limit issue if possible for upgrades |
33 | if (!ini_get('safe_mode')) { | |
34 | set_time_limit(0); | |
35 | } | |
36 | ||
4ef8abc2 CW |
37 | Civi::resources()->addStyleFile('civicrm', 'css/admin.css'); |
38 | ||
6a488035 TO |
39 | $upgrade = new CRM_Upgrade_Form(); |
40 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
41 | ||
42 | CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', | |
be2fb01f | 43 | [1 => $latestVer] |
6a488035 TO |
44 | )); |
45 | ||
46 | $template = CRM_Core_Smarty::singleton(); | |
47 | $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', | |
be2fb01f | 48 | [1 => $latestVer] |
6a488035 | 49 | )); |
6a488035 TO |
50 | $template->assign('cancelURL', |
51 | CRM_Utils_System::url('civicrm/dashboard', 'reset=1') | |
52 | ); | |
53 | ||
54 | $action = CRM_Utils_Array::value('action', $_REQUEST, 'intro'); | |
55 | switch ($action) { | |
56 | case 'intro': | |
57 | $this->runIntro(); | |
58 | break; | |
59 | ||
60 | case 'begin': | |
61 | $this->runBegin(); | |
62 | break; | |
63 | ||
64 | case 'finish': | |
65 | $this->runFinish(); | |
66 | break; | |
67 | ||
68 | default: | |
800dad43 | 69 | throw new CRM_Core_Exception(ts('Unrecognized upgrade action')); |
6a488035 TO |
70 | } |
71 | } | |
72 | ||
73 | /** | |
e8e8f3ad | 74 | * Display an introductory screen with any pre-upgrade messages. |
6a488035 | 75 | */ |
00be9182 | 76 | public function runIntro() { |
6a488035 TO |
77 | $upgrade = new CRM_Upgrade_Form(); |
78 | $template = CRM_Core_Smarty::singleton(); | |
79 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
80 | ||
81 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
800dad43 | 82 | throw new CRM_Core_Exception($error); |
6a488035 TO |
83 | } |
84 | ||
cb0a8786 CW |
85 | $config = CRM_Core_Config::singleton(); |
86 | ||
6633dcbf | 87 | // All cached content needs to be cleared because the civi codebase was just replaced |
4cc9b813 | 88 | CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode(); |
6633dcbf | 89 | |
221997c6 CW |
90 | // cleanup only the templates_c directory |
91 | $config->cleanup(1, FALSE); | |
6a488035 TO |
92 | |
93 | $preUpgradeMessage = NULL; | |
94 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); | |
95 | ||
96 | $template->assign('currentVersion', $currentVer); | |
97 | $template->assign('newVersion', $latestVer); | |
98 | $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', | |
be2fb01f | 99 | [1 => $currentVer, 2 => $latestVer] |
6a488035 TO |
100 | )); |
101 | $template->assign('upgraded', FALSE); | |
102 | ||
103 | // Render page header | |
9dc21423 | 104 | if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) { |
6a488035 TO |
105 | CRM_Utils_System::addHTMLHead($region->render('')); |
106 | } | |
107 | ||
108 | $template->assign('preUpgradeMessage', $preUpgradeMessage); | |
6a488035 TO |
109 | |
110 | $content = $template->fetch('CRM/common/success.tpl'); | |
111 | echo CRM_Utils_System::theme($content, $this->_print, TRUE); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner | |
116 | */ | |
00be9182 | 117 | public function runBegin() { |
6a488035 TO |
118 | $upgrade = new CRM_Upgrade_Form(); |
119 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
120 | ||
121 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
800dad43 | 122 | throw new CRM_Core_Exception($error); |
6a488035 TO |
123 | } |
124 | ||
125 | $config = CRM_Core_Config::singleton(); | |
6a488035 | 126 | |
3a111e86 | 127 | $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful!') . '</span>'; |
6a488035 TO |
128 | |
129 | // lets drop all the triggers here | |
130 | CRM_Core_DAO::dropTriggers(); | |
131 | ||
c76e6d43 TO |
132 | $this->set('isUpgradePending', TRUE); |
133 | ||
6a488035 TO |
134 | // Persistent message storage across upgrade steps. TODO: Use structured message store |
135 | // Note: In clustered deployments, this file must be accessible by all web-workers. | |
136 | $this->set('postUpgradeMessageFile', CRM_Utils_File::tempnam('civicrm-post-upgrade')); | |
137 | file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage); | |
138 | ||
be2fb01f | 139 | $queueRunner = new CRM_Queue_Runner([ |
6a488035 TO |
140 | 'title' => ts('CiviCRM Upgrade Tasks'), |
141 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')), | |
142 | 'isMinimal' => TRUE, | |
143 | 'pathPrefix' => 'civicrm/upgrade/queue', | |
481a74f4 | 144 | 'onEndUrl' => CRM_Utils_System::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE), |
be2fb01f CW |
145 | 'buttons' => ['retry' => $config->debug, 'skip' => $config->debug], |
146 | ]); | |
6a488035 | 147 | $queueRunner->runAllViaWeb(); |
800dad43 | 148 | throw new CRM_Core_Exception(ts('Upgrade failed to redirect')); |
6a488035 TO |
149 | } |
150 | ||
151 | /** | |
152 | * Display any final messages, clear caches, etc | |
153 | */ | |
00be9182 | 154 | public function runFinish() { |
6a488035 TO |
155 | $upgrade = new CRM_Upgrade_Form(); |
156 | $template = CRM_Core_Smarty::singleton(); | |
157 | ||
c76e6d43 TO |
158 | // If we're redirected from queue-runner, then isUpgradePending=true. |
159 | // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.) | |
160 | if ($this->get('isUpgradePending')) { | |
43992531 TO |
161 | // TODO: Use structured message store |
162 | $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile')); | |
6a488035 | 163 | |
43992531 TO |
164 | // This destroys $session, so do it after get('postUpgradeMessageFile') |
165 | CRM_Upgrade_Form::doFinish(); | |
0db6c3e1 TO |
166 | } |
167 | else { | |
3655bea4 SL |
168 | // Session was destroyed! Can't recover messages. |
169 | $postUpgradeMessage = ''; | |
43992531 | 170 | } |
6a488035 TO |
171 | |
172 | // do a version check - after doFinish() sets the final version | |
173 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
174 | if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) { | |
800dad43 | 175 | throw new CRM_Core_Exception($error); |
6a488035 TO |
176 | } |
177 | ||
178 | $template->assign('message', $postUpgradeMessage); | |
179 | $template->assign('upgraded', TRUE); | |
202407d7 | 180 | $template->assign('sid', CRM_Utils_System::getSiteID()); |
a343bebf | 181 | $template->assign('newVersion', $latestVer); |
6a488035 TO |
182 | |
183 | // Render page header | |
9dc21423 | 184 | if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) { |
6a488035 TO |
185 | CRM_Utils_System::addHTMLHead($region->render('')); |
186 | } | |
187 | ||
188 | $content = $template->fetch('CRM/common/success.tpl'); | |
189 | echo CRM_Utils_System::theme($content, $this->_print, TRUE); | |
190 | } | |
96025800 | 191 | |
6a488035 | 192 | } |