diff --git a/application/forms/ContactGroupForm.php b/application/forms/ContactGroupForm.php index 7570f58aa..1f91bd685 100644 --- a/application/forms/ContactGroupForm.php +++ b/application/forms/ContactGroupForm.php @@ -252,31 +252,29 @@ public function editGroup(): void ->columns(['contact_id']) ->where([ 'contactgroup_id = ?' => $this->contactgroupId, + 'deleted = ?' => 'y', 'contact_id IN (?)' => $toAdd ]) ); - $removeDeletedFlagFromIds = []; + $toAdd = array_diff($toAdd, $contactsMarkedAsDeleted); foreach ($toAdd as $contactId) { - if (in_array($contactId, $contactsMarkedAsDeleted)) { - $removeDeletedFlagFromIds[] = $contactId; - } else { - $this->db->insert( - 'contactgroup_member', - [ - 'contactgroup_id' => $this->contactgroupId, - 'contact_id' => $contactId - ] - ); - } + $this->db->insert( + 'contactgroup_member', + [ + 'contactgroup_id' => $this->contactgroupId, + 'contact_id' => $contactId + ] + ); } - if (! empty($removeDeletedFlagFromIds)) { + + if (! empty($contactsMarkedAsDeleted)) { $this->db->update( 'contactgroup_member', ['changed_at' => $changedAt, 'deleted' => 'n'], [ 'contactgroup_id = ?' => $this->contactgroupId, - 'contact_id IN (?)' => $removeDeletedFlagFromIds + 'contact_id IN (?)' => $contactsMarkedAsDeleted ] ); }