From 6e889b4d9837e95245ccfa8eead3b34b4a4424b0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 16 May 2024 10:19:28 +0200 Subject: [PATCH] persist --- application/forms/RotationConfigForm.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/application/forms/RotationConfigForm.php b/application/forms/RotationConfigForm.php index 9f9a2e78a..044614060 100644 --- a/application/forms/RotationConfigForm.php +++ b/application/forms/RotationConfigForm.php @@ -8,7 +8,6 @@ use DateTime; use Generator; use Icinga\Exception\Http\HttpNotFoundException; -use Icinga\Exception\NotImplementedError; use Icinga\Module\Notifications\Common\Database; use Icinga\Module\Notifications\Model\Contact; use Icinga\Module\Notifications\Model\Contactgroup; @@ -365,7 +364,26 @@ public function editRotation(int $rotationId): void */ public function removeRotation(int $id): void { - throw new NotImplementedError('Not implemented'); + $transactionStarted = false; + if (! $this->db->inTransaction()) { + $transactionStarted = $this->db->beginTransaction(); + } + + $timeperiodId = $this->db->fetchScalar( + (new Select()) + ->from('timeperiod') + ->columns('id') + ->where(['owned_by_rotation_id = ?' => $id]) + ); + + $this->db->delete('timeperiod_entry', ['timeperiod_id = ?' => $timeperiodId]); + $this->db->delete('timeperiod', ['id = ?' => $timeperiodId]); + $this->db->delete('rotation_member', ['rotation_id = ?' => $id]); + $this->db->delete('rotation', ['id = ?' => $id]); + + if ($transactionStarted) { + $this->db->commitTransaction(); + } } protected function assembleModeSelection(): string