Merge pull request #19827 from civicrm/5.36
[civicrm-core.git] / CRM / Upgrade / Form.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Upgrade_Form
14 */
15 class CRM_Upgrade_Form extends CRM_Core_Form {
16 const QUEUE_NAME = 'CRM_Upgrade';
17
18 /**
19 * Minimum size of MySQL's thread_stack option
20 *
21 * @see install/index.php MINIMUM_THREAD_STACK
22 */
23 const MINIMUM_THREAD_STACK = 192;
24
25 /**
26 * Minimum previous CiviCRM version we can directly upgrade from
27 */
28 const MINIMUM_UPGRADABLE_VERSION = '4.4.7';
29
30 /**
31 * @var \CRM_Core_Config
32 */
33 protected $_config;
34
35 /**
36 * Upgrade for multilingual.
37 *
38 * @var bool
39 */
40 public $multilingual = FALSE;
41
42 /**
43 * Locales available for multilingual upgrade.
44 *
45 * @var array
46 */
47 public $locales;
48
49 /**
50 * Constructor for the basic form page.
51 *
52 * We should not use QuickForm directly. This class provides a lot
53 * of default convenient functions, rules and buttons
54 *
55 * @param object $state
56 * State associated with this form.
57 * @param const|\enum|int $action The mode the form is operating in (None/Create/View/Update/Delete)
58 * @param string $method
59 * The type of http method used (GET/POST).
60 * @param string $name
61 * The name of the form if different from class name.
62 */
63 public function __construct(
64 $state = NULL,
65 $action = CRM_Core_Action::NONE,
66 $method = 'post',
67 $name = NULL
68 ) {
69 $this->_config = CRM_Core_Config::singleton();
70
71 $locales = CRM_Core_I18n::getMultilingual();
72
73 $this->multilingual = (bool) $locales;
74 $this->locales = $locales;
75
76 $smarty = CRM_Core_Smarty::singleton();
77 //$smarty->compile_dir = $this->_config->templateCompileDir;
78 $smarty->assign('multilingual', $this->multilingual);
79 $smarty->assign('locales', $this->locales);
80
81 // we didn't call CRM_Core_BAO_ConfigSetting::retrieve(), so we need to set $dbLocale by hand
82 if ($this->multilingual) {
83 global $dbLocale;
84 $dbLocale = "_{$this->_config->lcMessages}";
85 }
86
87 parent::__construct($state, $action, $method, $name);
88 }
89
90 /**
91 * @param $version
92 *
93 * @return mixed
94 */
95 public static function &incrementalPhpObject($version) {
96 static $incrementalPhpObject = [];
97
98 $versionParts = explode('.', $version);
99 $versionName = CRM_Utils_EnglishNumber::toCamelCase($versionParts[0]) . CRM_Utils_EnglishNumber::toCamelCase($versionParts[1]);
100
101 if (!array_key_exists($versionName, $incrementalPhpObject)) {
102 $className = "CRM_Upgrade_Incremental_php_{$versionName}";
103 $incrementalPhpObject[$versionName] = new $className();
104 }
105 return $incrementalPhpObject[$versionName];
106 }
107
108 /**
109 * @param $version
110 * @param $release
111 *
112 * @return bool
113 */
114 public function checkVersionRelease($version, $release) {
115 $versionParts = explode('.', $version);
116 return ($versionParts[2] == $release);
117 }
118
119 /**
120 * @param $constraints
121 *
122 * @return array
123 */
124 public function checkSQLConstraints(&$constraints) {
125 $pass = $fail = 0;
126 foreach ($constraints as $constraint) {
127 if ($this->checkSQLConstraint($constraint)) {
128 $pass++;
129 }
130 else {
131 $fail++;
132 }
133 return [$pass, $fail];
134 }
135 }
136
137 /**
138 * @param $constraint
139 *
140 * @return bool
141 */
142 public function checkSQLConstraint($constraint) {
143 // check constraint here
144 return TRUE;
145 }
146
147 /**
148 * @param string $fileName
149 * @param bool $isQueryString
150 */
151 public function source($fileName, $isQueryString = FALSE) {
152 if ($isQueryString) {
153 CRM_Utils_File::runSqlQuery($this->_config->dsn,
154 $fileName, NULL
155 );
156 }
157 else {
158 CRM_Utils_File::sourceSQLFile($this->_config->dsn,
159 $fileName, NULL
160 );
161 }
162 }
163
164 public function preProcess() {
165 CRM_Utils_System::setTitle($this->getTitle());
166 if (!$this->verifyPreDBState($errorMessage)) {
167 if (!isset($errorMessage)) {
168 $errorMessage = 'pre-condition failed for current upgrade step';
169 }
170 throw new CRM_Core_Exception($errorMessage);
171 }
172 $this->assign('recentlyViewed', FALSE);
173 }
174
175 public function buildQuickForm() {
176 $this->addDefaultButtons($this->getButtonTitle(),
177 'next',
178 NULL,
179 TRUE
180 );
181 }
182
183 /**
184 * Getter function for title. Should be over-ridden by derived class
185 *
186 * @return string
187 */
188
189 /**
190 * @return string
191 */
192 public function getTitle() {
193 return ts('Title not Set');
194 }
195
196 /**
197 * @return string
198 */
199 public function getFieldsetTitle() {
200 return '';
201 }
202
203 /**
204 * @return string
205 */
206 public function getButtonTitle() {
207 return ts('Continue');
208 }
209
210 /**
211 * Use the form name to create the tpl file name.
212 *
213 * @return string
214 */
215
216 /**
217 * @return string
218 */
219 public function getTemplateFileName() {
220 $this->assign('title',
221 $this->getFieldsetTitle()
222 );
223 $this->assign('message',
224 $this->getTemplateMessage()
225 );
226 return 'CRM/Upgrade/Base.tpl';
227 }
228
229 public function postProcess() {
230 $this->upgrade();
231
232 if (!$this->verifyPostDBState($errorMessage)) {
233 if (!isset($errorMessage)) {
234 $errorMessage = 'post-condition failed for current upgrade step';
235 }
236 throw new CRM_Core_Exception($errorMessage);
237 }
238 }
239
240 /**
241 * @param $query
242 *
243 * @return Object
244 */
245 public function runQuery($query) {
246 return CRM_Core_DAO::executeQuery($query);
247 }
248
249 /**
250 * @param $version
251 *
252 * @return Object
253 */
254 public function setVersion($version) {
255 $this->logVersion($version);
256
257 $query = "
258 UPDATE civicrm_domain
259 SET version = '$version'
260 ";
261 return $this->runQuery($query);
262 }
263
264 /**
265 * @param $newVersion
266 *
267 * @return bool
268 */
269 public function logVersion($newVersion) {
270 if ($newVersion) {
271 $oldVersion = CRM_Core_BAO_Domain::version();
272
273 $session = CRM_Core_Session::singleton();
274 $logParams = [
275 'entity_table' => 'civicrm_domain',
276 'entity_id' => 1,
277 'data' => "upgrade:{$oldVersion}->{$newVersion}",
278 // lets skip 'modified_id' for now, as it causes FK issues And
279 // is not very important for now.
280 'modified_date' => date('YmdHis'),
281 ];
282 CRM_Core_BAO_Log::add($logParams);
283 return TRUE;
284 }
285
286 return FALSE;
287 }
288
289 /**
290 * @return array
291 * @throws Exception
292 */
293 public function getRevisionSequence() {
294 $revList = [];
295 $sqlDir = implode(DIRECTORY_SEPARATOR,
296 [dirname(__FILE__), 'Incremental', 'sql']
297 );
298 $sqlFiles = scandir($sqlDir);
299
300 $sqlFilePattern = '/^((\d{1,2}\.\d{1,2})\.(\d{1,2}\.)?(\d{1,2}|\w{4,7}))\.(my)?sql(\.tpl)?$/i';
301 foreach ($sqlFiles as $file) {
302 if (preg_match($sqlFilePattern, $file, $matches)) {
303 if (!in_array($matches[1], $revList)) {
304 $revList[] = $matches[1];
305 }
306 }
307 }
308
309 usort($revList, 'version_compare');
310 return $revList;
311 }
312
313 /**
314 * @param $tplFile
315 * @param $rev
316 *
317 * @return bool
318 */
319 public function processLocales($tplFile, $rev) {
320 $smarty = CRM_Core_Smarty::singleton();
321 $smarty->assign('domainID', CRM_Core_Config::domainID());
322
323 $this->source($smarty->fetch($tplFile), TRUE);
324
325 if ($this->multilingual) {
326 CRM_Core_I18n_Schema::rebuildMultilingualSchema($this->locales, $rev);
327 }
328 return $this->multilingual;
329 }
330
331 /**
332 * @param $rev
333 */
334 public function setSchemaStructureTables($rev) {
335 if ($this->multilingual) {
336 CRM_Core_I18n_Schema::schemaStructureTables($rev, TRUE);
337 }
338 }
339
340 /**
341 * @param $rev
342 *
343 * @throws Exception
344 */
345 public function processSQL($rev) {
346 $sqlFile = implode(DIRECTORY_SEPARATOR,
347 [
348 dirname(__FILE__),
349 'Incremental',
350 'sql',
351 $rev . '.mysql',
352 ]
353 );
354 $tplFile = "$sqlFile.tpl";
355
356 if (file_exists($tplFile)) {
357 $this->processLocales($tplFile, $rev);
358 }
359 else {
360 if (!file_exists($sqlFile)) {
361 throw new CRM_Core_Exception("sqlfile - $rev.mysql not found.");
362 }
363 $this->source($sqlFile);
364 }
365 }
366
367 /**
368 * Determine the start and end version of the upgrade process.
369 *
370 * @return array(0=>$currentVer, 1=>$latestVer)
371 */
372 public function getUpgradeVersions() {
373 $latestVer = CRM_Utils_System::version();
374 $currentVer = CRM_Core_BAO_Domain::version(TRUE);
375 if (!$currentVer) {
376 throw new CRM_Core_Exception(ts('Version information missing in civicrm database.'));
377 }
378 elseif (stripos($currentVer, 'upgrade')) {
379 throw new CRM_Core_Exception(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.'));
380 }
381 if (!$latestVer) {
382 throw new CRM_Core_Exception(ts('Version information missing in civicrm codebase.'));
383 }
384
385 return [$currentVer, $latestVer];
386 }
387
388 /**
389 * Determine if $currentVer can be upgraded to $latestVer
390 *
391 * @param $currentVer
392 * @param $latestVer
393 *
394 * @return mixed, a string error message or boolean 'false' if OK
395 */
396 public function checkUpgradeableVersion($currentVer, $latestVer) {
397 $error = FALSE;
398 // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
399 // lets do a pattern check -
400 if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
401 $error = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
402 }
403 elseif (version_compare($currentVer, $latestVer) > 0) {
404 // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
405 $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.',
406 [1 => $currentVer, 2 => $latestVer]
407 );
408 }
409 elseif (version_compare($currentVer, $latestVer) == 0) {
410 $error = ts('Your database has already been upgraded to CiviCRM %1',
411 [1 => $latestVer]
412 );
413 }
414 elseif (version_compare($currentVer, self::MINIMUM_UPGRADABLE_VERSION) < 0) {
415 $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.',
416 [1 => self::MINIMUM_UPGRADABLE_VERSION, 2 => $latestVer]
417 );
418 }
419
420 if (version_compare(phpversion(), CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER) < 0) {
421 $error = ts('CiviCRM %3 requires PHP version %1 (or newer), but the current system uses %2 ',
422 [
423 1 => CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER,
424 2 => phpversion(),
425 3 => $latestVer,
426 ]);
427 }
428
429 if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), CRM_Upgrade_Incremental_General::MIN_INSTALL_MYSQL_VER) < 0) {
430 $error = ts('CiviCRM %4 requires MySQL version v%1 or MariaDB v%3 (or newer), but the current system uses %2 ',
431 [
432 1 => CRM_Upgrade_Incremental_General::MIN_INSTALL_MYSQL_VER,
433 2 => CRM_Utils_SQL::getDatabaseVersion(),
434 3 => '10.1',
435 4 => $latestVer,
436 ]);
437 }
438
439 // check for mysql trigger privileges
440 if (!\Civi::settings()->get('logging_no_trigger_permission') && !CRM_Core_DAO::checkTriggerViewPermission(FALSE, TRUE)) {
441 $error = ts('CiviCRM %1 requires MySQL trigger privileges.',
442 [1 => $latestVer]);
443 }
444
445 if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024 * self::MINIMUM_THREAD_STACK)) {
446 $error = ts('CiviCRM %1 requires MySQL thread stack >= %2k', [
447 1 => $latestVer,
448 2 => self::MINIMUM_THREAD_STACK,
449 ]);
450 }
451
452 return $error;
453 }
454
455 /**
456 * Determine if $currentver already matches $latestVer
457 *
458 * @param $currentVer
459 * @param $latestVer
460 *
461 * @return mixed, a string error message or boolean 'false' if OK
462 */
463 public function checkCurrentVersion($currentVer, $latestVer) {
464 $error = FALSE;
465
466 // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
467 // lets do a pattern check -
468 if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
469 $error = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
470 }
471 elseif (version_compare($currentVer, $latestVer) != 0) {
472 $error = ts('Your database is not configured for version %1',
473 [1 => $latestVer]
474 );
475 }
476 return $error;
477 }
478
479 /**
480 * Fill the queue with upgrade tasks.
481 *
482 * @param string $currentVer
483 * the original revision.
484 * @param string $latestVer
485 * the target (final) revision.
486 * @param string $postUpgradeMessageFile
487 * path of a modifiable file which lists the post-upgrade messages.
488 *
489 * @return CRM_Queue_Service
490 */
491 public static function buildQueue($currentVer, $latestVer, $postUpgradeMessageFile) {
492 $upgrade = new CRM_Upgrade_Form();
493
494 // Ensure that queue can be created
495 if (!CRM_Queue_BAO_QueueItem::findCreateTable()) {
496 throw new CRM_Core_Exception(ts('Failed to find or create queueing table'));
497 }
498 $queue = CRM_Queue_Service::singleton()->create([
499 'name' => self::QUEUE_NAME,
500 'type' => 'Sql',
501 'reset' => TRUE,
502 ]);
503
504 $task = new CRM_Queue_Task(
505 ['CRM_Upgrade_Form', 'doFileCleanup'],
506 [$postUpgradeMessageFile],
507 "Cleanup old files"
508 );
509 $queue->createItem($task);
510
511 $task = new CRM_Queue_Task(
512 ['CRM_Upgrade_Form', 'disableOldExtensions'],
513 [$postUpgradeMessageFile],
514 "Checking extensions"
515 );
516 $queue->createItem($task);
517
518 $revisions = $upgrade->getRevisionSequence();
519 foreach ($revisions as $rev) {
520 // proceed only if $currentVer < $rev
521 if (version_compare($currentVer, $rev) < 0) {
522 $beginTask = new CRM_Queue_Task(
523 // callback
524 ['CRM_Upgrade_Form', 'doIncrementalUpgradeStart'],
525 // arguments
526 [$rev],
527 "Begin Upgrade to $rev"
528 );
529 $queue->createItem($beginTask);
530
531 $task = new CRM_Queue_Task(
532 // callback
533 ['CRM_Upgrade_Form', 'doIncrementalUpgradeStep'],
534 // arguments
535 [$rev, $currentVer, $latestVer, $postUpgradeMessageFile],
536 "Upgrade DB to $rev"
537 );
538 $queue->createItem($task);
539
540 $task = new CRM_Queue_Task(
541 // callback
542 ['CRM_Upgrade_Form', 'doIncrementalUpgradeFinish'],
543 // arguments
544 [$rev, $currentVer, $latestVer, $postUpgradeMessageFile],
545 "Finish Upgrade DB to $rev"
546 );
547 $queue->createItem($task);
548 }
549 }
550
551 return $queue;
552 }
553
554 /**
555 * Find any old, orphaned files that should have been deleted.
556 *
557 * These files can get left behind, eg, if you use the Joomla
558 * upgrade procedure.
559 *
560 * The earlier we can do this, the better - don't want upgrade logic
561 * to inadvertently rely on old/relocated files.
562 *
563 * @param \CRM_Queue_TaskContext $ctx
564 * @param string $postUpgradeMessageFile
565 * @return bool
566 */
567 public static function doFileCleanup(CRM_Queue_TaskContext $ctx, $postUpgradeMessageFile) {
568 $source = new CRM_Utils_Check_Component_Source();
569 $files = $source->findOrphanedFiles();
570 $errors = [];
571 foreach ($files as $file) {
572 if (is_dir($file['path'])) {
573 @rmdir($file['path']);
574 }
575 else {
576 @unlink($file['path']);
577 }
578
579 if (file_exists($file['path'])) {
580 $errors[] = sprintf("<li>%s</li>", htmlentities($file['path']));
581 }
582 }
583
584 if (!empty($errors)) {
585 file_put_contents($postUpgradeMessageFile,
586 '<br/><br/>' . ts('Some old files could not be removed. Please remove them.')
587 . '<ul>' . implode("\n", $errors) . '</ul>',
588 FILE_APPEND
589 );
590 }
591
592 return TRUE;
593 }
594
595 /**
596 * Disable/uninstall any extensions not compatible with this new version.
597 *
598 * @param \CRM_Queue_TaskContext $ctx
599 * @param string $postUpgradeMessageFile
600 * @return bool
601 */
602 public static function disableOldExtensions(CRM_Queue_TaskContext $ctx, $postUpgradeMessageFile) {
603 $messages = [];
604 $manager = CRM_Extension_System::singleton()->getManager();
605 foreach ($manager->getStatuses() as $key => $status) {
606 $enableReplacement = CRM_Core_DAO::singleValueQuery('SELECT is_active FROM civicrm_extension WHERE full_name = %1', [1 => [$key, 'String']]);
607 $obsolete = $manager->isIncompatible($key);
608 if ($obsolete) {
609 if (!empty($obsolete['disable']) && in_array($status, [$manager::STATUS_INSTALLED, $manager::STATUS_INSTALLED_MISSING])) {
610 try {
611 $manager->disable($key);
612 // Update the status for the sake of uninstall below.
613 $status = $status == $manager::STATUS_INSTALLED ? $manager::STATUS_DISABLED : $manager::STATUS_DISABLED_MISSING;
614 // This message is intentionally overwritten by uninstall below as it would be redundant
615 $messages[$key] = ts('The extension %1 is now obsolete and has been disabled.', [1 => $key]);
616 }
617 catch (CRM_Extension_Exception $e) {
618 $messages[] = ts('The obsolete extension %1 could not be removed due to an error. It is recommended to remove this extension manually.', [1 => $key]);
619 }
620 }
621 if (!empty($obsolete['uninstall']) && in_array($status, [$manager::STATUS_DISABLED, $manager::STATUS_DISABLED_MISSING])) {
622 try {
623 $manager->uninstall($key);
624 $messages[$key] = ts('The extension %1 is now obsolete and has been uninstalled.', [1 => $key]);
625 if ($status == $manager::STATUS_DISABLED) {
626 $messages[$key] .= ' ' . ts('You can remove it from your extensions directory.');
627 }
628 }
629 catch (CRM_Extension_Exception $e) {
630 $messages[] = ts('The obsolete extension %1 could not be removed due to an error. It is recommended to remove this extension manually.', [1 => $key]);
631 }
632 }
633 if (!empty($obsolete['force-uninstall'])) {
634 CRM_Core_DAO::executeQuery('UPDATE civicrm_extension SET is_active = 0 WHERE full_name = %1', [
635 1 => [$key, 'String'],
636 ]);
637 }
638 if (!empty($obsolete['replacement']) && $enableReplacement) {
639 try {
640 $manager->enable($manager->install($obsolete['replacement']));
641 $messages[] = ts('A replacement extension %1 has been installed as you had the obsolete extension %2 installed', [1 => $obsolete['replacement'], 2 => $key]);
642 }
643 catch (CRM_Extension_Exception $e) {
644 $messages[] = ts('The replacement extension %1 could not be installed due to an error. It is recommended to enable this extension manually.', [1 => $obsolete['replacement']]);
645 }
646 }
647 }
648 }
649 if ($messages) {
650 file_put_contents($postUpgradeMessageFile,
651 '<br/><br/><ul><li>' . implode("</li>\n<li>", $messages) . '</li></ul>',
652 FILE_APPEND
653 );
654 }
655
656 return TRUE;
657 }
658
659 /**
660 * Perform an incremental version update.
661 *
662 * @param CRM_Queue_TaskContext $ctx
663 * @param string $rev
664 * the target (intermediate) revision e.g '3.2.alpha1'.
665 *
666 * @return bool
667 */
668 public static function doIncrementalUpgradeStart(CRM_Queue_TaskContext $ctx, $rev) {
669 $upgrade = new CRM_Upgrade_Form();
670
671 // as soon as we start doing anything we append ".upgrade" to version.
672 // this also helps detect any partial upgrade issues
673 $upgrade->setVersion($rev . '.upgrade');
674
675 return TRUE;
676 }
677
678 /**
679 * Perform an incremental version update.
680 *
681 * @param CRM_Queue_TaskContext $ctx
682 * @param string $rev
683 * the target (intermediate) revision e.g '3.2.alpha1'.
684 * @param string $originalVer
685 * the original revision.
686 * @param string $latestVer
687 * the target (final) revision.
688 * @param string $postUpgradeMessageFile
689 * path of a modifiable file which lists the post-upgrade messages.
690 *
691 * @return bool
692 */
693 public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext $ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) {
694 $upgrade = new CRM_Upgrade_Form();
695
696 $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
697
698 $versionObject = $upgrade->incrementalPhpObject($rev);
699
700 // pre-db check for major release.
701 if ($upgrade->checkVersionRelease($rev, 'alpha1')) {
702 if (!(is_callable([$versionObject, 'verifyPreDBstate']))) {
703 throw new CRM_Core_Exception("verifyPreDBstate method was not found for $rev");
704 }
705
706 $error = NULL;
707 if (!($versionObject->verifyPreDBstate($error))) {
708 if (!isset($error)) {
709 $error = "post-condition failed for current upgrade for $rev";
710 }
711 throw new CRM_Core_Exception($error);
712 }
713
714 }
715
716 $upgrade->setSchemaStructureTables($rev);
717
718 if (is_callable([$versionObject, $phpFunctionName])) {
719 $versionObject->$phpFunctionName($rev, $originalVer, $latestVer);
720 }
721 else {
722 $upgrade->processSQL($rev);
723 }
724
725 // set post-upgrade-message if any
726 if (is_callable([$versionObject, 'setPostUpgradeMessage'])) {
727 $postUpgradeMessage = file_get_contents($postUpgradeMessageFile);
728 $versionObject->setPostUpgradeMessage($postUpgradeMessage, $rev);
729 file_put_contents($postUpgradeMessageFile, $postUpgradeMessage);
730 }
731
732 return TRUE;
733 }
734
735 /**
736 * Perform an incremental version update.
737 *
738 * @param CRM_Queue_TaskContext $ctx
739 * @param string $rev
740 * the target (intermediate) revision e.g '3.2.alpha1'.
741 * @param string $currentVer
742 * the original revision.
743 * @param string $latestVer
744 * the target (final) revision.
745 * @param string $postUpgradeMessageFile
746 * path of a modifiable file which lists the post-upgrade messages.
747 *
748 * @return bool
749 */
750 public static function doIncrementalUpgradeFinish(CRM_Queue_TaskContext $ctx, $rev, $currentVer, $latestVer, $postUpgradeMessageFile) {
751 $upgrade = new CRM_Upgrade_Form();
752 $upgrade->setVersion($rev);
753 CRM_Utils_System::flushCache();
754
755 return TRUE;
756 }
757
758 public static function doFinish() {
759 Civi::dispatcher()->setDispatchPolicy(\CRM_Upgrade_DispatchPolicy::get('upgrade.finish'));
760 $restore = \CRM_Utils_AutoClean::with(function() {
761 Civi::dispatcher()->setDispatchPolicy(\CRM_Upgrade_DispatchPolicy::get('upgrade.main'));
762 });
763
764 $upgrade = new CRM_Upgrade_Form();
765 list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
766 // Seems extraneous in context, but we'll preserve old behavior
767 $upgrade->setVersion($latestVer);
768
769 $config = CRM_Core_Config::singleton();
770 $config->userSystem->flush();
771
772 CRM_Core_Invoke::rebuildMenuAndCaches(FALSE, TRUE);
773 // NOTE: triggerRebuild is FALSE becaues it will run again in a moment (via fixSchemaDifferences).
774
775 $versionCheck = new CRM_Utils_VersionCheck();
776 $versionCheck->flushCache();
777
778 // Rebuild all triggers and re-enable logging if needed
779 $logging = new CRM_Logging_Schema();
780 $logging->fixSchemaDifferences();
781 // Force a rebuild of CiviCRM asset cache in case things have changed.
782 \Civi::service('asset_builder')->clear(FALSE);
783 }
784
785 /**
786 * Compute any messages which should be displayed before upgrade
787 * by calling the 'setPreUpgradeMessage' on each incremental upgrade
788 * object.
789 *
790 * @param string $preUpgradeMessage
791 * alterable.
792 * @param $currentVer
793 * @param $latestVer
794 */
795 public function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
796 // check for changed message templates
797 CRM_Upgrade_Incremental_General::checkMessageTemplate($preUpgradeMessage, $latestVer, $currentVer);
798 // set global messages
799 CRM_Upgrade_Incremental_General::setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
800
801 // Scan through all php files and see if any file is interested in setting pre-upgrade-message
802 // based on $currentVer, $latestVer.
803 // Please note, at this point upgrade hasn't started executing queries.
804 $revisions = $this->getRevisionSequence();
805 foreach ($revisions as $rev) {
806 if (version_compare($currentVer, $rev) < 0) {
807 $versionObject = $this->incrementalPhpObject($rev);
808 CRM_Upgrade_Incremental_General::updateMessageTemplate($preUpgradeMessage, $rev);
809 if (is_callable([$versionObject, 'setPreUpgradeMessage'])) {
810 $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer);
811 }
812 }
813 }
814 }
815
816 }