diff --git a/application/forms/RotationConfigForm.php b/application/forms/RotationConfigForm.php index 9f9a2e78a..7c8da2f00 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,37 @@ public function editRotation(int $rotationId): void */ public function removeRotation(int $id): void { - throw new NotImplementedError('Not implemented'); + $scheduleId = $this->getValue('schedule'); + $priority = $this->getValue('priority'); + if ($scheduleId === null || $priority === null) { + throw new LogicException('The schedule and priority must be populated'); + } + + $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]); + + $this->db->update('rotation', ['priority' => new Expression('priority - 1')], [ + 'schedule_id = ?' => $scheduleId, + 'priority > ?' => $priority + ]); + + if ($transactionStarted) { + $this->db->commitTransaction(); + } } protected function assembleModeSelection(): string