From ffd12e325cf59a628c8a19d586c1103d04400f01 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Thu, 7 May 2015 14:05:16 +0200 Subject: [PATCH] Improve up downtime command form properties Use a flag instead of a enumeration in delete downtime command form, to remove needless boilerplate. refs #8624 --- .../Object/DeleteDowntimeCommandForm.php | 2 +- .../Command/Object/DeleteDowntimeCommand.php | 34 +++++++------------ .../IcingaCommandFileCommandRenderer.php | 7 +--- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php index 1d959caab..31ec778fa 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php @@ -21,7 +21,7 @@ class DeleteDowntimeCommandForm extends CommandForm $this->setAttrib('class', 'inline'); } - /** + /** * (non-PHPDoc) * @see \Icinga\Web\Form::createElements() For the method documentation. */ diff --git a/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php index 96dc8f755..a2c593f26 100644 --- a/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php +++ b/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php @@ -10,46 +10,38 @@ use Icinga\Module\Monitoring\Command\IcingaCommand; */ class DeleteDowntimeCommand extends IcingaCommand { - /** - * Downtime for a host - */ - const DOWNTIME_TYPE_HOST = 'host'; - - /** - * Downtime for a service - */ - const DOWNTIME_TYPE_SERVICE = 'service'; - /** * ID of the downtime that is to be deleted * * @var int */ protected $downtimeId; - + /** + * If the command affects a service downtime * - * @var type + * @var boolean */ - protected $downtimeType = self::DOWNTIME_TYPE_HOST; - + protected $isService = false; + /** - * Set the downtime type, either host or service + * Set if this command affects a service * - * @param string $type the downtime type + * @param type $value */ - public function setDowntimeType($type) + public function setIsService($value = true) { - $this->downtimeType = $type; + $this->isService = (bool) $value; } /** - * + * Return whether the command affects a service + * * @return type */ - public function getDowntimeType() + public function getIsService() { - return $this->downtimeType; + return $this->isService; } /** diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php index 19d7574ca..f6a35dcc2 100644 --- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php +++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaCommandFileCommandRenderer.php @@ -332,14 +332,9 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface public function renderDeleteDowntime(DeleteDowntimeCommand $command) { - if ($command->getDowntimeType() === 'host') { - $commandString = 'DEL_HOST_DOWNTIME'; - } else { - $commandString = 'DEL_SVC_DOWNTIME'; - } return sprintf( '%s;%u', - $commandString, + $command->getIsService() ? 'DEL_SVC_DOWNTIME' : 'DEL_HOST_DOWNTIME', $command->getDowntimeId() ); }