diff --git a/CRM/Upgrade/Headless.php b/CRM/Upgrade/Headless.php index 44dca076c916..674a334e5527 100644 --- a/CRM/Upgrade/Headless.php +++ b/CRM/Upgrade/Headless.php @@ -14,6 +14,12 @@ */ class CRM_Upgrade_Headless { + /** + * Pre Upgrade Message + * @var string + */ + private $preUpgradeMessage; + /** * Perform an upgrade without using the web-frontend * @@ -38,8 +44,11 @@ public function run($enablePrint = TRUE) { CRM_Core_DAO::dropTriggers(); // CRM-11156 - $preUpgradeMessage = NULL; - $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); + if (empty($this->preUpgradeMessage)) { + $preUpgradeMessage = NULL; + $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); + $this->preUpgradeMessage = $preUpgradeMessage; + } $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade'); $queueRunner = new CRM_Queue_Runner([ @@ -67,4 +76,25 @@ public function run($enablePrint = TRUE) { ]; } + /** + * Get the PreUpgrade message + * @return string + * @throws \Exception + */ + public function getPreUpgradeMessage(): string { + $upgrade = new CRM_Upgrade_Form(); + [$currentVer, $latestVer] = $upgrade->getUpgradeVersions(); + + if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) { + throw new Exception($error); + } + // CRM-11156 + if (empty($this->preUpgradeMessage)) { + $preUpgradeMessage = NULL; + $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer); + $this->preUpgradeMessage = $preUpgradeMessage; + } + return $this->preUpgradeMessage; + } + }