Fix visibility on legacy functions
[civicrm-core.git] / CRM / Upgrade / Form.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
32 * $Id$
33 *
34 */
35class CRM_Upgrade_Form extends CRM_Core_Form {
7da04cde 36 const QUEUE_NAME = 'CRM_Upgrade';
6a488035
TO
37
38 /**
39 * Minimum size of MySQL's thread_stack option
40 *
41 * @see install/index.php MINIMUM_THREAD_STACK
42 */
43 const MINIMUM_THREAD_STACK = 192;
44
304c1a5a
CW
45 /**
46 * Minimum previous CiviCRM version we can directly upgrade from
47 */
48 const MINIMUM_UPGRADABLE_VERSION = '4.0.8';
49
50 /**
51 * Minimum php version we support
52 */
678d6d82 53 const MINIMUM_PHP_VERSION = '5.3.4';
304c1a5a 54
6a488035
TO
55 protected $_config;
56
6a488035 57 /**
fe482240 58 * Upgrade for multilingual.
6a488035
TO
59 *
60 * @var boolean
6a488035
TO
61 */
62 public $multilingual = FALSE;
63
64 /**
fe482240 65 * Locales available for multilingual upgrade.
6a488035
TO
66 *
67 * @var array
6a488035
TO
68 */
69 public $locales;
70
71 /**
fe482240 72 * Number to string mapper.
6a488035
TO
73 *
74 * @var array
6a488035
TO
75 */
76 static $_numberMap = array(
77 0 => 'Zero',
78 1 => 'One',
79 2 => 'Two',
80 3 => 'Three',
81 4 => 'Four',
82 5 => 'Five',
79e3ddee 83 6 => 'Six',
6a488035
TO
84 7 => 'Seven',
85 8 => 'Eight',
86 9 => 'Nine',
87 );
88
624e56fa 89 /**
fe482240 90 * Constructor for the basic form page.
624e56fa
EM
91 *
92 * We should not use QuickForm directly. This class provides a lot
93 * of default convenient functions, rules and buttons
94 *
c68f8bfa
TO
95 * @param object $state
96 * State associated with this form.
e8e8f3ad 97 * @param const|\enum|int $action The mode the form is operating in (None/Create/View/Update/Delete)
c68f8bfa
TO
98 * @param string $method
99 * The type of http method used (GET/POST).
100 * @param string $name
101 * The name of the form if different from class name.
624e56fa 102 */
ae5ffbb7 103 public function __construct(
4e66d748 104 $state = NULL,
6a488035
TO
105 $action = CRM_Core_Action::NONE,
106 $method = 'post',
e418776c 107 $name = NULL
6a488035
TO
108 ) {
109 $this->_config = CRM_Core_Config::singleton();
110
6a488035
TO
111 $domain = new CRM_Core_DAO_Domain();
112 $domain->find(TRUE);
113
114 $this->multilingual = (bool) $domain->locales;
115 $this->locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
116
117 $smarty = CRM_Core_Smarty::singleton();
635f0b86 118 //$smarty->compile_dir = $this->_config->templateCompileDir;
6a488035
TO
119 $smarty->assign('multilingual', $this->multilingual);
120 $smarty->assign('locales', $this->locales);
121
122 // we didn't call CRM_Core_BAO_ConfigSetting::retrieve(), so we need to set $dbLocale by hand
123 if ($this->multilingual) {
124 global $dbLocale;
125 $dbLocale = "_{$this->_config->lcMessages}";
126 }
127
128 parent::__construct($state, $action, $method, $name);
129 }
130
624e56fa
EM
131 /**
132 * @param $version
133 *
134 * @return mixed
135 */
00be9182 136 public static function &incrementalPhpObject($version) {
6a488035
TO
137 static $incrementalPhpObject = array();
138
139 $versionParts = explode('.', $version);
140 $versionName = self::$_numberMap[$versionParts[0]] . self::$_numberMap[$versionParts[1]];
141
142 if (!array_key_exists($versionName, $incrementalPhpObject)) {
0e6e8724 143 $className = "CRM_Upgrade_Incremental_php_{$versionName}";
e8cb3963 144 $incrementalPhpObject[$versionName] = new $className();
6a488035
TO
145 }
146 return $incrementalPhpObject[$versionName];
147 }
148
624e56fa
EM
149 /**
150 * @param $version
151 * @param $release
152 *
153 * @return bool
154 */
00be9182 155 public function checkVersionRelease($version, $release) {
6a488035 156 $versionParts = explode('.', $version);
bf6a5362 157 return ($versionParts[2] == $release);
6a488035
TO
158 }
159
624e56fa
EM
160 /**
161 * @param $constraints
162 *
163 * @return array
164 */
00be9182 165 public function checkSQLConstraints(&$constraints) {
6a488035
TO
166 $pass = $fail = 0;
167 foreach ($constraints as $constraint) {
168 if ($this->checkSQLConstraint($constraint)) {
169 $pass++;
170 }
171 else {
172 $fail++;
173 }
174 return array($pass, $fail);
175 }
176 }
177
624e56fa
EM
178 /**
179 * @param $constraint
180 *
181 * @return bool
182 */
00be9182 183 public function checkSQLConstraint($constraint) {
6a488035
TO
184 // check constraint here
185 return TRUE;
186 }
187
624e56fa 188 /**
100fef9d 189 * @param string $fileName
624e56fa
EM
190 * @param bool $isQueryString
191 */
00be9182 192 public function source($fileName, $isQueryString = FALSE) {
6a488035
TO
193
194 CRM_Utils_File::sourceSQLFile($this->_config->dsn,
195 $fileName, NULL, $isQueryString
196 );
197 }
198
00be9182 199 public function preProcess() {
6a488035
TO
200 CRM_Utils_System::setTitle($this->getTitle());
201 if (!$this->verifyPreDBState($errorMessage)) {
202 if (!isset($errorMessage)) {
203 $errorMessage = 'pre-condition failed for current upgrade step';
204 }
205 CRM_Core_Error::fatal($errorMessage);
206 }
207 $this->assign('recentlyViewed', FALSE);
208 }
209
00be9182 210 public function buildQuickForm() {
6a488035
TO
211 $this->addDefaultButtons($this->getButtonTitle(),
212 'next',
213 NULL,
214 TRUE
215 );
216 }
217
624e56fa 218 /**
100fef9d 219 * Getter function for title. Should be over-ridden by derived class
624e56fa
EM
220 *
221 * @return string
624e56fa
EM
222 */
223 /**
224 * @return string
225 */
00be9182 226 public function getTitle() {
6a488035
TO
227 return ts('Title not Set');
228 }
229
624e56fa
EM
230 /**
231 * @return string
232 */
00be9182 233 public function getFieldsetTitle() {
ba8f6a69 234 return '';
6a488035
TO
235 }
236
624e56fa
EM
237 /**
238 * @return string
239 */
00be9182 240 public function getButtonTitle() {
6a488035
TO
241 return ts('Continue');
242 }
243
624e56fa 244 /**
fe482240 245 * Use the form name to create the tpl file name.
624e56fa
EM
246 *
247 * @return string
624e56fa
EM
248 */
249 /**
250 * @return string
251 */
00be9182 252 public function getTemplateFileName() {
6a488035
TO
253 $this->assign('title',
254 $this->getFieldsetTitle()
255 );
256 $this->assign('message',
257 $this->getTemplateMessage()
258 );
259 return 'CRM/Upgrade/Base.tpl';
260 }
261
00be9182 262 public function postProcess() {
6a488035
TO
263 $this->upgrade();
264
265 if (!$this->verifyPostDBState($errorMessage)) {
266 if (!isset($errorMessage)) {
267 $errorMessage = 'post-condition failed for current upgrade step';
268 }
269 CRM_Core_Error::fatal($errorMessage);
270 }
271 }
272
624e56fa
EM
273 /**
274 * @param $query
275 *
276 * @return Object
277 */
00be9182 278 public function runQuery($query) {
6a488035
TO
279 return CRM_Core_DAO::executeQuery($query,
280 CRM_Core_DAO::$_nullArray
281 );
282 }
283
624e56fa
EM
284 /**
285 * @param $version
286 *
287 * @return Object
288 */
00be9182 289 public function setVersion($version) {
6a488035
TO
290 $this->logVersion($version);
291
292 $query = "
293UPDATE civicrm_domain
294SET version = '$version'
295";
296 return $this->runQuery($query);
297 }
298
624e56fa
EM
299 /**
300 * @param $newVersion
301 *
302 * @return bool
303 */
00be9182 304 public function logVersion($newVersion) {
6a488035
TO
305 if ($newVersion) {
306 $oldVersion = CRM_Core_BAO_Domain::version();
307
308 $session = CRM_Core_Session::singleton();
309 $logParams = array(
310 'entity_table' => 'civicrm_domain',
311 'entity_id' => 1,
312 'data' => "upgrade:{$oldVersion}->{$newVersion}",
313 // lets skip 'modified_id' for now, as it causes FK issues And
314 // is not very important for now.
315 'modified_date' => date('YmdHis'),
316 );
317 CRM_Core_BAO_Log::add($logParams);
318 return TRUE;
319 }
320
321 return FALSE;
322 }
323
624e56fa
EM
324 /**
325 * @param $version
326 *
327 * @return bool
328 */
00be9182 329 public function checkVersion($version) {
6a488035
TO
330 $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain',
331 $version, 'id',
332 'version'
333 );
334 return $domainID ? TRUE : FALSE;
335 }
336
624e56fa
EM
337 /**
338 * @return array
339 * @throws Exception
340 */
00be9182 341 public function getRevisionSequence() {
6a488035
TO
342 $revList = array();
343 $sqlDir = implode(DIRECTORY_SEPARATOR,
344 array(dirname(__FILE__), 'Incremental', 'sql')
345 );
346 $sqlFiles = scandir($sqlDir);
347
348 $sqlFilePattern = '/^((\d{1,2}\.\d{1,2})\.(\d{1,2}\.)?(\d{1,2}|\w{4,7}))\.(my)?sql(\.tpl)?$/i';
349 foreach ($sqlFiles as $file) {
350 if (preg_match($sqlFilePattern, $file, $matches)) {
351 if ($matches[2] == '4.0') {
b604d7ec 352 CRM_Core_Error::fatal("4.0.x upgrade files shouldn't exist. Contact Lobo to discuss this. This is related to the issue CRM-7731.");
6a488035
TO
353 }
354 if (!in_array($matches[1], $revList)) {
355 $revList[] = $matches[1];
356 }
357 }
358 }
359
6a488035
TO
360 usort($revList, 'version_compare');
361 return $revList;
362 }
363
624e56fa
EM
364 /**
365 * @param $rev
366 * @param int $index
367 *
368 * @return null
369 */
00be9182 370 public static function getRevisionPart($rev, $index = 1) {
6a488035
TO
371 $revPattern = '/^((\d{1,2})\.\d{1,2})\.(\d{1,2}|\w{4,7})?$/i';
372 preg_match($revPattern, $rev, $matches);
373
374 return array_key_exists($index, $matches) ? $matches[$index] : NULL;
375 }
376
624e56fa
EM
377 /**
378 * @param $tplFile
379 * @param $rev
380 *
381 * @return bool
382 */
00be9182 383 public function processLocales($tplFile, $rev) {
6a488035
TO
384 $smarty = CRM_Core_Smarty::singleton();
385 $smarty->assign('domainID', CRM_Core_Config::domainID());
386
387 $this->source($smarty->fetch($tplFile), TRUE);
388
389 if ($this->multilingual) {
390 CRM_Core_I18n_Schema::rebuildMultilingualSchema($this->locales, $rev);
391 }
392 return $this->multilingual;
393 }
394
624e56fa
EM
395 /**
396 * @param $rev
397 */
00be9182 398 public function setSchemaStructureTables($rev) {
6a488035
TO
399 if ($this->multilingual) {
400 CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE);
401 }
402 }
403
624e56fa
EM
404 /**
405 * @param $rev
406 *
407 * @throws Exception
408 */
00be9182 409 public function processSQL($rev) {
6a488035
TO
410 $sqlFile = implode(DIRECTORY_SEPARATOR,
411 array(
353ffa53
TO
412 dirname(__FILE__),
413 'Incremental',
414 'sql',
415 $rev . '.mysql',
6a488035
TO
416 )
417 );
418 $tplFile = "$sqlFile.tpl";
419
420 if (file_exists($tplFile)) {
421 $this->processLocales($tplFile, $rev);
422 }
423 else {
424 if (!file_exists($sqlFile)) {
425 CRM_Core_Error::fatal("sqlfile - $rev.mysql not found.");
426 }
427 $this->source($sqlFile);
428 }
429 }
430
431 /**
fe482240 432 * Determine the start and end version of the upgrade process.
6a488035
TO
433 *
434 * @return array(0=>$currentVer, 1=>$latestVer)
435 */
00be9182 436 public function getUpgradeVersions() {
6a488035 437 $latestVer = CRM_Utils_System::version();
e418776c 438 $currentVer = CRM_Core_BAO_Domain::version(TRUE);
6a488035
TO
439 if (!$currentVer) {
440 CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
441 }
442 elseif (stripos($currentVer, 'upgrade')) {
443 CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
444 }
445 if (!$latestVer) {
446 CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.'));
447 }
448
6a488035
TO
449 return array($currentVer, $latestVer);
450 }
451
452 /**
453 * Determine if $currentVer can be upgraded to $latestVer
454 *
77b97be7
EM
455 * @param $currentVer
456 * @param $latestVer
457 *
6a488035
TO
458 * @return mixed, a string error message or boolean 'false' if OK
459 */
00be9182 460 public function checkUpgradeableVersion($currentVer, $latestVer) {
6a488035
TO
461 $error = FALSE;
462 // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
463 // lets do a pattern check -
464 if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
465 $error = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
466 }
467 elseif (version_compare($currentVer, $latestVer) > 0) {
468 // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
469 $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.',
304c1a5a 470 array(1 => $currentVer, 2 => $latestVer)
6a488035
TO
471 );
472 }
473 elseif (version_compare($currentVer, $latestVer) == 0) {
474 $error = ts('Your database has already been upgraded to CiviCRM %1',
475 array(1 => $latestVer)
476 );
477 }
304c1a5a
CW
478 elseif (version_compare($currentVer, self::MINIMUM_UPGRADABLE_VERSION) < 0) {
479 $error = ts('CiviCRM versions prior to %1 cannot be upgraded directly to %2. This upgrade will need to be done in stages. First download an intermediate version (the LTS may be a good choice) and upgrade to that before proceeding to this version.',
480 array(1 => self::MINIMUM_UPGRADABLE_VERSION, 2 => $latestVer)
481 );
482 }
6a488035 483
304c1a5a 484 if (version_compare(phpversion(), self::MINIMUM_PHP_VERSION) < 0) {
6a488035 485 $error = ts('CiviCRM %3 requires PHP version %1 (or newer), but the current system uses %2 ',
353ffa53 486 array(
304c1a5a
CW
487 1 => self::MINIMUM_PHP_VERSION,
488 2 => phpversion(),
353ffa53
TO
489 3 => $latestVer,
490 ));
6a488035
TO
491 }
492
493 // check for mysql trigger privileges
509e50b7 494 if (!\Civi::settings()->get('logging_no_trigger_permission') && !CRM_Core_DAO::checkTriggerViewPermission(FALSE, TRUE)) {
6a488035 495 $error = ts('CiviCRM %1 requires MySQL trigger privileges.',
353ffa53 496 array(1 => $latestVer));
6a488035 497 }
032c9d10 498
e418776c 499 if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024 * self::MINIMUM_THREAD_STACK)) {
6a488035
TO
500 $error = ts('CiviCRM %1 requires MySQL thread stack >= %2k', array(
501 1 => $latestVer,
21dfd5f5 502 2 => self::MINIMUM_THREAD_STACK,
6a488035
TO
503 ));
504 }
505
506 return $error;
507 }
508
509 /**
510 * Determine if $currentver already matches $latestVer
511 *
77b97be7
EM
512 * @param $currentVer
513 * @param $latestVer
514 *
6a488035
TO
515 * @return mixed, a string error message or boolean 'false' if OK
516 */
00be9182 517 public function checkCurrentVersion($currentVer, $latestVer) {
6a488035
TO
518 $error = FALSE;
519
520 // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
521 // lets do a pattern check -
522 if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
523 $error = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
524 }
525 elseif (version_compare($currentVer, $latestVer) != 0) {
526 $error = ts('Your database is not configured for version %1',
527 array(1 => $latestVer)
528 );
529 }
530 return $error;
531 }
532
533 /**
fe482240 534 * Fill the queue with upgrade tasks.
6a488035 535 *
5a4f6742
CW
536 * @param string $currentVer
537 * the original revision.
538 * @param string $latestVer
539 * the target (final) revision.
540 * @param string $postUpgradeMessageFile
541 * path of a modifiable file which lists the post-upgrade messages.
6a488035 542 *
bf6a5362 543 * @return CRM_Queue_Service
6a488035 544 */
00be9182 545 public static function buildQueue($currentVer, $latestVer, $postUpgradeMessageFile) {
6a488035
TO
546 $upgrade = new CRM_Upgrade_Form();
547
548 // hack to make 4.0.x (D7,J1.6) codebase go through 3.4.x (d6, J1.5) upgrade files,
549 // since schema wise they are same
550 if (CRM_Upgrade_Form::getRevisionPart($currentVer) == '4.0') {
551 $currentVer = str_replace('4.0.', '3.4.', $currentVer);
552 }
553
554 // Ensure that queue can be created
555 if (!CRM_Queue_BAO_QueueItem::findCreateTable()) {
556 CRM_Core_Error::fatal(ts('Failed to find or create queueing table'));
557 }
558 $queue = CRM_Queue_Service::singleton()->create(array(
353ffa53
TO
559 'name' => self::QUEUE_NAME,
560 'type' => 'Sql',
561 'reset' => TRUE,
562 ));
6a488035
TO
563
564 $revisions = $upgrade->getRevisionSequence();
565 foreach ($revisions as $rev) {
566 // proceed only if $currentVer < $rev
567 if (version_compare($currentVer, $rev) < 0) {
568 $beginTask = new CRM_Queue_Task(
353ffa53 569 // callback
6a488035
TO
570 array('CRM_Upgrade_Form', 'doIncrementalUpgradeStart'),
571 // arguments
572 array($rev),
573 "Begin Upgrade to $rev"
574 );
575 $queue->createItem($beginTask);
576
577 $task = new CRM_Queue_Task(
353ffa53 578 // callback
6a488035
TO
579 array('CRM_Upgrade_Form', 'doIncrementalUpgradeStep'),
580 // arguments
581 array($rev, $currentVer, $latestVer, $postUpgradeMessageFile),
582 "Upgrade DB to $rev"
583 );
584 $queue->createItem($task);
585
586 $task = new CRM_Queue_Task(
353ffa53 587 // callback
6a488035
TO
588 array('CRM_Upgrade_Form', 'doIncrementalUpgradeFinish'),
589 // arguments
3373fe5e 590 array($rev, $currentVer, $latestVer, $postUpgradeMessageFile),
6a488035
TO
591 "Finish Upgrade DB to $rev"
592 );
593 $queue->createItem($task);
594 }
595 }
596
597 return $queue;
598 }
599
600 /**
fe482240 601 * Perform an incremental version update.
6a488035 602 *
77b97be7 603 * @param CRM_Queue_TaskContext $ctx
5a4f6742
CW
604 * @param string $rev
605 * the target (intermediate) revision e.g '3.2.alpha1'.
77b97be7
EM
606 *
607 * @return bool
6a488035 608 */
00be9182 609 public static function doIncrementalUpgradeStart(CRM_Queue_TaskContext $ctx, $rev) {
6a488035
TO
610 $upgrade = new CRM_Upgrade_Form();
611
612 // as soon as we start doing anything we append ".upgrade" to version.
613 // this also helps detect any partial upgrade issues
614 $upgrade->setVersion($rev . '.upgrade');
615
616 return TRUE;
617 }
618
619 /**
fe482240 620 * Perform an incremental version update.
6a488035 621 *
77b97be7 622 * @param CRM_Queue_TaskContext $ctx
5a4f6742
CW
623 * @param string $rev
624 * the target (intermediate) revision e.g '3.2.alpha1'.
625 * @param string $originalVer
626 * the original revision.
627 * @param string $latestVer
628 * the target (final) revision.
629 * @param string $postUpgradeMessageFile
630 * path of a modifiable file which lists the post-upgrade messages.
77b97be7
EM
631 *
632 * @return bool
6a488035 633 */
e418776c 634 public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext $ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) {
6a488035
TO
635 $upgrade = new CRM_Upgrade_Form();
636
637 $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
638
bd00780f
CW
639 $versionObject = $upgrade->incrementalPhpObject($rev);
640
641 // pre-db check for major release.
642 if ($upgrade->checkVersionRelease($rev, 'alpha1')) {
d9c7af19 643 if (!(is_callable(array($versionObject, 'verifyPreDBstate')))) {
bd00780f 644 CRM_Core_Error::fatal("verifyPreDBstate method was not found for $rev");
6a488035 645 }
6a488035 646
bd00780f
CW
647 $error = NULL;
648 if (!($versionObject->verifyPreDBstate($error))) {
649 if (!isset($error)) {
650 $error = "post-condition failed for current upgrade for $rev";
6a488035 651 }
bd00780f 652 CRM_Core_Error::fatal($error);
6a488035
TO
653 }
654
bd00780f 655 }
6a488035 656
bd00780f 657 $upgrade->setSchemaStructureTables($rev);
6a488035 658
d9c7af19 659 if (is_callable(array($versionObject, $phpFunctionName))) {
bd00780f
CW
660 $versionObject->$phpFunctionName($rev, $originalVer, $latestVer);
661 }
662 else {
663 $upgrade->processSQL($rev);
664 }
665
666 // set post-upgrade-message if any
d9c7af19 667 if (is_callable(array($versionObject, 'setPostUpgradeMessage'))) {
bd00780f
CW
668 $postUpgradeMessage = file_get_contents($postUpgradeMessageFile);
669 $versionObject->setPostUpgradeMessage($postUpgradeMessage, $rev);
bd00780f 670 file_put_contents($postUpgradeMessageFile, $postUpgradeMessage);
6a488035
TO
671 }
672
673 return TRUE;
674 }
675
676 /**
fe482240 677 * Perform an incremental version update.
6a488035 678 *
77b97be7 679 * @param CRM_Queue_TaskContext $ctx
5a4f6742
CW
680 * @param string $rev
681 * the target (intermediate) revision e.g '3.2.alpha1'.
682 * @param string $currentVer
683 * the original revision.
684 * @param string $latestVer
685 * the target (final) revision.
686 * @param string $postUpgradeMessageFile
687 * path of a modifiable file which lists the post-upgrade messages.
77b97be7
EM
688 *
689 * @return bool
6a488035 690 */
00be9182 691 public static function doIncrementalUpgradeFinish(CRM_Queue_TaskContext $ctx, $rev, $currentVer, $latestVer, $postUpgradeMessageFile) {
6a488035
TO
692 $upgrade = new CRM_Upgrade_Form();
693 $upgrade->setVersion($rev);
694 CRM_Utils_System::flushCache();
ac05cde3 695
d8a4acc0
C
696 $config = CRM_Core_Config::singleton();
697 $config->userSystem->flush();
6a488035
TO
698 return TRUE;
699 }
700
00be9182 701 public static function doFinish() {
6a488035
TO
702 $upgrade = new CRM_Upgrade_Form();
703 list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
704 // Seems extraneous in context, but we'll preserve old behavior
705 $upgrade->setVersion($latestVer);
706
f806379b
TO
707 // Clear cached metadata.
708 Civi::service('settings_manager')->flush();
b6386d8c 709
6a488035
TO
710 // cleanup caches CRM-8739
711 $config = CRM_Core_Config::singleton();
1fcf16cc 712 $config->cleanupCaches(1);
6a488035
TO
713
714 // Rebuild all triggers and re-enable logging if needed
715 $logging = new CRM_Logging_Schema();
716 $logging->fixSchemaDifferences();
70b85f7c 717
718 //CRM-16257 update Config.IDS.ini might be an old copy
719 CRM_Core_IDS::createConfigFile(TRUE);
6a488035
TO
720 }
721
722 /**
723 * Compute any messages which should be displayed before upgrade
724 * by calling the 'setPreUpgradeMessage' on each incremental upgrade
725 * object.
726 *
5a4f6742
CW
727 * @param string $preUpgradeMessage
728 * alterable.
77b97be7
EM
729 * @param $currentVer
730 * @param $latestVer
6a488035 731 */
00be9182 732 public function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
49368097
CW
733 // check for changed message templates
734 CRM_Upgrade_Incremental_General::checkMessageTemplate($preUpgradeMessage, $latestVer, $currentVer);
735 // set global messages
736 CRM_Upgrade_Incremental_General::setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
6a488035
TO
737
738 // Scan through all php files and see if any file is interested in setting pre-upgrade-message
739 // based on $currentVer, $latestVer.
740 // Please note, at this point upgrade hasn't started executing queries.
741 $revisions = $this->getRevisionSequence();
742 foreach ($revisions as $rev) {
49368097 743 if (version_compare($currentVer, $rev) < 0) {
6a488035 744 $versionObject = $this->incrementalPhpObject($rev);
49368097 745 if (is_callable(array($versionObject, 'setPreUpgradeMessage'))) {
e418776c
TO
746 $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer);
747 }
6a488035
TO
748 }
749 }
750 }
96025800 751
6a488035 752}