Assure that deleted cat/keys are working as expected
- A deleted cache-key would delete a merged cache-key as well - Deleting a key in the Model results in reloading the config to assure any value from underlying files
This commit is contained in:
@@ -71,6 +71,8 @@ class Config implements IManageConfigValues
|
||||
{
|
||||
try {
|
||||
$this->configFileManager->saveData($this->configCache);
|
||||
// reload after the save to possible reload default values of lower source-priorities again
|
||||
$this->reload();
|
||||
} catch (ConfigFileException $e) {
|
||||
throw new ConfigPersistenceException('Cannot save config', $e);
|
||||
}
|
||||
@@ -116,7 +118,7 @@ class Config implements IManageConfigValues
|
||||
/** {@inheritDoc} */
|
||||
public function delete(string $cat, string $key): bool
|
||||
{
|
||||
if ($this->configCache->delete($cat, $key, Cache::SOURCE_DATA)) {
|
||||
if ($this->configCache->delete($cat, $key)) {
|
||||
$this->save();
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -55,6 +55,11 @@ class Cache
|
||||
*/
|
||||
private $source = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $delConfig = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
@@ -232,6 +237,7 @@ class Cache
|
||||
if (isset($this->config[$cat][$key])) {
|
||||
unset($this->config[$cat][$key]);
|
||||
unset($this->source[$cat][$key]);
|
||||
$this->delConfig[$cat][$key] = true;
|
||||
if (count($this->config[$cat]) == 0) {
|
||||
unset($this->config[$cat]);
|
||||
unset($this->source[$cat]);
|
||||
@@ -313,6 +319,19 @@ class Cache
|
||||
}
|
||||
}
|
||||
|
||||
$delCategories = array_keys($cache->delConfig);
|
||||
|
||||
foreach ($delCategories as $category) {
|
||||
if (is_array($cache->delConfig[$category])) {
|
||||
$keys = array_keys($cache->delConfig[$category]);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
unset($newConfig[$category][$key]);
|
||||
unset($newSource[$category][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$newCache = new Cache();
|
||||
$newCache->config = $newConfig;
|
||||
$newCache->source = $newSource;
|
||||
|
||||
Reference in New Issue
Block a user