IcingaTimeperiod: Support includes and excludes

This commit is contained in:
Markus Frosch 2018-09-13 13:57:18 +02:00
parent 63eda31a64
commit 0d879c60d3
6 changed files with 202 additions and 2 deletions

View File

@ -52,8 +52,54 @@ class IcingaTimePeriodForm extends DirectorObjectForm
$this->addHidden('update_method', 'LegacyTimePeriod');
}
$this->addIncludeExclude();
$this->addImportsElement();
$this->setButtons();
}
protected function addIncludeExclude()
{
$periods = [];
foreach ($this->db->enumTimeperiods() as $id => $period) {
if ($this->object === null || $this->object->get('object_name') !== $period) {
$periods[$period] = $period;
}
}
if (empty($periods)) {
return;
}
$this->addElement(
'extensibleSet',
'includes',
array(
'label' => $this->translate('Include period'),
'description' => $this->translate(
'Include other time periods into this.'
),
'multiOptions' => $this->optionalEnum($periods),
)
);
$this->addElement(
'extensibleSet',
'excludes',
array(
'label' => $this->translate('Exclude period'),
'description' => $this->translate(
'Exclude other time periods from this.'
),
'multiOptions' => $this->optionalEnum($periods),
)
);
$this->optionalBoolean(
'prefer_includes',
$this->translate('Prefer includes'),
$this->translate('Whether to prefer timeperiods includes or excludes. Default to true.')
);
}
}

View File

@ -14,6 +14,7 @@ class IcingaTimePeriod extends IcingaObject
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'prefer_includes' => null,
'display_name' => null,
'update_method' => null,
);
@ -28,6 +29,18 @@ class IcingaTimePeriod extends IcingaObject
'zone' => 'IcingaZone',
);
protected $multiRelations = [
'includes' => [
'relatedObjectClass' => 'IcingaTimeperiod',
'relatedShortName' => 'include',
],
'excludes' => [
'relatedObjectClass' => 'IcingaTimeperiod',
'relatedShortName' => 'exclude',
'legacyPropertyName' => 'exclude'
],
];
/**
* Render update property
*

View File

@ -0,0 +1,38 @@
ALTER TABLE icinga_timeperiod
ADD COLUMN prefer_includes ENUM('y', 'n') DEFAULT NULL;
CREATE TABLE icinga_timeperiod_include (
timeperiod_id INT(10) UNSIGNED NOT NULL,
include_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (timeperiod_id, include_id),
CONSTRAINT icinga_timeperiod_include
FOREIGN KEY timeperiod (include_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT icinga_timeperiod_include_timeperiod
FOREIGN KEY include (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE icinga_timeperiod_exclude (
timeperiod_id INT(10) UNSIGNED NOT NULL,
exclude_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (timeperiod_id, exclude_id),
CONSTRAINT icinga_timeperiod_exclude
FOREIGN KEY timeperiod (exclude_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT icinga_timeperiod_exclude_timeperiod
FOREIGN KEY exclude (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (151, NOW());

View File

@ -197,6 +197,7 @@ CREATE TABLE icinga_timeperiod (
zone_id INT(10) UNSIGNED DEFAULT NULL,
object_type ENUM('object', 'template') NOT NULL,
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
prefer_includes ENUM('y', 'n') DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE INDEX object_name (object_name, zone_id),
CONSTRAINT icinga_timeperiod_zone
@ -1695,6 +1696,38 @@ CREATE TABLE icinga_dependency_states_set (
ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE TABLE icinga_timeperiod_include (
timeperiod_id INT(10) UNSIGNED NOT NULL,
include_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (timeperiod_id, include_id),
CONSTRAINT icinga_timeperiod_include
FOREIGN KEY timeperiod (include_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT icinga_timeperiod_include_timeperiod
FOREIGN KEY include (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE icinga_timeperiod_exclude (
timeperiod_id INT(10) UNSIGNED NOT NULL,
exclude_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (timeperiod_id, exclude_id),
CONSTRAINT icinga_timeperiod_exclude
FOREIGN KEY timeperiod (exclude_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT icinga_timeperiod_exclude_timeperiod
FOREIGN KEY exclude (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (150, NOW());
VALUES (151, NOW());

View File

@ -0,0 +1,38 @@
ALTER TABLE icinga_timeperiod
ADD COLUMN prefer_includes enum_boolean DEFAULT NULL;
CREATE TABLE icinga_timeperiod_include (
timeperiod_id integer NOT NULL,
include_id integer NOT NULL,
PRIMARY KEY (timeperiod_id, include_id),
CONSTRAINT icinga_timeperiod_timeperiod_include
FOREIGN KEY (include_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_timeperiod_include
FOREIGN KEY (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE icinga_timeperiod_exclude (
timeperiod_id integer NOT NULL,
exclude_id integer NOT NULL,
PRIMARY KEY (timeperiod_id, exclude_id),
CONSTRAINT icinga_timeperiod_timeperiod_exclude
FOREIGN KEY (exclude_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_timeperiod_exclude
FOREIGN KEY (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (151, NOW());

View File

@ -273,6 +273,7 @@ CREATE TABLE icinga_timeperiod (
zone_id integer DEFAULT NULL,
object_type enum_object_type_all NOT NULL,
disabled enum_boolean NOT NULL DEFAULT 'n',
prefer_includes enum_boolean DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT icinga_timeperiod_zone
FOREIGN KEY (zone_id)
@ -1990,7 +1991,38 @@ CREATE TABLE icinga_dependency_states_set (
CREATE INDEX dependency_states_set_dependency ON icinga_dependency_states_set (dependency_id);
COMMENT ON COLUMN icinga_dependency_states_set.merge_behaviour IS 'override: = [], extend: += [], blacklist: -= []';
CREATE TABLE icinga_timeperiod_include (
timeperiod_id integer NOT NULL,
include_id integer NOT NULL,
PRIMARY KEY (timeperiod_id, include_id),
CONSTRAINT icinga_timeperiod_timeperiod_include
FOREIGN KEY (include_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_timeperiod_include
FOREIGN KEY (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE icinga_timeperiod_exclude (
timeperiod_id integer NOT NULL,
exclude_id integer NOT NULL,
PRIMARY KEY (timeperiod_id, exclude_id),
CONSTRAINT icinga_timeperiod_timeperiod_exclude
FOREIGN KEY (exclude_id)
REFERENCES icinga_timeperiod (id)
ON DELETE RESTRICT
ON UPDATE CASCADE,
CONSTRAINT icinga_timeperiod_exclude
FOREIGN KEY (timeperiod_id)
REFERENCES icinga_timeperiod (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (150, NOW());
VALUES (151, NOW());