[icinga-checkins] icinga.org: icingaweb2-module-director/master: Db: improve readability, less duplication

git at icinga.org git at icinga.org
Sat Feb 27 11:37:47 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sat Feb 27 11:37:29 2016 +0100

Db: improve readability, less duplication

---

 library/Director/Db.php |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/library/Director/Db.php b/library/Director/Db.php
index 424e9f0..3e6745d 100644
--- a/library/Director/Db.php
+++ b/library/Director/Db.php
@@ -444,14 +444,16 @@ class Db extends DbConnection
 
         $queries = array();
         $db = $this->db();
+        $cnt = "COALESCE(SUM(CASE WHEN o.object_type = '%s' THEN 1 ELSE 0 END), 0)";
+
         foreach ($types as $type) {
             $queries[] = $db->select()->from(
                 array('o' => 'icinga_' . $type),
                 array(
                     'icinga_type'  => "('" . $type . "')",
-                    'cnt_object'   => "COALESCE(SUM(CASE WHEN o.object_type = 'object' THEN 1 ELSE 0 END), 0)",
-                    'cnt_template' => "COALESCE(SUM(CASE WHEN o.object_type = 'template' THEN 1 ELSE 0 END), 0)",
-                    'cnt_external' => "COALESCE(SUM(CASE WHEN o.object_type = 'external_object' THEN 1 ELSE 0 END), 0)",
+                    'cnt_object'   => sprintf($cnt, 'object'),
+                    'cnt_template' => sprintf($cnt, 'template'),
+                    'cnt_external' => sprintf($cnt, 'external_object'),
                     'cnt_total'    => 'COUNT(*)',
                 )
             );



More information about the icinga-checkins mailing list