[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaServiceSet: simplify code

git at icinga.org git at icinga.org
Thu Oct 27 18:37:05 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: f09560a89e4f5b0613310629cb38c62fe93d789b
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=f09560a89e4f5b0613310629cb38c62fe93d789b

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 20 07:23:49 2016 +0000

IcingaServiceSet: simplify code

---

 library/Director/Objects/IcingaServiceSet.php |   34 ++++++++++---------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php
index 09dbc1e..e0afd2f 100644
--- a/library/Director/Objects/IcingaServiceSet.php
+++ b/library/Director/Objects/IcingaServiceSet.php
@@ -50,29 +50,21 @@ class IcingaServiceSet extends IcingaObject
      */
     public function getServiceObjects()
     {
-        if (! $this->hasBeenLoadedFromDb()) {
-            return array();
+        if ($this->host_id) {
+            $imports = $this->imports;
+            if (empty($imports)) {
+                return array();
+            }
+
+            $base = IcingaServiceSet::load(array(
+                'object_name' => array_shift($imports),
+                'object_type' => 'template'
+            ), $this->getConnection());
+        } else {
+            $base = $this;
         }
 
-        $conn = $this->getConnection();
-        $db = $conn->getDbAdapter();
-
-        $query = $db->select()->from(
-            array('s' => 'icinga_service'),
-            '*'
-        )->join(
-            array('sset' => 'icinga_service_set_service'),
-            'sset.service_id = s.id',
-            array()
-        )->where(
-            $db->quoteInto(
-                'sset.service_set_id = ?',
-                (int) $this->id
-            )
-        )->order('s.object_name');
-
-        // TODO: This cannot be prefetched
-        return IcingaService::loadAll($conn, $query, 'object_name');
+        return $base->getMultiRelation('service')->getObjects();
     }
 
     public function renderToConfig(IcingaConfig $config)



More information about the icinga-checkins mailing list