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