Improve preference changeset calculation
The calculation is still subject to the concrete writer implementation as its parent Icinga\User\Preferences\PreferencesStore is only an abstraction layer without any knowledge how the data is actually stored so it is not able to determine how to handle differences. fixes #6220
This commit is contained in:
parent
333c95ef6d
commit
c7c2ad3790
|
@ -107,14 +107,10 @@ class DbStore extends PreferencesStore
|
|||
$this->insert($toBeInserted);
|
||||
}
|
||||
|
||||
$current = $this->preferences;
|
||||
$toBeUpdated = array();
|
||||
foreach (array_filter(
|
||||
array_keys(array_intersect_key($preferences, $this->preferences)),
|
||||
function ($k) use ($current, $preferences) { return $current[$k] == $preferences[$k] ? false : true; }
|
||||
) as $key) {
|
||||
$toBeUpdated[$key] = $preferences[$key];
|
||||
}
|
||||
$toBeUpdated = array_intersect_key(
|
||||
array_diff_assoc($preferences, $this->preferences),
|
||||
array_diff_assoc($this->preferences, $preferences)
|
||||
);
|
||||
if (!empty($toBeUpdated)) {
|
||||
$this->update($toBeUpdated);
|
||||
}
|
||||
|
|
|
@ -81,12 +81,7 @@ class IniStore extends PreferencesStore
|
|||
public function save(Preferences $preferences)
|
||||
{
|
||||
$preferences = $preferences->toArray();
|
||||
$this->update(
|
||||
array_merge(
|
||||
array_diff_key($preferences, $this->preferences),
|
||||
array_intersect_key($preferences, $this->preferences)
|
||||
)
|
||||
);
|
||||
$this->update(array_diff_assoc($preferences, $this->preferences));
|
||||
$this->delete(array_keys(array_diff_key($this->preferences, $preferences)));
|
||||
$this->write();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue