23bb11c18a358abf678391a9f8de226dbb026e5f
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_Upgrade_Page_Upgrade
extends CRM_Core_Page
{
36 public function preProcess() {
40 public function run() {
41 // lets get around the time limit issue if possible for upgrades
42 if (!ini_get('safe_mode')) {
46 $upgrade = new CRM_Upgrade_Form();
47 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
49 CRM_Utils_System
::setTitle(ts('Upgrade CiviCRM to Version %1',
50 array(1 => $latestVer)
53 $template = CRM_Core_Smarty
::singleton();
54 $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1',
55 array(1 => $latestVer)
57 $template->assign('cancelURL',
58 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
61 $action = CRM_Utils_Array
::value('action', $_REQUEST, 'intro');
76 CRM_Core_Error
::fatal(ts('Unrecognized upgrade action'));
81 * Display an introductory screen with any pre-upgrade messages
83 public function runIntro() {
84 $upgrade = new CRM_Upgrade_Form();
85 $template = CRM_Core_Smarty
::singleton();
86 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
88 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
89 CRM_Core_Error
::fatal($error);
92 $config = CRM_Core_Config
::singleton();
94 // All cached content needs to be cleared because the civi codebase was just replaced
95 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
96 CRM_Core_Menu
::store();
98 // cleanup only the templates_c directory
99 $config->cleanup(1, FALSE);
101 $preUpgradeMessage = NULL;
102 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
104 $template->assign('currentVersion', $currentVer);
105 $template->assign('newVersion', $latestVer);
106 $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2',
107 array(1 => $currentVer, 2 => $latestVer)
109 $template->assign('upgraded', FALSE);
111 // Render page header
112 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
113 CRM_Utils_System
::addHTMLHead($region->render(''));
116 $template->assign('preUpgradeMessage', $preUpgradeMessage);
118 $content = $template->fetch('CRM/common/success.tpl');
119 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);
123 * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner
125 public function runBegin() {
126 $upgrade = new CRM_Upgrade_Form();
127 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
129 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
130 CRM_Core_Error
::fatal($error);
133 $config = CRM_Core_Config
::singleton();
135 $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful!') . '</span>';
137 // lets drop all the triggers here
138 CRM_Core_DAO
::dropTriggers();
140 $this->set('isUpgradePending', TRUE);
142 // Persistent message storage across upgrade steps. TODO: Use structured message store
143 // Note: In clustered deployments, this file must be accessible by all web-workers.
144 $this->set('postUpgradeMessageFile', CRM_Utils_File
::tempnam('civicrm-post-upgrade'));
145 file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage);
147 $queueRunner = new CRM_Queue_Runner(array(
148 'title' => ts('CiviCRM Upgrade Tasks'),
149 'queue' => CRM_Upgrade_Form
::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')),
151 'pathPrefix' => 'civicrm/upgrade/queue',
152 'onEndUrl' => CRM_Utils_System
::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE),
153 'buttons' => array('retry' => $config->debug
, 'skip' => $config->debug
),
155 $queueRunner->runAllViaWeb();
156 CRM_Core_Error
::fatal(ts('Upgrade failed to redirect'));
160 * Display any final messages, clear caches, etc
162 public function runFinish() {
163 $upgrade = new CRM_Upgrade_Form();
164 $template = CRM_Core_Smarty
::singleton();
166 // If we're redirected from queue-runner, then isUpgradePending=true.
167 // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.)
168 if ($this->get('isUpgradePending')) {
169 // TODO: Use structured message store
170 $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile'));
172 // This destroys $session, so do it after get('postUpgradeMessageFile')
173 CRM_Upgrade_Form
::doFinish();
176 $postUpgradeMessage = ''; // Session was destroyed! Can't recover messages.
179 // do a version check - after doFinish() sets the final version
180 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
181 if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) {
182 CRM_Core_Error
::fatal($error);
185 $template->assign('message', $postUpgradeMessage);
186 $template->assign('upgraded', TRUE);
188 // Render page header
189 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
190 CRM_Utils_System
::addHTMLHead($region->render(''));
193 $content = $template->fetch('CRM/common/success.tpl');
194 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);