From d95758b02f549c0662b9cabed7c55ad8cff8e5ef Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 3 Jul 2024 13:29:37 +0200 Subject: [PATCH] ContactGroupForm: Add missing filter and simplify code --- application/forms/ContactGroupForm.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) 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 ] ); }