Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | )); | |
57 | $template->assign('menuRebuildURL', | |
58 | CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1') | |
59 | ); | |
60 | $template->assign('cancelURL', | |
61 | CRM_Utils_System::url('civicrm/dashboard', 'reset=1') | |
62 | ); | |
63 | ||
64 | $action = CRM_Utils_Array::value('action', $_REQUEST, 'intro'); | |
65 | switch ($action) { | |
66 | case 'intro': | |
67 | $this->runIntro(); | |
68 | break; | |
69 | ||
70 | case 'begin': | |
71 | $this->runBegin(); | |
72 | break; | |
73 | ||
74 | case 'finish': | |
75 | $this->runFinish(); | |
76 | break; | |
77 | ||
78 | default: | |
79 | CRM_Core_Error::fatal(ts('Unrecognized upgrade action')); | |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
84 | * Display an introductory screen with any pre-upgrade messages | |
85 | */ | |
86 | function runIntro() { | |
87 | $upgrade = new CRM_Upgrade_Form(); | |
88 | $template = CRM_Core_Smarty::singleton(); | |
89 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
90 | ||
91 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
92 | CRM_Core_Error::fatal($error); | |
93 | } | |
94 | ||
95 | // This could be removed in later rev | |
96 | if ($currentVer == '2.1.6') { | |
97 | $config = CRM_Core_Config::singleton(); | |
98 | // also cleanup the templates_c directory | |
99 | $config->cleanupCaches(); | |
100 | } else { | |
101 | $config = CRM_Core_Config::singleton(); | |
102 | // cleanup only the templates_c directory | |
103 | $config->cleanup(1, FALSE); | |
104 | } | |
105 | // end of hack | |
106 | ||
107 | $preUpgradeMessage = NULL; | |
108 | $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); | |
109 | ||
110 | $template->assign('currentVersion', $currentVer); | |
111 | $template->assign('newVersion', $latestVer); | |
112 | $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', | |
113 | array(1 => $currentVer, 2 => $latestVer) | |
114 | )); | |
115 | $template->assign('upgraded', FALSE); | |
116 | ||
117 | // Render page header | |
9dc21423 | 118 | if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) { |
6a488035 TO |
119 | CRM_Utils_System::addHTMLHead($region->render('')); |
120 | } | |
121 | ||
122 | $template->assign('preUpgradeMessage', $preUpgradeMessage); | |
123 | // $template->assign( 'message', $postUpgradeMessage ); | |
124 | ||
125 | $content = $template->fetch('CRM/common/success.tpl'); | |
126 | echo CRM_Utils_System::theme($content, $this->_print, TRUE); | |
127 | } | |
128 | ||
129 | /** | |
130 | * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner | |
131 | */ | |
132 | function runBegin() { | |
133 | $upgrade = new CRM_Upgrade_Form(); | |
134 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); | |
135 | ||
136 | if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { | |
137 | CRM_Core_Error::fatal($error); | |
138 | } | |
139 | ||
140 | $config = CRM_Core_Config::singleton(); | |
141 | // This could be removed in later rev | |
142 | if ($currentVer == '2.1.6') { | |
143 | // also cleanup the templates_c directory | |
144 | $config->cleanupCaches(); | |
145 | } | |
146 | // end of hack | |
147 | ||
148 | $postUpgradeMessage = ts('CiviCRM upgrade was successful.'); | |
149 | ||
150 | // lets drop all the triggers here | |
151 | CRM_Core_DAO::dropTriggers(); | |
152 | ||
153 | // Persistent message storage across upgrade steps. TODO: Use structured message store | |
154 | // Note: In clustered deployments, this file must be accessible by all web-workers. | |
155 | $this->set('postUpgradeMessageFile', CRM_Utils_File::tempnam('civicrm-post-upgrade')); | |
156 | file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage); | |
157 | ||
158 | $queueRunner = new CRM_Queue_Runner(array( | |
159 | 'title' => ts('CiviCRM Upgrade Tasks'), | |
160 | 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')), | |
161 | 'isMinimal' => TRUE, | |
162 | 'pathPrefix' => 'civicrm/upgrade/queue', | |
163 | 'onEndUrl' => CRM_Utils_System::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE ), | |
164 | 'buttons' => array('retry' => $config->debug, 'skip' => $config->debug), | |
165 | )); | |
166 | $queueRunner->runAllViaWeb(); | |
167 | CRM_Core_Error::fatal(ts('Upgrade failed to redirect')); | |
168 | } | |
169 | ||
170 | /** | |
171 | * Display any final messages, clear caches, etc | |
172 | */ | |
173 | function runFinish() { | |
174 | $upgrade = new CRM_Upgrade_Form(); | |
175 | $template = CRM_Core_Smarty::singleton(); | |
176 | ||
43992531 TO |
177 | list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); |
178 | if ($currentVer != $latestVer) { | |
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(); | |
184 | } else { | |
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); | |
196 | ||
197 | // Render page header | |
9dc21423 | 198 | if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region::instance('html-header', FALSE)) { |
6a488035 TO |
199 | CRM_Utils_System::addHTMLHead($region->render('')); |
200 | } | |
201 | ||
202 | $content = $template->fetch('CRM/common/success.tpl'); | |
203 | echo CRM_Utils_System::theme($content, $this->_print, TRUE); | |
204 | } | |
205 | } | |
206 |