Skip to content

Commit 55a01c7

Browse files
wip
1 parent 3f6a071 commit 55a01c7

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

application/controllers/ApiV1ContactgroupsController.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ function (Filter\Condition $condition) {
213213
$contactgroupId = $this->getContactgroupId($identifier);
214214
if ($contactgroupId !== null) {
215215
$db->update('contactgroup', ['name' => $data['name']], ['id = ?' => $contactgroupId]);
216-
217-
$db->delete('contactgroup_member', ['contactgroup_id = ?' => $contactgroupId]);
216+
$db->update('contactgroup_member', ['deleted' => 'y'], ['contactgroup_id = ?' => $contactgroupId, 'deleted = ?' => 'n']);
218217

219218
if (! empty($data['users'])) {
220219
$this->addUsers($contactgroupId, $data['users']);
@@ -374,8 +373,25 @@ private function addUsers(int $contactgroupId, array $users): void
374373
*/
375374
private function removeContactgroup(int $id): void
376375
{
377-
Database::get()->delete('contactgroup_member', ['contactgroup_id = ?' => $id]);
378-
Database::get()->delete('contactgroup', ['id = ?' => $id]);
376+
$db = Database::get();
377+
$markAsDeleted = ['deleted' => 'y'];
378+
379+
$db->update(
380+
'rotation_member',
381+
$markAsDeleted + ['position' => null],
382+
['contactgroup_id = ?' => $id, 'deleted = ?' => 'n']
383+
);
384+
385+
$db->update(
386+
'rule_escalation_recipient',
387+
$markAsDeleted,
388+
['contactgroup_id = ?' => $id, 'deleted = ?' => 'n']
389+
);
390+
391+
$db->update('contactgroup_member', $markAsDeleted, ['contactgroup_id = ?' => $id, 'deleted = ?' => 'n']);
392+
$db->update('contactgroup', $markAsDeleted, ['id = ?' => $id]);
393+
394+
//TODO: properly remove rotations|escalations with no members as in form
379395
}
380396

381397
/**

application/controllers/ApiV1ContactsController.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,12 @@ function (Filter\Condition $condition) {
226226
$db->update('contact', [
227227
'full_name' => $data['full_name'],
228228
'username' => $data['username'] ?? null,
229-
'default_channel_id' => $this->getChannelId($data['default_channel'])
229+
'default_channel_id' => $this->getChannelId($data['default_channel']),
230230
], ['id = ?' => $contactId]);
231231

232-
$db->delete('contact_address', ['contact_id = ?' => $contactId]);
233-
$db->delete('contactgroup_member', ['contact_id = ?' => $contactId]);
232+
$markAsDeleted = ['deleted' => 'y'];
233+
$db->update('contact_address', $markAsDeleted, ['contact_id = ?' => $contactId, 'deleted = ?' => 'n']);
234+
$db->update('contactgroup_member', $markAsDeleted, ['contact_id = ?' => $contactId, 'deleted = ?' => 'n']);
234235

235236
if (! empty($data['addresses'])) {
236237
$this->addAddresses($contactId, $data['addresses']);
@@ -497,9 +498,26 @@ private function addAddresses(int $contactId, array $addresses): void
497498
*/
498499
private function removeContact(int $id): void
499500
{
500-
Database::get()->delete('contactgroup_member', ['contact_id = ?' => $id]);
501-
Database::get()->delete('contact_address', ['contact_id = ?' => $id]);
502-
Database::get()->delete('contact', ['id = ?' => $id]);
501+
$db = Database::get();
502+
$markAsDeleted = ['deleted' => 'y'];
503+
504+
$db->update(
505+
'rotation_member',
506+
$markAsDeleted + ['position' => null],
507+
['contact_id = ?' => $id, 'deleted = ?' => 'n']
508+
);
509+
510+
$db->update(
511+
'rule_escalation_recipient',
512+
$markAsDeleted,
513+
['contact_id = ?' => $id, 'deleted = ?' => 'n']
514+
);
515+
516+
$db->update('contactgroup_member', $markAsDeleted, ['contact_id = ?' => $id, 'deleted = ?' => 'n']);
517+
$db->update('contact_address', $markAsDeleted, ['contact_id = ?' => $id, 'deleted = ?' => 'n']);
518+
$db->update('contact', $markAsDeleted, ['id = ?' => $id]);
519+
520+
//TODO: properly remove rotations|escalations with no members as in form
503521
}
504522

505523
/**

0 commit comments

Comments
 (0)