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 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
48 $upgrade = new CRM_Upgrade_Form();
49 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
51 CRM_Utils_System
::setTitle(ts('Upgrade CiviCRM to Version %1',
52 array(1 => $latestVer)
55 $template = CRM_Core_Smarty
::singleton();
56 $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1',
57 array(1 => $latestVer)
59 $template->assign('cancelURL',
60 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
63 $action = CRM_Utils_Array
::value('action', $_REQUEST, 'intro');
78 CRM_Core_Error
::fatal(ts('Unrecognized upgrade action'));
83 * Display an introductory screen with any pre-upgrade messages
85 public function runIntro() {
86 $upgrade = new CRM_Upgrade_Form();
87 $template = CRM_Core_Smarty
::singleton();
88 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
90 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
91 CRM_Core_Error
::fatal($error);
94 $config = CRM_Core_Config
::singleton();
96 // All cached content needs to be cleared because the civi codebase was just replaced
97 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
98 CRM_Core_Menu
::store();
100 // cleanup only the templates_c directory
101 $config->cleanup(1, FALSE);
103 $preUpgradeMessage = NULL;
104 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
106 $template->assign('currentVersion', $currentVer);
107 $template->assign('newVersion', $latestVer);
108 $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2',
109 array(1 => $currentVer, 2 => $latestVer)
111 $template->assign('upgraded', FALSE);
113 // Render page header
114 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
115 CRM_Utils_System
::addHTMLHead($region->render(''));
118 $template->assign('preUpgradeMessage', $preUpgradeMessage);
120 $content = $template->fetch('CRM/common/success.tpl');
121 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);
125 * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner
127 public function runBegin() {
128 $upgrade = new CRM_Upgrade_Form();
129 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
131 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
132 CRM_Core_Error
::fatal($error);
135 $config = CRM_Core_Config
::singleton();
137 $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful!') . '</span>';
139 // lets drop all the triggers here
140 CRM_Core_DAO
::dropTriggers();
142 $this->set('isUpgradePending', TRUE);
144 // Persistent message storage across upgrade steps. TODO: Use structured message store
145 // Note: In clustered deployments, this file must be accessible by all web-workers.
146 $this->set('postUpgradeMessageFile', CRM_Utils_File
::tempnam('civicrm-post-upgrade'));
147 file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage);
149 $queueRunner = new CRM_Queue_Runner(array(
150 'title' => ts('CiviCRM Upgrade Tasks'),
151 'queue' => CRM_Upgrade_Form
::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')),
153 'pathPrefix' => 'civicrm/upgrade/queue',
154 'onEndUrl' => CRM_Utils_System
::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE),
155 'buttons' => array('retry' => $config->debug
, 'skip' => $config->debug
),
157 $queueRunner->runAllViaWeb();
158 CRM_Core_Error
::fatal(ts('Upgrade failed to redirect'));
162 * Display any final messages, clear caches, etc
164 public function runFinish() {
165 $upgrade = new CRM_Upgrade_Form();
166 $template = CRM_Core_Smarty
::singleton();
168 // If we're redirected from queue-runner, then isUpgradePending=true.
169 // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.)
170 if ($this->get('isUpgradePending')) {
171 // TODO: Use structured message store
172 $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile'));
174 // This destroys $session, so do it after get('postUpgradeMessageFile')
175 CRM_Upgrade_Form
::doFinish();
178 $postUpgradeMessage = ''; // Session was destroyed! Can't recover messages.
181 // do a version check - after doFinish() sets the final version
182 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
183 if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) {
184 CRM_Core_Error
::fatal($error);
187 $template->assign('message', $postUpgradeMessage);
188 $template->assign('upgraded', TRUE);
189 $template->assign('sid', CRM_Utils_System
::getSiteID());
191 // Render page header
192 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
193 CRM_Utils_System
::addHTMLHead($region->render(''));
196 $content = $template->fetch('CRM/common/success.tpl');
197 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);