Skip to content

Commit

Permalink
persist
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed May 16, 2024
1 parent ef5ae22 commit 0701662
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions application/forms/RotationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0701662

Please sign in to comment.