Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Upgrade_Page_Upgrade extends CRM_Core_Page { | |
36 | function preProcess() { | |
37 | parent::preProcess(); | |
38 | } | |
39 | ||
40 | function run() { | |
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 | */ | |
83 | function runIntro() { | |
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 | ||
6633dcbf | 92 | // All cached content needs to be cleared because the civi codebase was just replaced |
4cc9b813 CW |
93 | CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode(); |
94 | CRM_Core_Menu::store(); | |
6633dcbf | 95 | |
6a488035 TO |
96 | // This could be removed in later rev |
97 | if ($currentVer == '2.1.6') { | |
98 | $config = CRM_Core_Config::singleton(); | |
99 | // also cleanup the templates_c directory | |
100 | $config->cleanupCaches(); | |
101 | } else { | |
102 | $config = CRM_Core_Config::singleton(); | |
103 | // cleanup only the templates_c directory | |
104 | $config->cleanup(1, FALSE); | |
105 | } | |
106 | // end of hack | |
107 | ||
108 | $preUpgradeMessage = NULL; | |
109 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); | |
110 | ||
111 | $template->assign('currentVersion', $currentVer); | |
112 | $template->assign('newVersion', $latestVer); | |
113 | $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', | |
114 | array(1 => $currentVer, 2 => $latestVer) | |
115 | )); | |
116 | $template->assign('upgraded', FALSE); | |
117 | ||
118 | // Render page header | |
9dc21423 | 119 | if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) { |
6a488035 TO |
120 | CRM_Utils_System::addHTMLHead($region->render('')); |
121 | } | |
122 | ||
123 | $template->assign('preUpgradeMessage', $preUpgradeMessage); | |
124 | // $template->assign( 'message', $postUpgradeMessage ); | |
125 | ||
126 | $content = $template->fetch('CRM/common/success.tpl'); | |
127 | echo CRM_Utils_System::theme($content, $this->_print, TRUE); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner | |
132 | */ | |
133 | function runBegin() { | |
134 | $upgrade = new CRM_Upgrade_Form(); | |
135 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
136 | ||
137 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
138 | CRM_Core_Error::fatal($error); | |
139 | } | |
140 | ||
141 | $config = CRM_Core_Config::singleton(); | |
142 | // This could be removed in later rev | |
143 | if ($currentVer == '2.1.6') { | |
144 | // also cleanup the templates_c directory | |
145 | $config->cleanupCaches(); | |
146 | } | |
147 | // end of hack | |
148 | ||
bb216f68 | 149 | $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful! (... wasn\'t that easy!)') . '</span>'; |
6a488035 TO |
150 | |
151 | // lets drop all the triggers here | |
152 | CRM_Core_DAO::dropTriggers(); | |
153 | ||
c76e6d43 TO |
154 | $this->set('isUpgradePending', TRUE); |
155 | ||
6a488035 TO |
156 | // Persistent message storage across upgrade steps. TODO: Use structured message store |
157 | // Note: In clustered deployments, this file must be accessible by all web-workers. | |
158 | $this->set('postUpgradeMessageFile', CRM_Utils_File::tempnam('civicrm-post-upgrade')); | |
159 | file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage); | |
160 | ||
161 | $queueRunner = new CRM_Queue_Runner(array( | |
162 | 'title' => ts('CiviCRM Upgrade Tasks'), | |
163 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')), | |
164 | 'isMinimal' => TRUE, | |
165 | 'pathPrefix' => 'civicrm/upgrade/queue', | |
166 | 'onEndUrl' => CRM_Utils_System::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE ), | |
167 | 'buttons' => array('retry' => $config->debug, 'skip' => $config->debug), | |
168 | )); | |
169 | $queueRunner->runAllViaWeb(); | |
170 | CRM_Core_Error::fatal(ts('Upgrade failed to redirect')); | |
171 | } | |
172 | ||
173 | /** | |
174 | * Display any final messages, clear caches, etc | |
175 | */ | |
176 | function runFinish() { | |
177 | $upgrade = new CRM_Upgrade_Form(); | |
178 | $template = CRM_Core_Smarty::singleton(); | |
179 | ||
c76e6d43 TO |
180 | // If we're redirected from queue-runner, then isUpgradePending=true. |
181 | // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.) | |
182 | if ($this->get('isUpgradePending')) { | |
43992531 TO |
183 | // TODO: Use structured message store |
184 | $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile')); | |
6a488035 | 185 | |
43992531 TO |
186 | // This destroys $session, so do it after get('postUpgradeMessageFile') |
187 | CRM_Upgrade_Form::doFinish(); | |
188 | } else { | |
189 | $postUpgradeMessage = ''; // Session was destroyed! Can't recover messages. | |
190 | } | |
6a488035 TO |
191 | |
192 | // do a version check - after doFinish() sets the final version | |
193 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
194 | if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) { | |
195 | CRM_Core_Error::fatal($error); | |
196 | } | |
197 | ||
198 | $template->assign('message', $postUpgradeMessage); | |
199 | $template->assign('upgraded', TRUE); | |
200 | ||
201 | // Render page header | |
9dc21423 | 202 | if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) { |
6a488035 TO |
203 | CRM_Utils_System::addHTMLHead($region->render('')); |
204 | } | |
205 | ||
206 | $content = $template->fetch('CRM/common/success.tpl'); | |
207 | echo CRM_Utils_System::theme($content, $this->_print, TRUE); | |
208 | } | |
209 | } | |
210 |