Skip to content

Commit

Permalink
Define isEvilUpgradeThatICannotBeBotheredToRemove()
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Mar 3, 2023
1 parent 8229dac commit 9f1ffbe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions CRM/Upgrade/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,26 @@ public static function isDatabaseStillBroken(): bool {
return $isCoreCurrent < 1;
}

/**
* We want to stop new API calls from getting into the upgrader. There are a couple already in
* there, and it's annoying to understand+replace after-the-fact, so this function is just a
* list of grandfathered methods.
*
* @return bool
*/
public static function isEvilUpgradeThatICannotBeBotheredToRemove(): bool {
$functions = [];
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $stackFrame) {
$functions[] = ($stackFrame['class'] ?? '') . '::' . ($stackFrame['function'] ?? '');
}
$evilOldFunctions = [
'CRM_Upgrade_Incremental_php_FiveFifty::convertMappingFieldLabelsToNames',
'CRM_Upgrade_Incremental_php_FiveFiftyOne::convertMappingFieldLabelsToNames',
'CRM_Upgrade_Incremental_php_FiveFiftyThree::addInvoicePDFFormat',
'CRM_Upgrade_Incremental_php_FiveFiftyThree::addRecentItemsProviders',
'CRM_Upgrade_Incremental_php_FiveSixty::addScheduledReminderSmartySetting',
];
return !empty(array_intersect($functions, $evilOldFunctions));
}

}
2 changes: 1 addition & 1 deletion Civi/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function run($entity, $action, $params) {
* @throws \CRM_Core_Exception
*/
public function runSafe($entity, $action, $params) {
if (\CRM_Core_Config::isUpgradeMode() && \CRM_Upgrade_Form::isDatabaseStillBroken()) {
if (\CRM_Core_Config::isUpgradeMode() && \CRM_Upgrade_Form::isDatabaseStillBroken() && !\CRM_Upgrade_Form::isEvilUpgradeThatICannotBeBotheredToRemove()) {
throw new \API_Exception("Don't put API calls in the upgrader.");
}

Expand Down

0 comments on commit 9f1ffbe

Please sign in to comment.