if (!is_array($contactIds)) {
return [0, 0, 0];
}
-
if ($status == 'Removed' || $status == 'Deleted') {
$op = 'delete';
}
foreach ($contactIds as $contactId) {
if ($status == 'Deleted') {
- $query = "DELETE FROM civicrm_group_contact WHERE contact_id=$contactId AND group_id=$groupId";
- $dao = CRM_Core_DAO::executeQuery($query);
+ $query = "DELETE FROM civicrm_group_contact WHERE contact_id = %1 AND group_id = %2";
+ $dao = CRM_Core_DAO::executeQuery($query, [
+ 1 => [$contactId, 'Positive'],
+ 2 => [$groupId, 'Positive'],
+ ]);
$historyParams = [
'group_id' => $groupId,
'contact_id' => $contactId,
'tracking' => $tracking,
];
CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
+ // Removing a row from civicrm_group_contact for a smart group may mean a contact
+ // Is now back in a group based on criteria so we will invalidate the cache if it is there
+ // So that accurate group cache is created next time it is needed.
+ CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($groupId);
}
else {
$groupContact = new CRM_Contact_DAO_GroupContact();
return date('YmdHis', strtotime("+ " . self::smartGroupCacheTimeout() . " Minutes"));
}
+ /**
+ * Invalidates the smart group cache for a particular group
+ * @param int $groupID - Group to invalidate
+ */
+ public static function invalidateGroupContactCache($groupID) {
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_group
+ SET cache_date = NULL, refresh_date = NULL
+ WHERE id = %1", [
+ 1 => [$groupID, 'Positive'],
+ ]);
+ }
+
}