[icinga-checkins] icinga.org: icingaweb2/bugfix/inirepository-updatedelete-12065: IniRepository: Avoid using iterator_to_array with ArrayDatasource

git at icinga.org git at icinga.org
Tue Jun 28 16:20:39 CEST 2016


Module: icingaweb2
Branch: bugfix/inirepository-updatedelete-12065
Commit: 2c93471f6f6c7cb35467412ddcf050ba0b7c5c18
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=2c93471f6f6c7cb35467412ddcf050ba0b7c5c18

Author: Markus Frosch <lazyfrosch at icinga.org>
Date:   Tue Jun 28 16:16:29 2016 +0200

IniRepository: Avoid using iterator_to_array with ArrayDatasource

While iterating ConfigObject/ArrayDatasource will not rewrite the section header into a row value as keycolumn.

In addition we now properly use the filter.

refs #12065

---

 library/Icinga/Repository/IniRepository.php |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/library/Icinga/Repository/IniRepository.php b/library/Icinga/Repository/IniRepository.php
index f197631..c7fcaec 100644
--- a/library/Icinga/Repository/IniRepository.php
+++ b/library/Icinga/Repository/IniRepository.php
@@ -98,11 +98,11 @@ abstract class IniRepository extends Repository implements Extensible, Updatable
         }
 
         $newSection = null;
-        foreach (iterator_to_array($this->ds) as $section => $config) {
-            if ($filter !== null && !$filter->matches($config)) {
-                continue;
-            }
 
+        $query = $this->ds->select();
+        $query->addFilter($filter);
+
+        foreach ($query as $section => $config) {
             if ($newSection !== null) {
                 throw new StatementException(
                     t('Cannot update. Column "%s" holds a section\'s name which must be unique'),
@@ -150,12 +150,12 @@ abstract class IniRepository extends Repository implements Extensible, Updatable
             $filter = $this->requireFilter($target, $filter);
         }
 
-        foreach (iterator_to_array($this->ds) as $section => $config) {
-            if ($filter === null || $filter->matches($config)) {
-                $this->ds->removeSection($section);
-            }
-        }
+        $query = $this->ds->select();
+        $query->addFilter($filter);
 
+        foreach ($query as $section => $config) {
+            $this->ds->removeSection($section);
+        }
         try {
             $this->ds->saveIni();
         } catch (Exception $e) {



More information about the icinga-checkins mailing list