Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Add in function to retrieve Pre Upgrade messages in headless #25414

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions CRM/Upgrade/Headless.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
*/
class CRM_Upgrade_Headless {

/**
* Pre Upgrade Message
* @var string
*/
private $preUpgradeMessage;

/**
* Perform an upgrade without using the web-frontend
*
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ug - this is a bit nasty that it is a pass-by-ref huh? Doesn't look like it is trivial to unravel though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is pass by reference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's also a confusing name... but there are 3 distinct structures which include variations on this signature (CRM_Upgrade_Incremental_Base and its subclasses; then also CRM_Upgrade_Form; then also CRM_Upgrade_Incremental_General).

$this->preUpgradeMessage = $preUpgradeMessage;
}

$postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade');
$queueRunner = new CRM_Queue_Runner([
Expand Down Expand Up @@ -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;
}

}