diff --git a/library/Icingadb/Model/Downtime.php b/library/Icingadb/Model/Downtime.php index 923d4b3a..9b188ece 100644 --- a/library/Icingadb/Model/Downtime.php +++ b/library/Icingadb/Model/Downtime.php @@ -11,7 +11,6 @@ use Icinga\Module\Icingadb\Model\Behavior\Timestamp; use ipl\Orm\Behaviors; use ipl\Orm\Model; use ipl\Orm\Relations; -use ipl\Sql\Expression; class Downtime extends Model { @@ -42,44 +41,44 @@ class Downtime extends Model 'entry_time', 'scheduled_start_time', 'scheduled_end_time', - 'flexible_duration', + 'scheduled_duration', 'is_flexible', + 'flexible_duration', 'is_in_effect', 'start_time', 'end_time', + 'duration', 'scheduled_by', - 'zone_id', - 'duration' => new Expression( - 'CASE WHEN %s = \'y\' THEN %s ELSE %s - %s END', - ['is_flexible', 'flexible_duration', 'scheduled_end_time', 'scheduled_start_time'] - ) + 'zone_id' ]; } public function getMetaData() { return [ - 'environment_id' => t('Downtime Environment Id'), - 'triggered_by_id' => t('Downtime Triggered By Id'), - 'parent_id' => t('Downtime Parent Id'), - 'object_type' => t('Downtime Object Type'), - 'host_id' => t('Downtime Host Id'), - 'service_id' => t('Downtime Service Id'), - 'name_checksum' => t('Downtime Name Checksum'), - 'properties_checksum' => t('Downtime Properties Checksum'), - 'name' => t('Downtime Name'), - 'author' => t('Downtime Author'), - 'comment' => t('Downtime Comment'), - 'entry_time' => t('Downtime Entry Time'), - 'scheduled_start_time' => t('Downtime Scheduled Start'), - 'scheduled_end_time' => t('Downtime Scheduled End'), - 'is_flexible' => t('Downtime Is Flexible'), - 'is_in_effect' => t('Downtime Is In Effect'), - 'start_time' => t('Downtime Actual Start'), - 'end_time' => t('Downtime Actual End'), - 'scheduled_by' => t('Downtime Scheduled By'), - 'zone_id' => t('Downtime Zone Id'), - 'duration' => t('Downtime Duration') + 'environment_id' => t('Downtime Environment Id'), + 'triggered_by_id' => t('Downtime Triggered By Id'), + 'parent_id' => t('Downtime Parent Id'), + 'object_type' => t('Downtime Object Type'), + 'host_id' => t('Downtime Host Id'), + 'service_id' => t('Downtime Service Id'), + 'name_checksum' => t('Downtime Name Checksum'), + 'properties_checksum' => t('Downtime Properties Checksum'), + 'name' => t('Downtime Name'), + 'author' => t('Downtime Author'), + 'comment' => t('Downtime Comment'), + 'entry_time' => t('Downtime Entry Time'), + 'scheduled_start_time' => t('Downtime Scheduled Start'), + 'scheduled_end_time' => t('Downtime Scheduled End'), + 'scheduled_duration' => t('Downtime Scheduled Duration'), + 'is_flexible' => t('Downtime Is Flexible'), + 'flexible_duration' => t('Downtime Flexible Duration'), + 'is_in_effect' => t('Downtime Is In Effect'), + 'start_time' => t('Downtime Actual Start'), + 'end_time' => t('Downtime Actual End'), + 'duration' => t('Downtime Duration'), + 'scheduled_by' => t('Downtime Scheduled By'), + 'zone_id' => t('Downtime Zone Id') ]; } @@ -104,13 +103,15 @@ class Downtime extends Model 'entry_time', 'scheduled_start_time', 'scheduled_end_time', + 'scheduled_duration', 'flexible_duration', 'start_time', - 'end_time' + 'end_time', + 'duration' ])); $behaviors->add(new ReRoute([ - 'hostgroup' => 'host.hostgroup', - 'servicegroup' => 'service.servicegroup' + 'hostgroup' => 'host.hostgroup', + 'servicegroup' => 'service.servicegroup' ])); } diff --git a/library/Icingadb/Model/DowntimeHistory.php b/library/Icingadb/Model/DowntimeHistory.php index f2fab037..47f16497 100644 --- a/library/Icingadb/Model/DowntimeHistory.php +++ b/library/Icingadb/Model/DowntimeHistory.php @@ -91,6 +91,7 @@ class DowntimeHistory extends Model 'entry_time', 'scheduled_start_time', 'scheduled_end_time', + 'flexible_duration', 'start_time', 'end_time', 'trigger_time', diff --git a/library/Icingadb/Widget/Detail/DowntimeDetail.php b/library/Icingadb/Widget/Detail/DowntimeDetail.php index f751e806..979dbcb1 100644 --- a/library/Icingadb/Widget/Detail/DowntimeDetail.php +++ b/library/Icingadb/Widget/Detail/DowntimeDetail.php @@ -41,18 +41,6 @@ class DowntimeDetail extends BaseHtmlElement /** @var Downtime */ protected $downtime; - /** @var int */ - protected $duration; - - /** @var string */ - protected $endTime; - - /** @var bool */ - protected $isActive; - - /** @var string */ - protected $startTime; - protected $defaultAttributes = ['class' => ['object-detail', 'downtime-detail']]; protected $tag = 'div'; @@ -60,23 +48,6 @@ class DowntimeDetail extends BaseHtmlElement public function __construct(Downtime $downtime) { $this->downtime = $downtime; - - if ($this->downtime->is_flexible && $this->downtime->is_in_effect) { - $this->startTime = $this->downtime->start_time; - } else { - $this->startTime = $this->downtime->scheduled_start_time; - } - - if ($this->downtime->is_flexible && $this->downtime->is_in_effect) { - $this->endTime = $this->downtime->start_time + $this->downtime->flexible_duration; - } else { - $this->endTime = $this->downtime->scheduled_end_time; - } - - $this->isActive = $this->downtime->is_in_effect - || $this->downtime->is_flexible && $this->downtime->scheduled_start_time <= time(); - - $this->duration = ($this->isActive ? $this->endTime : $this->startTime) - time(); } protected function createCancelDowntimeForm() @@ -159,9 +130,7 @@ class DowntimeDetail extends BaseHtmlElement )); $this->add(new HorizontalKeyValue( t('Scheduled Duration'), - DateFormatter::formatDuration( - $this->downtime->scheduled_end_time - $this->downtime->scheduled_start_time - ) + DateFormatter::formatDuration($this->downtime->scheduled_duration) )); if ($this->downtime->is_flexible) { $this->add(new HorizontalKeyValue( diff --git a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php index 445c3461..80b15153 100644 --- a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php @@ -5,17 +5,15 @@ namespace Icinga\Module\Icingadb\Widget\ItemList; use Icinga\Date\DateFormatter; +use Icinga\Module\Icingadb\Common\BaseListItem; use Icinga\Module\Icingadb\Common\HostLink; use Icinga\Module\Icingadb\Common\Icons; use Icinga\Module\Icingadb\Common\Links; -use Icinga\Module\Icingadb\Widget\MarkdownLine; use Icinga\Module\Icingadb\Common\NoSubjectLink; use Icinga\Module\Icingadb\Common\ObjectLinkDisabled; use Icinga\Module\Icingadb\Common\ServiceLink; use Icinga\Module\Icingadb\Model\Downtime; -use Icinga\Module\Icingadb\Common\BaseListItem; -use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList; -use ipl\Html\Attributes; +use Icinga\Module\Icingadb\Widget\MarkdownLine; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; use ipl\Html\HtmlElement; @@ -57,14 +55,9 @@ abstract class BaseDowntimeListItem extends BaseListItem { if ($this->item->is_flexible && $this->item->is_in_effect) { $this->startTime = $this->item->start_time; + $this->endTime = $this->item->end_time; } else { $this->startTime = $this->item->scheduled_start_time; - } - - if ($this->item->is_flexible && $this->item->is_in_effect) { -// $this->endTime = $this->item->end_time; - $this->endTime = $this->item->start_time + $this->item->flexible_duration; - } else { $this->endTime = $this->item->scheduled_end_time; } @@ -83,7 +76,7 @@ abstract class BaseDowntimeListItem extends BaseListItem $this->setObjectLinkDisabled($this->list->getObjectLinkDisabled()); $this->setNoSubjectLink($this->list->getNoSubjectLink()); - if ($this->isActive && $this->item->is_in_effect) { + if ($this->item->is_in_effect) { $this->getAttributes()->add('class', 'in-effect'); } }