Skip to content

Commit

Permalink
Don't put API calls in the upgrader
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Aug 24, 2022
1 parent ed4f86c commit b6ba927
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
11 changes: 1 addition & 10 deletions CRM/Upgrade/DispatchPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ public static function pick(): ?array {
return NULL;
}

// Have we run CRM_Upgrade_Form::doCoreFinish() for this version?
$codeVer = CRM_Utils_System::version();
$isCoreCurrent = CRM_Core_DAO::singleValueQuery('
SELECT count(*) as count
FROM civicrm_log
WHERE entity_table = "civicrm_domain"
AND data LIKE %1
', [1 => ['upgrade:%->' . $codeVer, 'String']]);

return CRM_Upgrade_DispatchPolicy::get($isCoreCurrent < 1 ? 'upgrade.main' : 'upgrade.finish');
return CRM_Upgrade_DispatchPolicy::get(!CRM_Upgrade_Form::isDatabaseStillBroken() ? 'upgrade.main' : 'upgrade.finish');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions CRM/Upgrade/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,4 +884,22 @@ public function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVe
}
}

/**
* Has the condition of the database reached parity with the codebase?
*
* @return bool
* @throws \CRM_Core_Exception
*/
public static function isDatabaseStillBroken(): bool {
// Have we run CRM_Upgrade_Form::doCoreFinish() for this version?
$codeVer = CRM_Utils_System::version();
$isCoreCurrent = CRM_Core_DAO::singleValueQuery('
SELECT count(*) as count
FROM civicrm_log
WHERE entity_table = "civicrm_domain"
AND data LIKE %1
', [1 => ['upgrade:%->' . $codeVer, 'String']]);
return $isCoreCurrent < 1;
}

}
4 changes: 4 additions & 0 deletions Civi/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public function run($entity, $action, $params) {
* @throws \API_Exception
*/
public function runSafe($entity, $action, $params) {
if (\CRM_Core_Config::isUpgradeMode() && \CRM_Upgrade_Form::isDatabaseStillBroken()) {
throw new \API_Exception("Don't put API calls in the upgrader.");
}

$apiRequest = [];
try {
$apiRequest = Request::create($entity, $action, $params);
Expand Down

0 comments on commit b6ba927

Please sign in to comment.