Skip to content

Commit

Permalink
Contact(group)Form: Delete timeperiod_entry when the member is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 11, 2024
1 parent 2ebe803 commit 49ca621
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions application/forms/ContactGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,24 @@ public function removeContactgroup(): void
$markAsDeleted = ['changed_at' => time() * 1000, 'deleted' => 'y'];
$updateCondition = ['contactgroup_id = ?' => $this->contactgroupId, 'deleted = ?' => 'n'];

$rotationIds = $this->db->fetchCol(
$rotationAndMemberIds = $this->db->fetchPairs(
RotationMember::on($this->db)
->columns('rotation_id')
->columns(['id', 'rotation_id'])
->filter(Filter::equal('contactgroup_id', $this->contactgroupId))
->assembleSelect()
);

$rotationMemberIds = array_keys($rotationAndMemberIds);
$rotationIds = array_values($rotationAndMemberIds);

$this->db->update('rotation_member', $markAsDeleted + ['position' => null], $updateCondition);

$this->db->update(
'timeperiod_entry',
$markAsDeleted,
['rotation_member_id IN (?)' => $rotationMemberIds, 'deleted = ?' => 'n']
);

if (! empty($rotationIds)) {
$rotationIdsWithOtherMembers = $this->db->fetchCol(
RotationMember::on($this->db)
Expand Down
13 changes: 11 additions & 2 deletions library/Notifications/Web/Form/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,24 @@ public function removeContact(): void
$markAsDeleted = ['changed_at' => time() * 1000, 'deleted' => 'y'];
$updateCondition = ['contact_id = ?' => $this->contactId, 'deleted = ?' => 'n'];

$rotationIds = $this->db->fetchCol(
$rotationAndMemberIds = $this->db->fetchPairs(
RotationMember::on($this->db)
->columns('rotation_id')
->columns(['id', 'rotation_id'])
->filter(Filter::equal('contact_id', $this->contactId))
->assembleSelect()
);

$rotationMemberIds = array_keys($rotationAndMemberIds);
$rotationIds = array_values($rotationAndMemberIds);

$this->db->update('rotation_member', $markAsDeleted + ['position' => null], $updateCondition);

$this->db->update(
'timeperiod_entry',
$markAsDeleted,
['rotation_member_id IN (?)' => $rotationMemberIds, 'deleted = ?' => 'n']
);

if (! empty($rotationIds)) {
$rotationIdsWithOtherMembers = $this->db->fetchCol(
RotationMember::on($this->db)
Expand Down

0 comments on commit 49ca621

Please sign in to comment.