From 7c19368db58f16858fde7f1c5fe50c0d640c0482 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:45:00 +0200 Subject: Adding upstream version 1.1.2. Signed-off-by: Daniel Baumann --- .../forms/Command/Object/DeleteDowntimeForm.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'application/forms/Command/Object/DeleteDowntimeForm.php') diff --git a/application/forms/Command/Object/DeleteDowntimeForm.php b/application/forms/Command/Object/DeleteDowntimeForm.php index 5f695b9..b13bcc5 100644 --- a/application/forms/Command/Object/DeleteDowntimeForm.php +++ b/application/forms/Command/Object/DeleteDowntimeForm.php @@ -4,12 +4,14 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; -use Generator; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\DeleteDowntimeCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Web\Notification; +use ipl\Orm\Model; use ipl\Web\Common\RedirectOption; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; class DeleteDowntimeForm extends CommandForm @@ -66,19 +68,14 @@ class DeleteDowntimeForm extends CommandForm ); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = (function () use ($objects): Generator { - foreach ($objects as $object) { - if ( - $this->isGrantedOn('icingadb/command/downtime/delete', $object->{$object->object_type}) - && $object->scheduled_by === null - ) { - yield $object; - } - } - })(); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $object->scheduled_by === null + && $this->isGrantedOn('icingadb/command/downtime/delete', $object->{$object->object_type}); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new DeleteDowntimeCommand(); $command->setObjects($granted); -- cgit v1.2.3