diff options
author | M.Dent <dentm42@dm42.net> | 2018-10-29 23:04:13 -0400 |
---|---|---|
committer | M.Dent <dentm42@dm42.net> | 2018-10-29 23:04:13 -0400 |
commit | 0060f88c4599c5cda1c6d5a7f6eb345a496e382f (patch) | |
tree | 5939f63bb123ba71ed1c863267fb8cf00c74909b | |
parent | 1241e778f9073b5ba50d966eea20b28b9400339b (diff) | |
download | volse-hubzilla-0060f88c4599c5cda1c6d5a7f6eb345a496e382f.tar.gz volse-hubzilla-0060f88c4599c5cda1c6d5a7f6eb345a496e382f.tar.bz2 volse-hubzilla-0060f88c4599c5cda1c6d5a7f6eb345a496e382f.zip |
Add tracking of deleted pconfig variables
-rw-r--r-- | Zotlabs/Lib/PConfig.php | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/Zotlabs/Lib/PConfig.php b/Zotlabs/Lib/PConfig.php index 8bc5681f0..b9384cf6b 100644 --- a/Zotlabs/Lib/PConfig.php +++ b/Zotlabs/Lib/PConfig.php @@ -135,6 +135,16 @@ class PConfig { $updated = datetime_convert(); } + $hash = hash('sha256',$family.':'.$key); + + if (self::Get($uid, 'hz_delpconfig', $hash) !== false) { + if (Get($uid, 'hz_delpconfig', $hash) > $updated) { + logger('Refusing to update pconfig with outdated info (Item deleted more recently).', LOGGER_NORMAL, LOG_ERR); + return self::Get($uid,$family,$key); + } else { + self::Delete($uid,'hz_delpconfig',$hash); + } + } if(self::Get($uid, $family, $key) === false) { if(! array_key_exists($uid, \App::$config)) @@ -142,6 +152,7 @@ class PConfig { if(! array_key_exists($family, \App::$config[$uid])) \App::$config[$uid][$family] = array(); + $ret = q("INSERT INTO pconfig ( uid, cat, k, v, updated ) VALUES ( %d, '%s', '%s', '%s', '%s' ) ", intval($uid), dbesc($family), @@ -150,6 +161,14 @@ class PConfig { dbesc($updated) ); + // There is a possible race condition if another process happens + // to insert something after this thread has Loaded and now. We should + // at least make a note of it if it happens. + + if (!$ret) { + logger("Error: Insert to pconfig failed.",LOGGER_NORMAL, LOG_ERR); + } + \App::$config[$uid][$family]['pcfgud:'.$key] = $updated; } @@ -157,6 +176,12 @@ class PConfig { $new = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated); if ($new) { + + // @NOTE There is still a possible race condition under limited circumstances + // where a value will be updated by another thread with more current data than + // we have. At this point there is no easy way to test for it, so we update + // and hope for the best. + $ret = q("UPDATE pconfig SET v = '%s', updated = '%s' WHERE uid = %d and cat = '%s' AND k = '%s' ", dbesc($dbvalue), dbesc($updated), @@ -164,12 +189,16 @@ class PConfig { dbesc($family), dbesc($key) ); + + \App::$config[$uid][$family]['pcfgud:'.$key] = $updated; + } else { logger('Refusing to update pconfig with outdated info.', LOGGER_NORMAL, LOG_ERR); return self::Get($uid, $family, $key); } } + // keep a separate copy for all variables which were // set in the life of this page. We need this to // synchronise channel clones. @@ -223,11 +252,13 @@ class PConfig { $ret = false; - if(array_key_exists($uid,\App::$config) - && is_array(\App::$config['uid']) - && array_key_exists($family,\App::$config['uid']) - && array_key_exists($key, \App::$config[$uid][$family])) + if (isset(\App::$config[$uid][$family][$key])) { unset(\App::$config[$uid][$family][$key]); + } + + if (isset(\App::$config[$uid][$family]['pcfgud:'.$key])) { + unset(\App::$config[$uid][$family]['pcfgud:'.$key]); + } $ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'", intval($uid), @@ -235,6 +266,11 @@ class PConfig { dbesc($key) ); + if ($family != 'hz_delpconfig') { + $hash = hash('sha256',$family.':'.$key); + set_pconfig($uid,'hz_delpconfig',$hash,$updated); + } + // Synchronize delete with clones. if(! array_key_exists('transient', \App::$config[$uid])) |