3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Upgrade_Page_Upgrade
extends CRM_Core_Page
{
22 public function preProcess() {
31 public function run() {
34 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
36 $upgrade = new CRM_Upgrade_Form();
37 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
39 CRM_Utils_System
::setTitle(ts('Upgrade CiviCRM to Version %1',
43 $template = CRM_Core_Smarty
::singleton();
44 $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1',
47 $template->assign('cancelURL',
48 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
51 $action = CRM_Utils_Array
::value('action', $_REQUEST, 'intro');
66 throw new CRM_Core_Exception(ts('Unrecognized upgrade action'));
71 * Display an introductory screen with any pre-upgrade messages.
73 public function runIntro() {
74 $upgrade = new CRM_Upgrade_Form();
75 $template = CRM_Core_Smarty
::singleton();
76 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
77 CRM_Core_Smarty
::singleton()->assign('sid', CRM_Utils_System
::getSiteID());
78 // Show success msg if db already upgraded
79 if (version_compare($currentVer, $latestVer) == 0) {
80 $template->assign('upgraded', TRUE);
81 $template->assign('newVersion', $latestVer);
82 CRM_Utils_System
::setTitle(ts('Your database has already been upgraded to CiviCRM %1',
85 $template->assign('pageTitle', ts('Your database has already been upgraded to CiviCRM %1',
90 // Throw error if db in unexpected condition
91 elseif ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
92 throw new CRM_Core_Exception($error);
96 $config = CRM_Core_Config
::singleton();
98 // All cached content needs to be cleared because the civi codebase was just replaced
99 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
101 // cleanup only the templates_c directory
102 $config->cleanup(1, FALSE);
104 $preUpgradeMessage = NULL;
105 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
107 $template->assign('preUpgradeMessage', $preUpgradeMessage);
108 $template->assign('currentVersion', $currentVer);
109 $template->assign('newVersion', $latestVer);
110 $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2',
111 [1 => $currentVer, 2 => $latestVer]
113 $template->assign('upgraded', FALSE);
116 // Render page header
117 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
118 CRM_Utils_System
::addHTMLHead($region->render(''));
121 $content = $template->fetch('CRM/common/success.tpl');
122 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);
126 * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner
128 public function runBegin() {
129 $upgrade = new CRM_Upgrade_Form();
130 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
132 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
133 throw new CRM_Core_Exception($error);
136 $config = CRM_Core_Config
::singleton();
138 $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful!') . '</span>';
140 // lets drop all the triggers here
141 CRM_Core_DAO
::dropTriggers();
143 $this->set('isUpgradePending', TRUE);
145 // Persistent message storage across upgrade steps. TODO: Use structured message store
146 // Note: In clustered deployments, this file must be accessible by all web-workers.
147 $this->set('postUpgradeMessageFile', CRM_Utils_File
::tempnam('civicrm-post-upgrade'));
148 file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage);
150 $queueRunner = new CRM_Queue_Runner([
151 'title' => ts('CiviCRM Upgrade Tasks'),
152 'queue' => CRM_Upgrade_Form
::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')),
154 'pathPrefix' => 'civicrm/upgrade/queue',
155 'onEndUrl' => CRM_Utils_System
::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE),
156 'buttons' => ['retry' => $config->debug
, 'skip' => $config->debug
],
158 $queueRunner->runAllViaWeb();
159 throw new CRM_Core_Exception(ts('Upgrade failed to redirect'));
163 * Display any final messages, clear caches, etc
165 public function runFinish() {
166 $upgrade = new CRM_Upgrade_Form();
167 $template = CRM_Core_Smarty
::singleton();
169 // If we're redirected from queue-runner, then isUpgradePending=true.
170 // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.)
171 if ($this->get('isUpgradePending')) {
172 // TODO: Use structured message store
173 $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile'));
175 // This destroys $session, so do it after get('postUpgradeMessageFile')
176 CRM_Upgrade_Form
::doFinish();
179 // Session was destroyed! Can't recover messages.
180 $postUpgradeMessage = '';
183 // do a version check - after doFinish() sets the final version
184 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
185 if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) {
186 throw new CRM_Core_Exception($error);
189 $template->assign('message', $postUpgradeMessage);
190 $template->assign('upgraded', TRUE);
191 $template->assign('newVersion', $latestVer);
193 // Render page header
194 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
195 CRM_Utils_System
::addHTMLHead($region->render(''));
198 $content = $template->fetch('CRM/common/success.tpl');
199 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);