[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaConfig: let single queries fail...

git at icinga.org git at icinga.org
Tue Jun 28 14:02:16 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Jun 28 14:01:43 2016 +0200

IcingaConfig: let single queries fail...

...and do not use transactions

---

 library/Director/IcingaConfig/IcingaConfig.php |  100 +++++++++++-------------
 1 file changed, 46 insertions(+), 54 deletions(-)

diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index 09e3622..21230a2 100644
--- a/library/Director/IcingaConfig/IcingaConfig.php
+++ b/library/Director/IcingaConfig/IcingaConfig.php
@@ -282,73 +282,65 @@ class IcingaConfig
         $fileTable = IcingaConfigFile::$table;
         $fileKey = IcingaConfigFile::$keyName;
 
-        $this->db->beginTransaction();
-        try {
-            $existingQuery = $this->db->select()
-                ->from($fileTable, 'checksum')
-                ->where('checksum IN (?)', array_map(array($this, 'dbBin'), $this->getFilesChecksums()));
+        $existingQuery = $this->db->select()
+            ->from($fileTable, 'checksum')
+            ->where('checksum IN (?)', array_map(array($this, 'dbBin'), $this->getFilesChecksums()));
 
-            $existing = $this->db->fetchCol($existingQuery);
+        $existing = $this->db->fetchCol($existingQuery);
 
-            foreach ($existing as $key => $val) {
-                if (is_resource($val)) {
-                    $existing[$key] = stream_get_contents($val);
-                }
+        foreach ($existing as $key => $val) {
+            if (is_resource($val)) {
+                $existing[$key] = stream_get_contents($val);
             }
+        }
 
-            $missing = array_diff($this->getFilesChecksums(), $existing);
-            $stored = array();
-
-            /** @var IcingaConfigFile $file */
-            foreach ($this->files as $name => $file) {
-                $checksum = $file->getChecksum();
-                if (! in_array($checksum, $missing)) {
-                    continue;
-                }
+        $missing = array_diff($this->getFilesChecksums(), $existing);
+        $stored = array();
 
-                if (array_key_exists($checksum, $stored)) {
-                    continue;
-                }
+        /** @var IcingaConfigFile $file */
+        foreach ($this->files as $name => $file) {
+            $checksum = $file->getChecksum();
+            if (! in_array($checksum, $missing)) {
+                continue;
+            }
 
-                $stored[$checksum] = true;
-
-                $this->db->insert(
-                    $fileTable,
-                    array(
-                        $fileKey       => $this->dbBin($checksum),
-                        'content'      => $file->getContent(),
-                        'cnt_object'   => $file->getObjectCount(),
-                        'cnt_template' => $file->getTemplateCount()
-                    )
-                );
+            if (array_key_exists($checksum, $stored)) {
+                continue;
             }
 
-            $activity = $this->dbBin($this->getLastActivityChecksum());
+            $stored[$checksum] = true;
+
             $this->db->insert(
-                self::$table,
+                $fileTable,
                 array(
-                    'duration'                => $this->generationTime,
-                    'first_activity_checksum' => $activity,
-                    'last_activity_checksum'  => $activity,
-                    'checksum'                => $this->dbBin($this->getChecksum()),
+                    $fileKey       => $this->dbBin($checksum),
+                    'content'      => $file->getContent(),
+                    'cnt_object'   => $file->getObjectCount(),
+                    'cnt_template' => $file->getTemplateCount()
                 )
             );
-            /** @var IcingaConfigFile $file */
-            foreach ($this->files as $name => $file) {
-                $this->db->insert(
-                    'director_generated_config_file',
-                    array(
-                        'config_checksum' => $this->dbBin($this->getChecksum()),
-                        'file_checksum'   => $this->dbBin($file->getChecksum()),
-                        'file_path'       => $name,
-                    )
-                );
-            }
+        }
 
-            $this->db->commit();
-        } catch (Exception $e) {
-            $this->db->rollBack();
-            throw $e;
+        $activity = $this->dbBin($this->getLastActivityChecksum());
+        $this->db->insert(
+            self::$table,
+            array(
+                'duration'                => $this->generationTime,
+                'first_activity_checksum' => $activity,
+                'last_activity_checksum'  => $activity,
+                'checksum'                => $this->dbBin($this->getChecksum()),
+            )
+        );
+        /** @var IcingaConfigFile $file */
+        foreach ($this->files as $name => $file) {
+            $this->db->insert(
+                'director_generated_config_file',
+                array(
+                    'config_checksum' => $this->dbBin($this->getChecksum()),
+                    'file_checksum'   => $this->dbBin($file->getChecksum()),
+                    'file_path'       => $name,
+                )
+            );
         }
 
         return $this;



More information about the icinga-checkins mailing list