diff --git a/application/forms/ContactGroupForm.php b/application/forms/ContactGroupForm.php index 903be85d..07608ab1 100644 --- a/application/forms/ContactGroupForm.php +++ b/application/forms/ContactGroupForm.php @@ -243,7 +243,8 @@ public function editGroup(): void ['changed_at' => $changedAt, 'deleted' => 'y'], [ 'contactgroup_id = ?' => $this->contactgroupId, - 'contact_id IN (?)' => $toDelete + 'contact_id IN (?)' => $toDelete, + 'deleted = ?' => 'n' ] ); } @@ -294,6 +295,7 @@ public function removeContactgroup(): void $this->db->beginTransaction(); $markAsDeleted = ['changed_at' => time() * 1000, 'deleted' => 'y']; + $updateCondition = ['contactgroup_id = ?' => $this->contactgroupId, 'deleted = ?' => 'n']; $rotationIds = $this->db->fetchCol( RotationMember::on($this->db) @@ -302,11 +304,7 @@ public function removeContactgroup(): void ->assembleSelect() ); - $this->db->update( - 'rotation_member', - $markAsDeleted + ['position' => null], - ['contactgroup_id = ?' => $this->contactgroupId] - ); + $this->db->update('rotation_member', $markAsDeleted + ['position' => null], $updateCondition); if (! empty($rotationIds)) { $rotationIdsWithOtherMembers = $this->db->fetchCol( @@ -339,11 +337,7 @@ public function removeContactgroup(): void ->assembleSelect() ); - $this->db->update( - 'rule_escalation_recipient', - $markAsDeleted, - ['contactgroup_id = ?' => $this->contactgroupId] - ); + $this->db->update('rule_escalation_recipient', $markAsDeleted, $updateCondition); if (! empty($escalationIds)) { $escalationIdsWithOtherRecipients = $this->db->fetchCol( @@ -366,8 +360,13 @@ public function removeContactgroup(): void } } - $this->db->update('contactgroup_member', $markAsDeleted, ['contactgroup_id = ?' => $this->contactgroupId]); - $this->db->update('contactgroup', $markAsDeleted, ['id = ?' => $this->contactgroupId]); + $this->db->update('contactgroup_member', $markAsDeleted, $updateCondition); + + $this->db->update( + 'contactgroup', + $markAsDeleted, + ['id = ?' => $this->contactgroupId, 'deleted = ?' => 'n'] + ); $this->db->commitTransaction(); } diff --git a/application/forms/SaveEventRuleForm.php b/application/forms/SaveEventRuleForm.php index b7385d4d..dc46dcf7 100644 --- a/application/forms/SaveEventRuleForm.php +++ b/application/forms/SaveEventRuleForm.php @@ -344,7 +344,7 @@ function (array $element) use ($recipientId) { $db->update( 'rule_escalation_recipient', ['changed_at' => $changedAt, 'deleted' => 'y'], - ['id IN (?)' => $recipientsToRemove] + ['id IN (?)' => $recipientsToRemove, 'deleted = ?' => 'n'] ); } } @@ -455,7 +455,7 @@ public function editRule(int $id, array $config): void $db->update( 'rule_escalation_recipient', $markAsDeleted, - ['rule_escalation_id IN (?)' => $escalationsToRemove] + ['rule_escalation_id IN (?)' => $escalationsToRemove, 'deleted = ?' => 'n'] ); $db->update( @@ -501,7 +501,7 @@ public function removeRule(int $id): void $db->update( 'rule_escalation_recipient', $markAsDeleted, - ['rule_escalation_id IN (?)' => $escalationsToRemove] + ['rule_escalation_id IN (?)' => $escalationsToRemove, 'deleted = ?' => 'n'] ); } diff --git a/library/Notifications/Model/Rotation.php b/library/Notifications/Model/Rotation.php index 61a00098..d1d8547b 100644 --- a/library/Notifications/Model/Rotation.php +++ b/library/Notifications/Model/Rotation.php @@ -129,7 +129,12 @@ public function delete(): void $db->update('timeperiod_entry', $markAsDeleted, ['timeperiod_id = ?' => $timeperiodId]); $db->update('timeperiod', $markAsDeleted, ['id = ?' => $timeperiodId]); - $db->update('rotation_member', $markAsDeleted + ['position' => null], ['rotation_id = ?' => $this->id]); + + $db->update( + 'rotation_member', + $markAsDeleted + ['position' => null], + ['rotation_id = ?' => $this->id, 'deleted = ?' => 'n'] + ); $db->update( 'rotation', diff --git a/library/Notifications/Web/Form/ContactForm.php b/library/Notifications/Web/Form/ContactForm.php index 296fbde1..de8b5cd4 100644 --- a/library/Notifications/Web/Form/ContactForm.php +++ b/library/Notifications/Web/Form/ContactForm.php @@ -229,7 +229,7 @@ public function editContact(): void $this->db->update( 'contact_address', ['changed_at' => $changedAt, 'deleted' => 'y'], - ['id = ?' => $storedAddresses[$type][0]] + ['id = ?' => $storedAddresses[$type][0], 'deleted = ?' => 'n'] ); } } elseif (! isset($storedAddresses[$type])) { @@ -263,6 +263,7 @@ public function removeContact(): void $this->db->beginTransaction(); $markAsDeleted = ['changed_at' => time() * 1000, 'deleted' => 'y']; + $updateCondition = ['contact_id = ?' => $this->contactId, 'deleted = ?' => 'n']; $rotationIds = $this->db->fetchCol( RotationMember::on($this->db) @@ -271,11 +272,7 @@ public function removeContact(): void ->assembleSelect() ); - $this->db->update( - 'rotation_member', - $markAsDeleted + ['position' => null], - ['contact_id = ?' => $this->contactId] - ); + $this->db->update('rotation_member', $markAsDeleted + ['position' => null], $updateCondition); if (! empty($rotationIds)) { $rotationIdsWithOtherMembers = $this->db->fetchCol( @@ -310,7 +307,7 @@ public function removeContact(): void ->assembleSelect() ); - $this->db->update('rule_escalation_recipient', $markAsDeleted, ['contact_id = ?' => $this->contactId]); + $this->db->update('rule_escalation_recipient', $markAsDeleted, $updateCondition); if (! empty($escalationIds)) { $escalationIdsWithOtherRecipients = $this->db->fetchCol( @@ -333,8 +330,9 @@ public function removeContact(): void } } - $this->db->update('contactgroup_member', $markAsDeleted, ['contact_id = ?' => $this->contactId]); - $this->db->update('contact_address', $markAsDeleted, ['contact_id = ?' => $this->contactId]); + $this->db->update('contactgroup_member', $markAsDeleted, $updateCondition); + $this->db->update('contact_address', $markAsDeleted, $updateCondition); + $this->db->update('contact', $markAsDeleted + ['username' => null], ['id = ?' => $this->contactId]); $this->db->commitTransaction();