diff options
author | M.Dent <dentm42@dm42.net> | 2018-10-28 17:23:31 -0400 |
---|---|---|
committer | M.Dent <dentm42@dm42.net> | 2018-10-28 17:23:31 -0400 |
commit | 3ab0ef1902a9ff1f33cf5540a866745dc98a11a9 (patch) | |
tree | 523ac2eeede1cb9c1ded36bbc1e58f5735d09a5a /Zotlabs/Lib/PConfig.php | |
parent | c7c35b8b5a64e44f01e7557a43d13e518dc62aa8 (diff) | |
download | volse-hubzilla-3ab0ef1902a9ff1f33cf5540a866745dc98a11a9.tar.gz volse-hubzilla-3ab0ef1902a9ff1f33cf5540a866745dc98a11a9.tar.bz2 volse-hubzilla-3ab0ef1902a9ff1f33cf5540a866745dc98a11a9.zip |
Add timestamp and associated logic to pconfig
Diffstat (limited to 'Zotlabs/Lib/PConfig.php')
-rw-r--r-- | Zotlabs/Lib/PConfig.php | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/Zotlabs/Lib/PConfig.php b/Zotlabs/Lib/PConfig.php index ec0792ce1..31c0ee87b 100644 --- a/Zotlabs/Lib/PConfig.php +++ b/Zotlabs/Lib/PConfig.php @@ -57,6 +57,7 @@ class PConfig { \App::$config[$uid][$c]['config_loaded'] = true; } \App::$config[$uid][$c][$k] = $rr['v']; + \App::$config[$uid][$c]['pcfgud:'.$k] = $rr['updated']; } } } @@ -113,7 +114,7 @@ class PConfig { * The value to store * @return mixed Stored $value or false */ - static public function Set($uid, $family, $key, $value) { + static public function Set($uid, $family, $key, $value, $updated=NULL) { // this catches subtle errors where this function has been called // with local_channel() when not logged in (which returns false) @@ -130,27 +131,43 @@ class PConfig { $dbvalue = ((is_array($value)) ? serialize($value) : $value); $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue); + if (! $updated) { + $updated = datetime_convert(); + } + + if(self::Get($uid, $family, $key) === false) { if(! array_key_exists($uid, \App::$config)) \App::$config[$uid] = array(); if(! array_key_exists($family, \App::$config[$uid])) \App::$config[$uid][$family] = array(); - $ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ", + $ret = q("INSERT INTO pconfig ( uid, cat, k, v, updated ) VALUES ( %d, '%s', '%s', '%s', '%s' ) ", intval($uid), dbesc($family), dbesc($key), - dbesc($dbvalue) + dbesc($dbvalue), + dbesc($updated) ); + + \App::$config[$uid][$family]['pcfgud:'.$key] = $updated; + } else { - - $ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'", - dbesc($dbvalue), - intval($uid), - dbesc($family), - dbesc($key) - ); + $new = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated); + + if ($new) { + $ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s' AND updated = '%s'", + dbesc($dbvalue), + intval($uid), + dbesc($family), + dbesc($key), + dbesc($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 @@ -163,7 +180,11 @@ class PConfig { \App::$config[$uid]['transient'][$family] = array(); \App::$config[$uid][$family][$key] = $value; - \App::$config[$uid]['transient'][$family][$key] = $value; + + if ($new) { + \App::$config[$uid]['transient'][$family][$key] = $value; + \App::$config[$uid]['transient'][$family]['pcfgud:'.$key] = $updated; + } if($ret) return $value; @@ -186,11 +207,20 @@ class PConfig { * The configuration key to delete * @return mixed */ - static public function Delete($uid, $family, $key) { + static public function Delete($uid, $family, $key, $updated = NULL) { if(is_null($uid) || $uid === false) return false; + $updated = ($updated) ? $updated : datetime_convert(); + + $newer = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated); + + if (! $newer) { + logger('Refusing to delete pconfig with outdated delete request.', LOGGER_NORMAL, LOG_ERR); + return false; + } + $ret = false; if(array_key_exists($uid,\App::$config) @@ -205,6 +235,17 @@ class PConfig { dbesc($key) ); + // Synchronize delete with clones. + + if(! array_key_exists('transient', \App::$config[$uid])) + \App::$config[$uid]['transient'] = array(); + if(! array_key_exists($family, \App::$config[$uid]['transient'])) + \App::$config[$uid]['transient'][$family] = array(); + + if ($new) { + \App::$config[$uid]['transient'][$family]['pcfgdel:'.$key] = $updated; + } + return $ret; } |