Skip to content

Commit

Permalink
Merge pull request #24062 from eileenmcnaughton/api_query
Browse files Browse the repository at this point in the history
Remove legacy `apiquery` call from `isContactInGroup`
  • Loading branch information
colemanw authored Aug 2, 2022
2 parents 18c69c6 + 92b99d9 commit 539eb78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
26 changes: 9 additions & 17 deletions CRM/Contact/BAO/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Contact;
use Civi\Api4\SubscriptionHistory;
use Civi\Core\Event\PostEvent;
use Civi\Core\HookInterface;
Expand Down Expand Up @@ -502,28 +503,19 @@ public static function create(array $params) {
}

/**
* Function that doesn't do much.
*
* @param int $contactID
* @param int $groupID
*
* @deprecated
* @return bool
*/
public static function isContactInGroup($contactID, $groupID) {
if (!CRM_Utils_Rule::positiveInteger($contactID) ||
!CRM_Utils_Rule::positiveInteger($groupID)
) {
return FALSE;
}

$params = [
['group', 'IN', [$groupID], 0, 0],
['contact_id', '=', $contactID, 0, 0],
];
[$contacts] = CRM_Contact_BAO_Query::apiQuery($params, ['contact_id']);

if (!empty($contacts)) {
return TRUE;
}
return FALSE;
public static function isContactInGroup(int $contactID, int $groupID) {
return (bool) Contact::get(FALSE)
->addWhere('id', '=', $contactID)
->addWhere('groups', 'IN', [$groupID])
->selectRowCount()->execute()->count();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Contact/BAO/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ public function testDeleteContact() {
/**
* Test case for createProfileContact.
*/
public function testCreateProfileContact() {
public function testCreateProfileContact(): void {
//Create 3 groups.
foreach (['group1', 'group2', 'group3'] as $key => $title) {
$this->groups["id{$key}"] = $this->callAPISuccess('Group', 'create', [
'title' => $title,
'visibility' => "Public Pages",
'visibility' => 'Public Pages',
])['id'];
}

Expand Down

0 comments on commit 539eb78

Please sign in to comment.