mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-21 12:54:26 +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);
|
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 {
|
} else {
|
||||||
$query = $this->ds->select();
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$this->requireFilter($filter);
|
$this->requireFilter($filter);
|
||||||
$query->applyFilter($filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $query->fetchAll();
|
$contents = iterator_to_array($this->ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
$newSection = null;
|
$newSection = null;
|
||||||
foreach ($results as $section => $config) {
|
foreach ($contents as $section => $config) {
|
||||||
|
if ($filter && !$filter->matches($config)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($newSection !== null) {
|
if ($newSection !== null) {
|
||||||
throw new StatementException(
|
throw new StatementException(
|
||||||
t('Cannot update. Column "%s" holds a section\'s name which must be unique'),
|
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 ($newSection) {
|
||||||
if ($this->ds->hasSection($newSection)) {
|
if ($this->ds->hasSection($newSection)) {
|
||||||
throw new StatementException(t('Cannot update. Section "%s" does already exist'), $newSection);
|
throw new StatementException(t('Cannot update. Section "%s" does already exist'), $newSection);
|
||||||
@ -147,20 +145,18 @@ abstract class IniRepository extends Repository implements Extensible, Updatable
|
|||||||
return; // Nothing to do
|
return; // Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = array($target => $this->ds->getSection($target));
|
$this->ds->removeSection($target);
|
||||||
} else {
|
} else {
|
||||||
$query = $this->ds->select();
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$this->requireFilter($filter);
|
$this->requireFilter($filter);
|
||||||
$query->applyFilter($filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $query->fetchAll();
|
foreach (iterator_to_array($this->ds) as $section => $config) {
|
||||||
}
|
if (! $filter || $filter->matches($config)) {
|
||||||
|
|
||||||
foreach ($results as $section => $_) {
|
|
||||||
$this->ds->removeSection($section);
|
$this->ds->removeSection($section);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->ds->saveIni();
|
$this->ds->saveIni();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user