From 464670e2414d522f68b89d4b083e78c347667bb7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 15 Aug 2023 19:19:23 -0700 Subject: [PATCH] FiveSixtyTwo - Fix upgrade for domains with default value of `enable_components` --- CRM/Upgrade/Incremental/php/FiveSixtyTwo.php | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php b/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php index 02ac4664d7..44336fb31e 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php @@ -23,9 +23,8 @@ class CRM_Upgrade_Incremental_php_FiveSixtyTwo extends CRM_Upgrade_Incremental_B public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { if ($rev == '5.62.alpha1') { - $rawComponentLists = CRM_Core_DAO::executeQuery('SELECT value, count(*) c FROM civicrm_setting WHERE name = "enable_components" GROUP BY value') - ->fetchMap('value', 'value'); - $distinctComponentLists = array_unique(array_map(function(string $serializedList) { + $rawComponentLists = static::findEffectiveComponentsByDomain()->execute()->fetchMap('value', 'value'); + $distinctComponentLists = array_unique(array_map(function(?string $serializedList) { $list = \CRM_Utils_String::unserialize($serializedList); sort($list); return implode(',', $list); @@ -127,8 +126,7 @@ class CRM_Upgrade_Incremental_php_FiveSixtyTwo extends CRM_Upgrade_Incremental_B * Ex: ['CiviEvent', 'CiviMail'] */ public static function findAllEnabledComponents(): array { - $raw = CRM_Core_DAO::executeQuery('SELECT domain_id, value FROM civicrm_setting WHERE name = "enable_components"') - ->fetchMap('domain_id', 'value'); + $raw = static::findEffectiveComponentsByDomain()->execute()->fetchMap('domain_id', 'value'); $all = []; foreach ($raw as $value) { $all = array_unique(array_merge($all, \CRM_Utils_String::unserialize($value))); @@ -136,4 +134,20 @@ class CRM_Upgrade_Incremental_php_FiveSixtyTwo extends CRM_Upgrade_Incremental_B return array_values($all); } + /** + * @return \CRM_Utils_SQL_Select + * SQL Query. Each row has a `domain_id,value` with the de-facto value of the `enable_component` + * setting in that domain. + */ + private static function findEffectiveComponentsByDomain(): CRM_Utils_SQL_Select { + // Traditional list of components, as it existed circa 5.61. + $defaults = ['CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge']; + + return CRM_Utils_SQL_Select::from('civicrm_domain d') + ->join('civicrm_setting s', 'LEFT JOIN civicrm_setting s ON (d.id = s.domain_id AND s.name = "enable_components")') + ->select('d.id as domain_id, coalesce(s.value, @DEFAULT) as value') + ->param(['DEFAULT' => \serialize($defaults)]); + + } + } -- 2.25.1