@@ -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