Fix that the ini writer produces invalid configuration files
fixes #6614
This commit is contained in:
parent
dc20973581
commit
9bec8e3c27
|
@ -177,29 +177,42 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
||||||
|
|
||||||
// Iterate over all properties in the old configuration file and search for deleted properties
|
// Iterate over all properties in the old configuration file and search for deleted properties
|
||||||
foreach ($oldconfig as $key => $value) {
|
foreach ($oldconfig as $key => $value) {
|
||||||
$nextParents = array_merge($parents, array($key));
|
if ($newconfig->get($key) === null) {
|
||||||
$newvalue = $newconfig->get($key);
|
$nextParents = array_merge($parents, array($key));
|
||||||
$keyIdentifier = empty($parents) ? array($key) : array_slice($nextParents, 1, null, true);
|
$keyIdentifier = empty($parents) ? array($key) : array_slice($nextParents, 1, null, true);
|
||||||
|
foreach ($this->getPropertyIdentifiers($value, $keyIdentifier) as $propertyIdentifier) {
|
||||||
if ($newvalue === null) {
|
$editor->reset($propertyIdentifier, $section);
|
||||||
if ($value instanceof Zend_Config) {
|
|
||||||
// The deleted value is a nested Zend_Config, handle it recursively
|
|
||||||
$this->diffConfigs($value, new Zend_Config(array()), $editor, $nextParents);
|
|
||||||
if ($section === null) {
|
|
||||||
$editor->removeSection($key);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// The deleted value is a plain value, use the editor to delete it
|
|
||||||
if (is_numeric($key)) {
|
|
||||||
$editor->resetArrayElement($keyIdentifier, $section);
|
|
||||||
} elseif (!empty($parents)) {
|
|
||||||
// Drop nested properties, fixes #5958
|
|
||||||
$editor->resetArrayElement($nextParents, $section);
|
|
||||||
} else {
|
|
||||||
$editor->reset($keyIdentifier, $section);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all possible combinations of property identifiers for the given value
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to return all combinations for
|
||||||
|
* @param array $key The root property identifier, if any
|
||||||
|
*
|
||||||
|
* @return array All property combinations that are possible
|
||||||
|
*
|
||||||
|
* @todo Cannot handle array properties yet (e.g. a.b[]='c')
|
||||||
|
*/
|
||||||
|
protected function getPropertyIdentifiers($value, array $key = null)
|
||||||
|
{
|
||||||
|
$combinations = array();
|
||||||
|
$rootProperty = $key !== null ? $key : array();
|
||||||
|
|
||||||
|
if ($value instanceof Zend_Config) {
|
||||||
|
foreach ($value as $subProperty => $subValue) {
|
||||||
|
$combinations = array_merge(
|
||||||
|
$combinations,
|
||||||
|
$this->getPropertyIdentifiers($subValue, array_merge($rootProperty, array($subProperty)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif (is_string($value)) {
|
||||||
|
$combinations[] = $rootProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $combinations;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue