From 1520d6fbf6f62566b2965e2d7666ffba5c3c6208 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 23 Feb 2016 17:03:52 +0100 Subject: [PATCH] IcingaConfig: support the same file content twice --- .../Director/IcingaConfig/IcingaConfig.php | 7 +++++++ library/Director/Import/Sync.php | 21 ++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 9b91a3f7..84529c10 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -227,6 +227,7 @@ class IcingaConfig } $missing = array_diff($this->getFilesChecksums(), $existing); + $stored = array(); /** @var IcingaConfigFile $file */ foreach ($this->files as $name => $file) { @@ -235,6 +236,12 @@ class IcingaConfig continue; } + if (array_key_exists($checksum, $stored)) { + continue; + } + + $stored[$checksum] = true; + $this->db->insert( $fileTable, array( diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index c5c47573..e9e59717 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -11,6 +11,8 @@ class Sync { protected $rule; + protected $sources; + protected $modify = array(); protected $remove = array(); @@ -205,17 +207,22 @@ class Sync return preg_replace_callback('/\${([A-Za-z0-9\._-]+)}/', $func, $string); } - protected function perpareImportSources() + /** + * Instantiates all related ImportSource objects + * + * @return array + */ + protected function prepareRelatedImportSources() { - $sources = array(); + $this->sources = array(); foreach ($this->syncProperties as $p) { - $sourceId = $p->source_id; - if (! array_key_exists($sourceId, $sources)) { - $sources[$sourceId] = ImportSource::load($sourceId, $this->db); + $id = $p->source_id; + if (! array_key_exists($id, $sources)) { + $this->sources[$id] = ImportSource::load($id, $this->db); } } - return $sources; + return $this->sources; } protected function prepareSourceColumns() @@ -438,7 +445,7 @@ class Sync protected function prepare() { $rule = $this->rule; - $sources = $this->perpareImportSources(); + $sources = $this->prepareRelatedImportSources(); $imported = $this->fetchImportedData($sources); // TODO: Make object_type (template, object...) and object_name mandatory?