mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
IniRepository: There is no need to fetch the results using a query
Icinga\Application\Config is iterable. refs #8826
This commit is contained in:
parent
f1c82fc318
commit
30bc1db6ee
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user