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() {
32 // lets get around the time limit issue if possible for upgrades
33 if (!ini_get('safe_mode')) {
37 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
39 $upgrade = new CRM_Upgrade_Form();
40 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
42 CRM_Utils_System
::setTitle(ts('Upgrade CiviCRM to Version %1',
46 $template = CRM_Core_Smarty
::singleton();
47 $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1',
50 $template->assign('cancelURL',
51 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
54 $action = CRM_Utils_Array
::value('action', $_REQUEST, 'intro');
69 CRM_Core_Error
::fatal(ts('Unrecognized upgrade action'));
74 * Display an introductory screen with any pre-upgrade messages.
76 public function runIntro() {
77 $upgrade = new CRM_Upgrade_Form();
78 $template = CRM_Core_Smarty
::singleton();
79 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
81 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
82 CRM_Core_Error
::fatal($error);
85 $config = CRM_Core_Config
::singleton();
87 // All cached content needs to be cleared because the civi codebase was just replaced
88 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
89 CRM_Core_Menu
::store();
91 // cleanup only the templates_c directory
92 $config->cleanup(1, FALSE);
94 $preUpgradeMessage = NULL;
95 $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
97 $template->assign('currentVersion', $currentVer);
98 $template->assign('newVersion', $latestVer);
99 $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2',
100 [1 => $currentVer, 2 => $latestVer]
102 $template->assign('upgraded', FALSE);
104 // Render page header
105 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
106 CRM_Utils_System
::addHTMLHead($region->render(''));
109 $template->assign('preUpgradeMessage', $preUpgradeMessage);
111 $content = $template->fetch('CRM/common/success.tpl');
112 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);
116 * Begin the upgrade by building a queue of tasks and redirecting to the queue-runner
118 public function runBegin() {
119 $upgrade = new CRM_Upgrade_Form();
120 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
122 if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
123 CRM_Core_Error
::fatal($error);
126 $config = CRM_Core_Config
::singleton();
128 $postUpgradeMessage = '<span class="bold">' . ts('Congratulations! Your upgrade was successful!') . '</span>';
130 // lets drop all the triggers here
131 CRM_Core_DAO
::dropTriggers();
133 $this->set('isUpgradePending', TRUE);
135 // Persistent message storage across upgrade steps. TODO: Use structured message store
136 // Note: In clustered deployments, this file must be accessible by all web-workers.
137 $this->set('postUpgradeMessageFile', CRM_Utils_File
::tempnam('civicrm-post-upgrade'));
138 file_put_contents($this->get('postUpgradeMessageFile'), $postUpgradeMessage);
140 $queueRunner = new CRM_Queue_Runner([
141 'title' => ts('CiviCRM Upgrade Tasks'),
142 'queue' => CRM_Upgrade_Form
::buildQueue($currentVer, $latestVer, $this->get('postUpgradeMessageFile')),
144 'pathPrefix' => 'civicrm/upgrade/queue',
145 'onEndUrl' => CRM_Utils_System
::url('civicrm/upgrade', 'action=finish', FALSE, NULL, FALSE),
146 'buttons' => ['retry' => $config->debug
, 'skip' => $config->debug
],
148 $queueRunner->runAllViaWeb();
149 CRM_Core_Error
::fatal(ts('Upgrade failed to redirect'));
153 * Display any final messages, clear caches, etc
155 public function runFinish() {
156 $upgrade = new CRM_Upgrade_Form();
157 $template = CRM_Core_Smarty
::singleton();
159 // If we're redirected from queue-runner, then isUpgradePending=true.
160 // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.)
161 if ($this->get('isUpgradePending')) {
162 // TODO: Use structured message store
163 $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile'));
165 // This destroys $session, so do it after get('postUpgradeMessageFile')
166 CRM_Upgrade_Form
::doFinish();
169 // Session was destroyed! Can't recover messages.
170 $postUpgradeMessage = '';
173 // do a version check - after doFinish() sets the final version
174 list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
175 if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) {
176 CRM_Core_Error
::fatal($error);
179 $template->assign('message', $postUpgradeMessage);
180 $template->assign('upgraded', TRUE);
181 $template->assign('sid', CRM_Utils_System
::getSiteID());
182 $template->assign('newVersion', $latestVer);
184 // Render page header
185 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
186 CRM_Utils_System
::addHTMLHead($region->render(''));
189 $content = $template->fetch('CRM/common/success.tpl');
190 echo CRM_Utils_System
::theme($content, $this->_print
, TRUE);