Skip to content

Commit b6053a8

Browse files
TheSyscalllippserd
authored andcommitted
Rename should only work on form submission
1 parent ecb78f0 commit b6053a8

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

library/Icinga/Web/Form/ConfigForm.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,15 @@ protected function getIniKeyFromName(string $name): ?array
105105
* Get the value of a configuration key from an element name
106106
*
107107
* @param string $name The element name
108-
* @param mixed $default The default value to return if the element does not exist or the value is empty
108+
* @param mixed $default The default value to return if the config entry does not exist
109109
*
110110
* @return mixed The value of the configuration key or the default value
111111
*/
112112
public function getConfigValue(string $name, mixed $default = null): mixed
113113
{
114114
[$section, $key] = $this->getIniKeyFromName($name);
115-
if ($section !== null && $key !== null) {
116-
if (! $this->hasElement($name)) {
117-
return $default;
118-
}
119-
120-
if (($value = $this->getPopulatedValue($name)) !== null) {
121-
return $value;
122-
}
115+
if ($section === null || $key === null) {
116+
return $default;
123117
}
124118

125119
return $this->config->get($section, $key, $default);

library/Icinga/Web/Form/ConfigSectionForm.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ public function __construct()
6767
if ($this->shouldDelete()) {
6868
$this->handleDelete();
6969
$this->emit(static::ON_DELETE, [$this]);
70-
} elseif ($this->shouldRename()) {
71-
$oldName = $this->section;
72-
$this->handleRename();
73-
$this->emit(static::ON_RENAME, [
74-
$this,
75-
$oldName,
76-
$this->section,
77-
]);
7870
}
7971
});
8072
}
@@ -223,6 +215,14 @@ protected function handleDelete(): void
223215
*/
224216
protected function handleRename(): void
225217
{
218+
if (! $this->config) {
219+
throw new ProgrammingError('Config must be set before renaming a configuration section.');
220+
}
221+
222+
if ($this->section === null) {
223+
throw new ProgrammingError('Section must be set before renaming a configuration section.');
224+
}
225+
226226
$newName = $this->getPopulatedValue(static::NAME_ELEMENT_NAME);
227227
$section = $this->config->getSection($this->section);
228228
$this->config->removeSection($this->section);
@@ -322,7 +322,22 @@ protected function onSuccess(): void
322322
}
323323
}
324324

325+
$oldSection = $this->section;
326+
$isRename = $this->shouldRename();
327+
328+
if ($isRename) {
329+
$this->handleRename();
330+
}
331+
325332
parent::onSuccess();
333+
334+
if ($isRename) {
335+
$this->emit(static::ON_RENAME, [
336+
$this,
337+
$oldSection,
338+
$this->section,
339+
]);
340+
}
326341
}
327342

328343
/**

0 commit comments

Comments
 (0)