protected $_dict;
/**
+ * List of dirty prefs.
+ *
+ * @var array
+ */
+ protected $_dirty = array();
+
+ /**
* Attempts to return a concrete instance based on $driver.
*
* @param string $driver Either a driver name, or the full class name to
{
// FIXME not updated yet - not removed from backend.
$scope = $this->_getPreferenceScope($pref);
- unset($this->_prefs[$pref]);
+ unset($this->_dirty[$scope][$pref], $this->_prefs[$pref]);
$this->_cache->clear($scope, $pref);
}
*/
public function setDirty($pref, $bool)
{
+ if ($bool) {
+ $this->_dirty[$this->_scope][$pref] = $this->_prefs[$pref];
+ } else {
+ unset($this->_dirty[$this->_scope][$pref]);
+ }
+
$this->_setMask($pref, $bool, self::DIRTY);
}
/* Perform a Horde-wide cleanup? */
if ($all) {
/* Destroy the contents of the preferences hash. */
- $this->_prefs = array();
+ $this->_dirty = $this->_prefs = array();
/* Destroy the contents of the preferences cache. */
$this->_cache->clear();
}
/**
- * Return all "dirty" preferences across all scopes.
- *
- * @return array The values for all dirty preferences, in a
- * multi-dimensional array of scope => pref name =>
- * pref values.
- */
- protected function _dirtyPrefs()
- {
- $dirty_prefs = array();
-
- foreach ($this->_scopes as $scope => $prefs) {
- foreach ($prefs as $pref_name => $pref) {
- if (isset($pref['m']) && ($pref['m'] & self::DIRTY)) {
- $dirty_prefs[$scope][$pref_name] = $pref;
- }
- }
- }
-
- return $dirty_prefs;
- }
-
- /**
* Populates the $_scopes hash with new entries and externally
* defined default values.
*
/**
* Stores preferences in the current session.
*
- * @return boolean True on success.
* @throws Horde_Prefs_Exception
*/
public function store()
{
- if (is_null($this->_dirname)) {
- return false;
- }
-
- // Get the list of preferences that have changed. If there are
- // none, no need to hit the backend.
- $dirty_prefs = $this->_dirtyPrefs();
- if (!$dirty_prefs) {
- return true;
+ if (is_null($this->_dirname) || empty($this->_dirty)) {
+ return;
}
// Read in all existing preferences, if any.
}
// Update all values from dirty scope
- foreach ($dirty_prefs as $scope => $prefs) {
+ foreach ($this->_dirty as $scope => $prefs) {
foreach ($prefs as $name => $pref) {
// Don't store locked preferences.
if (!($this->_scopes[$scope][$name]['m'] & self::LOCKED)) {
if ($this->_writeCache() == false) {
throw new Horde_Prefs_Exception(sprintf('Write of preferences to %s failed', $this->_filename));
}
-
- return true;
}
}
{
// Get the list of preferences that have changed. If there are
// none, no need to hit the backend.
- $dirty_prefs = $this->_dirtyPrefs();
- if (!$dirty_prefs) {
+ if (empty($this->_dirty)) {
return;
}
$this->_connect();
- foreach ($dirty_prefs as $scope => $prefs) {
+ foreach ($this->_dirty as $scope => $prefs) {
$updated = array();
foreach ($prefs as $name => $pref) {
{
// Get the list of preferences that have changed. If there are
// none, no need to hit the backend.
- $dirty_prefs = $this->_dirtyPrefs();
- if (!$dirty_prefs) {
+ if (empty($this->_dirty)) {
return;
}
- $dirty_scopes = array_keys($dirty_prefs);
$this->_connect();
// all of the values of a multi-value entry wholesale, we
// can't just pick out the dirty preferences; we must update
// every scope that has dirty preferences.
- foreach ($dirty_scopes as $scope) {
+ foreach (array_keys($this->_dirty) as $scope) {
$new_values = array();
foreach ($this->_scopes[$scope] as $name => $pref) {
// Don't store locked preferences.
}
// Clean the preferences since they were just saved.
- foreach ($dirty_prefs as $scope => $prefs) {
+ foreach ($this->_dirty as $scope => $prefs) {
foreach ($prefs as $name => $pref) {
$this->_scopes[$scope][$name]['m'] &= ~self::DIRTY;
}
{
// Get the list of preferences that have changed. If there are
// none, no need to hit the backend.
- $dirty_prefs = $this->_dirtyPrefs();
- if (!$dirty_prefs) {
+ if (empty($this->_dirty)) {
return;
}
- $dirty_scopes = array_keys($dirty_prefs);
$this->_connect();
// can't just pick out the dirty preferences; we must update
// every scope that has dirty preferences.
$new_values = array();
- foreach ($dirty_scopes as $scope) {
+ foreach (array_keys($this->_dirty) as $scope) {
foreach ($this->_scopes[$scope] as $name => $pref) {
// Don't store locked preferences.
if (!($pref['m'] & self::LOCKED)) {
}
// Clean the preferences since they were just saved.
- foreach ($dirty_prefs as $scope => $prefs) {
+ foreach ($this->_dirty as $scope => $prefs) {
foreach ($prefs as $name => $pref) {
$this->_scopes[$scope][$name]['m'] &= ~self::DIRTY;
}
*/
public function store()
{
- // Get the list of preferences that have changed. If there are
- // none, no need to hit the backend.
- if (!($dirty_prefs = $this->_dirtyPrefs())) {
- return;
- }
-
// For each preference, check for an existing table row and
// update it if it's there, or create a new one if it's not.
- foreach ($dirty_prefs as $scope => $prefs) {
+ foreach ($this->_dirty as $scope => $prefs) {
$updated = array();
foreach ($prefs as $name => $pref) {