diff --git a/CRM/CivirulesActions/GroupContact/Remove.php b/CRM/CivirulesActions/GroupContact/Remove.php index 3777c9d5ccf639ed5ba4a67d6f8bf18ad5386beb..e6a303db7d5e33c177ec8344ed9e62e3ee427030 100644 --- a/CRM/CivirulesActions/GroupContact/Remove.php +++ b/CRM/CivirulesActions/GroupContact/Remove.php @@ -40,7 +40,7 @@ class CRM_CivirulesActions_GroupContact_Remove extends CRM_CivirulesActions_Grou $group_ids = $action_params['group_ids']; } foreach($group_ids as $group_id) { - if (CRM_Contact_BAO_GroupContact::isContactInGroup($contactId, $group_id)) { + if (CRM_CivirulesConditions_Utils_GroupContact::isContactInGroup($contactId, $group_id)) { $params = array(); $params['group_id'] = $group_id; diff --git a/CRM/CivirulesConditions/Contact/InGroup.php b/CRM/CivirulesConditions/Contact/InGroup.php index 65d50a7b5515a6641b4e22ec24d6026758965624..abd71b38ae21112dea216c5dd75f763456361225 100644 --- a/CRM/CivirulesConditions/Contact/InGroup.php +++ b/CRM/CivirulesConditions/Contact/InGroup.php @@ -52,7 +52,7 @@ class CRM_CivirulesConditions_Contact_InGroup extends CRM_Civirules_Condition { protected function contactIsNotMemberOfGroup($contact_id, $group_ids) { $isValid = true; foreach($group_ids as $gid) { - if (CRM_Contact_BAO_GroupContact::isContactInGroup($contact_id, $gid)) { + if (CRM_CivirulesConditions_Utils_GroupContact::isContactInGroup($contact_id, $gid)) { $isValid = false; break; } @@ -63,7 +63,7 @@ class CRM_CivirulesConditions_Contact_InGroup extends CRM_Civirules_Condition { protected function contactIsMemberOfOneGroup($contact_id, $group_ids) { $isValid = false; foreach($group_ids as $gid) { - if (CRM_Contact_BAO_GroupContact::isContactInGroup($contact_id, $gid)) { + if (CRM_CivirulesConditions_Utils_GroupContact::isContactInGroup($contact_id, $gid)) { $isValid = true; break; } @@ -74,7 +74,7 @@ class CRM_CivirulesConditions_Contact_InGroup extends CRM_Civirules_Condition { protected function contactIsMemberOfAllGroups($contact_id, $group_ids) { $isValid = 0; foreach($group_ids as $gid) { - if (CRM_Contact_BAO_GroupContact::isContactInGroup($contact_id, $gid)) { + if (CRM_CivirulesConditions_Utils_GroupContact::isContactInGroup($contact_id, $gid)) { $isValid++; } } diff --git a/CRM/CivirulesConditions/Utils/GroupContact.php b/CRM/CivirulesConditions/Utils/GroupContact.php new file mode 100644 index 0000000000000000000000000000000000000000..fc8b2dd67323abc38828500395c41f8edf7e9d2e --- /dev/null +++ b/CRM/CivirulesConditions/Utils/GroupContact.php @@ -0,0 +1,35 @@ +<?php + +class CRM_CivirulesConditions_Utils_GroupContact { + + /** + * Checks wether a contact is a member of a group + * + * This function is a copy of CRM_Contact_BAO_GroupContact::isContactInGroup but with + * a change so that the group contact cache won't be rebuild. Which somehow resulted + * in a deadlock + * + * @param $contact_id + * @param $group_id + * @return bool + */ + public static function isContactInGroup($contact_id, $group_id) { + if (!CRM_Utils_Rule::positiveInteger($contact_id) || + !CRM_Utils_Rule::positiveInteger($group_id) + ) { + return FALSE; + } + + $params = array( + array('group', 'IN', array($group_id => 1), 0, 0), + array('contact_id', '=', $contact_id, 0, 0), + ); + list($contacts, $_) = CRM_Contact_BAO_Query::apiQuery($params, array('contact_id'), null, null, 0, 1, false, false, true); + + if (!empty($contacts)) { + return TRUE; + } + return FALSE; + } + +} \ No newline at end of file