Skip to content

Commit

Permalink
Define isPreExistingEvil()
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Mar 3, 2023
1 parent 8229dac commit ad2154e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
60 changes: 60 additions & 0 deletions CRM/Upgrade/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,64 @@ 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 isPreExistingEvil(): bool {
$functions = [];
$stackFrames = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
foreach ($stackFrames as $stackFrame) {
$functions[] = ($stackFrame['class'] ?? '') . '::' . ($stackFrame['function'] ?? '');
if (($stackFrame['class'] ?? NULL) === CRM_Queue_Task::class) {
// Some upgrade functions are inherited, yielding two identities (e.g.
// 'CRM_Upgrade_Incremental_php_Base::updateSmartGroups' and
// 'CRM_Upgrade_Incremental_php_FiveFifteen::updateSmartGroups').
// The latter is better for grandfathering exceptions.
$task = $stackFrame['object'];
$functions[] = implode('::', (array) $task->callback);
}
}
$evilShallNotBeAllowedToGrow = [
'CRM_Upgrade_Incremental_php_FourSeven::disableFlexibleJobsExtension',
'CRM_Upgrade_Incremental_php_FourSeven::removePaymentProcessorType',
'CRM_Upgrade_Incremental_php_FourSeven::updateWysiwyg',
'CRM_Upgrade_Incremental_php_FourSeven::addDeletedByMergeActivityType',
'CRM_Upgrade_Incremental_php_FourSeven::addRefundAndChargeBackAccountsIfNotExist',
'CRM_Upgrade_Incremental_php_FourSeven::addWysiwygPresets',
'CRM_Upgrade_Incremental_php_FourSeven::addChangeCaseSubjectActivityType',
'CRM_Upgrade_Incremental_php_FourSeven::pickActivityRevisionPolicy',
'CRM_Upgrade_Incremental_php_FourSeven::removeContributionLoggingReports',
'CRM_Upgrade_Incremental_php_FiveFour::addActivityDefaultAssigneeOptions',
'CRM_Upgrade_Incremental_php_FiveEleven::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveTwelve::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveFifteen::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveFifteen::updateContributeSettings',
'CRM_Upgrade_Incremental_php_FiveSixteen::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveSeventeen::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveSeventeen::updateFileTypes',
'CRM_Upgrade_Incremental_php_FiveEighteen::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveEighteen::joinDateReportUpdate',
'CRM_Upgrade_Incremental_php_FiveNineteen::api4Menu',
'CRM_Upgrade_Incremental_php_FiveTwenty::templateStatus',
'CRM_Upgrade_Incremental_php_FiveTwentyThree::addXoauth2ProtocolOption',
'CRM_Upgrade_Incremental_php_FiveTwentyFive::convertReportsJcalendarToDatePicker',
'CRM_Upgrade_Incremental_php_FiveTwentySix::addNLBEOptionValue',
'CRM_Upgrade_Incremental_php_FiveThirtyNine::updateSmartGroups',
'CRM_Upgrade_Incremental_php_FiveForty::addGroupOptionList',
'CRM_Upgrade_Incremental_php_FiveForty::updateCkeditorOptionLabel',
'CRM_Upgrade_Incremental_php_FiveFortyTwo::addOptionGroup',
'CRM_Upgrade_Incremental_php_FiveFortySix::addImportCustomMenu',
'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, $evilShallNotBeAllowedToGrow));
}

}
4 changes: 3 additions & 1 deletion Civi/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ 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::isPreExistingEvil()) {
throw new \API_Exception("Don't put API calls in the upgrader.");
// This ^^ sometimes gets swallowed by API callers. For a more certain audit, use `die()`.
// debug_print_backtrace(); die("Don't put API calls in the upgrader.");
}

$apiRequest = [];
Expand Down

0 comments on commit ad2154e

Please sign in to comment.