From 4e662fdca670641634ba25dce69404585a20204a Mon Sep 17 00:00:00 2001 From: Jimmy Huang Date: Thu, 6 Jun 2024 16:45:36 +0800 Subject: [PATCH] refs #39637, add sync all function --- CRM/Contact/BAO/Group.php | 3 +++ CRM/Mailing/External/SmartMarketing.php | 27 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index e2b9e7b32..184418778 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -563,6 +563,9 @@ static function groupTypeCondition($groupType = NULL, $excludeHidden = TRUE) { elseif ($groupType == 'Access') { $value = CRM_Core_DAO::VALUE_SEPARATOR . '1' . CRM_Core_DAO::VALUE_SEPARATOR; } + elseif (is_numeric($groupType)) { + $value = CRM_Core_DAO::VALUE_SEPARATOR . "$groupType" . CRM_Core_DAO::VALUE_SEPARATOR; + } $condition = NULL; if ($excludeHidden) { diff --git a/CRM/Mailing/External/SmartMarketing.php b/CRM/Mailing/External/SmartMarketing.php index 572a2b453..766065030 100644 --- a/CRM/Mailing/External/SmartMarketing.php +++ b/CRM/Mailing/External/SmartMarketing.php @@ -23,7 +23,32 @@ abstract public function parseSavedData($json); * Sync all smart marketing to remote */ public static function syncAll() { - + $availableGroupTypes = CRM_Core_OptionGroup::values('group_type'); + $typeNames = array(); + foreach($availableGroupTypes as $typeId => $typeName) { + if (strstr($typeName, 'Smart Marketing')) { + list($smartMarketingVendor) = explode(' ', $typeName); + $typeNames[$typeId] = $smartMarketingVendor; + } + } + if (!empty($typeNames)) { + $syncResult = array(); + foreach($typeNames as $typeId => $class) { + $groups = CRM_Core_PseudoConstant::allGroup($typeId); + if (!empty($groups)) { + foreach($groups as $groupId => $groupName) { + // skip synced + if (isset($syncResult[$groupId])) { + continue; + } + $syncResult[$groupId] = self::syncGroup($groupId); + if (!empty($syncResult[$groupId]['result']['#report'])) { + CRM_Core_Error::debug_log_message(implode(' / ', $syncResult[$groupId]['result']['#report'])); + } + } + } + } + } } /**