Skip to content

Commit

Permalink
Improve preference changeset calculation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Johannes Meyer committed Jul 15, 2014
1 parent 333c95e commit c7c2ad3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
12 changes: 4 additions & 8 deletions library/Icinga/User/Preferences/Store/DbStore.php
Expand Up @@ -107,14 +107,10 @@ public function save(Preferences $preferences)
$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);
}
Expand Down
7 changes: 1 addition & 6 deletions library/Icinga/User/Preferences/Store/IniStore.php
Expand Up @@ -81,12 +81,7 @@ public function load()
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();
}
Expand Down

0 comments on commit c7c2ad3

Please sign in to comment.