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