[icinga-checkins] icinga.org: icingaweb2-module-director/feature-ddo-playground: Ddo\StateList: fix object creation

git at icinga.org git at icinga.org
Tue Jun 21 13:41:38 CEST 2016


Module: icingaweb2-module-director
Branch: feature-ddo-playground
Commit: de77db362b7e33b9ff77ada6ef7ce4ebbaad72b6
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=de77db362b7e33b9ff77ada6ef7ce4ebbaad72b6

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Jun 21 13:40:42 2016 +0200

Ddo\StateList: fix object creation

---

 library/Director/Ddo/StateList.php |   27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/library/Director/Ddo/StateList.php b/library/Director/Ddo/StateList.php
index 7104dbc..4e27db9 100644
--- a/library/Director/Ddo/StateList.php
+++ b/library/Director/Ddo/StateList.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Icinga\Module\Director\StateList;
+namespace Icinga\Module\Director\Ddo;
 
 class StateList
 {
@@ -8,7 +8,7 @@ class StateList
 
     protected $db;
 
-    protected $objects;
+    protected $objects = array();
 
     public function __construct(DdoDb $connection)
     {
@@ -29,8 +29,23 @@ class StateList
         }
 
         $object->processCheckResult($result);
-        if ($object->hasBeenModified()) {
-            $object->store();
+
+        return $object;
+    }
+
+    protected function createObject($host, $service, $key)
+    {
+        if ($service === null) {
+            return HostState::create(array(
+                'checksum' => $key,
+                'host'     => $host,
+            ), $this->connection);
+        } else {
+            return ServiceState::create(array(
+                'checksum' => $key,
+                'host'     => $host,
+                'service'  => $service,
+            ), $this->connection);
         }
     }
 
@@ -55,8 +70,8 @@ class StateList
     protected function createKey($host, $service = null)
     {
         $key = $host;
-        if (property_exists($result, 'service')) {
-            $key .= '!' . $result->service;
+        if ($service !== null) {
+            $key .= '!' . $service;
         }
 
         return sha1($key, true);



More information about the icinga-checkins mailing list