From 30bc1db6ee44de9a80c066503e3da32ff2cb3391 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 11 May 2015 07:46:36 +0200 Subject: [PATCH] IniRepository: There is no need to fetch the results using a query Icinga\Application\Config is iterable. refs #8826 --- library/Icinga/Repository/IniRepository.php | 30 +++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/library/Icinga/Repository/IniRepository.php b/library/Icinga/Repository/IniRepository.php index 7953422be..6b95fcdc1 100644 --- a/library/Icinga/Repository/IniRepository.php +++ b/library/Icinga/Repository/IniRepository.php @@ -79,19 +79,21 @@ abstract class IniRepository extends Repository implements Extensible, Updatable throw new StatementException(t('Cannot update. Section "%s" does not exist'), $target); } - $results = array($target => $this->ds->getSection($target)); + $contents = array($target => $this->ds->getSection($target)); } else { - $query = $this->ds->select(); if ($filter) { $this->requireFilter($filter); - $query->applyFilter($filter); } - $results = $query->fetchAll(); + $contents = iterator_to_array($this->ds); } $newSection = null; - foreach ($results as $section => $config) { + foreach ($contents as $section => $config) { + if ($filter && !$filter->matches($config)) { + continue; + } + if ($newSection !== null) { throw new StatementException( t('Cannot update. Column "%s" holds a section\'s name which must be unique'), @@ -107,10 +109,6 @@ abstract class IniRepository extends Repository implements Extensible, Updatable } } - if ($keyColumn && isset($config->$keyColumn) && $config->$keyColumn === $section) { - unset($config->$keyColumn); - } - if ($newSection) { if ($this->ds->hasSection($newSection)) { throw new StatementException(t('Cannot update. Section "%s" does already exist'), $newSection); @@ -147,19 +145,17 @@ abstract class IniRepository extends Repository implements Extensible, Updatable return; // Nothing to do } - $results = array($target => $this->ds->getSection($target)); + $this->ds->removeSection($target); } else { - $query = $this->ds->select(); if ($filter) { $this->requireFilter($filter); - $query->applyFilter($filter); } - $results = $query->fetchAll(); - } - - foreach ($results as $section => $_) { - $this->ds->removeSection($section); + foreach (iterator_to_array($this->ds) as $section => $config) { + if (! $filter || $filter->matches($config)) { + $this->ds->removeSection($section); + } + } } try {