[icinga-checkins] icinga.org: icingaweb2-module-director/master: DirectorDeploymentLog: add helper methods...

git at icinga.org git at icinga.org
Wed May 25 15:24:17 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed May 25 15:04:00 2016 +0200

DirectorDeploymentLog: add helper methods...

...dealing with related configs

---

 library/Director/Objects/DirectorDeploymentLog.php |   51 ++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/library/Director/Objects/DirectorDeploymentLog.php b/library/Director/Objects/DirectorDeploymentLog.php
index 01cd07d..82eb1e3 100644
--- a/library/Director/Objects/DirectorDeploymentLog.php
+++ b/library/Director/Objects/DirectorDeploymentLog.php
@@ -3,6 +3,9 @@
 namespace Icinga\Module\Director\Objects;
 
 use Icinga\Module\Director\Data\Db\DbObject;
+use Icinga\Module\Director\Db;
+use Icinga\Module\Director\IcingaConfig\IcingaConfig;
+use Icinga\Module\Director\Util;
 
 class DirectorDeploymentLog extends DbObject
 {
@@ -12,6 +15,8 @@ class DirectorDeploymentLog extends DbObject
 
     protected $autoincKeyName = 'id';
 
+    protected $config;
+
     protected $defaultProperties = array(
         'id'                     => null,
         'config_checksum'        => null,
@@ -30,4 +35,50 @@ class DirectorDeploymentLog extends DbObject
         'username'               => null,
         'startup_log'            => null,
     );
+
+    public function getConfigHexChecksum()
+    {
+        return Util::binary2hex($this->config_checksum);
+    }
+
+    public function getConfig()
+    {
+        if ($this->config === null) {
+            $this->config = IcingaConfig::load($this->config_checksum);
+        }
+
+        return $this->config;
+    }
+
+    public function configEquals(IcingaConfig $config)
+    {
+        return $this->config_checksum === $config->getChecksum();
+    }
+
+    public function getDeploymentTimestamp()
+    {
+        return strtotime($this->start_time);
+    }
+
+    public static function hasDeployments(Db $connection)
+    {
+        $db = $connection->getDbAdapter();
+        $query = $db->select()->from(
+            'director_deployment_log',
+            array('c' => 'COUNT(*)')
+        );
+
+        return (int) $db->fetchOne($query) > 0;
+    }
+
+    public static function loadLatest(Db $connection)
+    {
+        $db = $connection->getDbAdapter();
+        $query = $db->select()->from(
+            'director_deployment_log',
+            array('id' => 'MAX(id)')
+        );
+
+        return static::load($db->fetchOne($query), $connection);
+    }
 }



More information about the icinga-checkins mailing list