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