[icinga-checkins] icinga.org: icingaweb2-module-director/feature/icinga1-config-12919: IcingaTimeperiodRanges(Legacy): Implement toLegacyConfigString

git at icinga.org git at icinga.org
Fri Oct 14 15:36:27 CEST 2016


Module: icingaweb2-module-director
Branch: feature/icinga1-config-12919
Commit: 47072df9ff65e656888edb1b3c903947f41a674d
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=47072df9ff65e656888edb1b3c903947f41a674d

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Fri Oct 14 13:03:54 2016 +0200

IcingaTimeperiodRanges(Legacy): Implement toLegacyConfigString

refs #12919

---

 library/Director/Objects/IcingaObject.php          |   13 +++++++++++-
 .../Director/Objects/IcingaTimePeriodRanges.php    |   22 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 5636dff..9388767 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -1841,6 +1841,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         }
     }
 
+    /**
+     * @return string
+     */
+    protected function renderLegacyRanges()
+    {
+        if ($this->supportsRanges()) {
+            return $this->ranges()->toLegacyConfigString();
+        } else {
+            return '';
+        }
+    }
 
     /**
      * @return string
@@ -1957,7 +1968,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             $this->renderLegacyObjectHeader(),
             $this->renderLegacyImports(),
             $this->renderLegacyProperties(),
-            //$this->renderRanges(),
+            $this->renderLegacyRanges(),
             //$this->renderArguments(),
             //$this->renderRelatedSets(),
             $this->renderLegacyGroups(),
diff --git a/library/Director/Objects/IcingaTimePeriodRanges.php b/library/Director/Objects/IcingaTimePeriodRanges.php
index e55aef8..d0a75dc 100644
--- a/library/Director/Objects/IcingaTimePeriodRanges.php
+++ b/library/Director/Objects/IcingaTimePeriodRanges.php
@@ -7,6 +7,7 @@ use Iterator;
 use Countable;
 use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
 use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
+use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
 
 class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRenderer
 {
@@ -286,4 +287,25 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
             }
         }
     }
+
+    public function toLegacyConfigString()
+    {
+        if (empty($this->ranges) && $this->object->object_type === 'template') {
+            return '';
+        }
+
+        $out = '';
+
+        foreach ($this->ranges as $range) {
+            $out .= c1::renderKeyValue(
+                $range->range_key,
+                $range->range_value
+            );
+        }
+        if ($out !== '') {
+            $out = "\n".$out;
+        }
+
+        return $out;
+    }
 }



More information about the icinga-checkins mailing list