Skip to content

Commit

Permalink
Forms: Do not update changed_at column of deleted entries again
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 10, 2024
1 parent f841484 commit bd53dde
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
25 changes: 12 additions & 13 deletions application/forms/ContactGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions application/forms/SaveEventRuleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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']
);
}

Expand Down
7 changes: 6 additions & 1 deletion library/Notifications/Model/Rotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 7 additions & 9 deletions library/Notifications/Web/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down

0 comments on commit bd53dde

Please sign in to comment.