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:
Philipp 2023-01-11 21:53:34 +01:00
parent fd882abd80
commit 11a8bd17e3
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
5 changed files with 65 additions and 42 deletions

View file

@ -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 {

View file

@ -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;