Add tracking of deleted pconfig variables
This commit is contained in:
parent
1241e778f9
commit
0060f88c45
@ -135,6 +135,16 @@ class PConfig {
|
|||||||
$updated = datetime_convert();
|
$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(self::Get($uid, $family, $key) === false) {
|
||||||
if(! array_key_exists($uid, \App::$config))
|
if(! array_key_exists($uid, \App::$config))
|
||||||
@ -142,6 +152,7 @@ class PConfig {
|
|||||||
if(! array_key_exists($family, \App::$config[$uid]))
|
if(! array_key_exists($family, \App::$config[$uid]))
|
||||||
\App::$config[$uid][$family] = array();
|
\App::$config[$uid][$family] = array();
|
||||||
|
|
||||||
|
|
||||||
$ret = q("INSERT INTO pconfig ( uid, cat, k, v, updated ) VALUES ( %d, '%s', '%s', '%s', '%s' ) ",
|
$ret = q("INSERT INTO pconfig ( uid, cat, k, v, updated ) VALUES ( %d, '%s', '%s', '%s', '%s' ) ",
|
||||||
intval($uid),
|
intval($uid),
|
||||||
dbesc($family),
|
dbesc($family),
|
||||||
@ -150,6 +161,14 @@ class PConfig {
|
|||||||
dbesc($updated)
|
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;
|
\App::$config[$uid][$family]['pcfgud:'.$key] = $updated;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -157,6 +176,12 @@ class PConfig {
|
|||||||
$new = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated);
|
$new = (\App::$config[$uid][$family]['pcfgud:'.$key] < $updated);
|
||||||
|
|
||||||
if ($new) {
|
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' ",
|
$ret = q("UPDATE pconfig SET v = '%s', updated = '%s' WHERE uid = %d and cat = '%s' AND k = '%s' ",
|
||||||
dbesc($dbvalue),
|
dbesc($dbvalue),
|
||||||
dbesc($updated),
|
dbesc($updated),
|
||||||
@ -164,12 +189,16 @@ class PConfig {
|
|||||||
dbesc($family),
|
dbesc($family),
|
||||||
dbesc($key)
|
dbesc($key)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
\App::$config[$uid][$family]['pcfgud:'.$key] = $updated;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger('Refusing to update pconfig with outdated info.', LOGGER_NORMAL, LOG_ERR);
|
logger('Refusing to update pconfig with outdated info.', LOGGER_NORMAL, LOG_ERR);
|
||||||
return self::Get($uid, $family, $key);
|
return self::Get($uid, $family, $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// keep a separate copy for all variables which were
|
// keep a separate copy for all variables which were
|
||||||
// set in the life of this page. We need this to
|
// set in the life of this page. We need this to
|
||||||
// synchronise channel clones.
|
// synchronise channel clones.
|
||||||
@ -223,11 +252,13 @@ class PConfig {
|
|||||||
|
|
||||||
$ret = false;
|
$ret = false;
|
||||||
|
|
||||||
if(array_key_exists($uid,\App::$config)
|
if (isset(\App::$config[$uid][$family][$key])) {
|
||||||
&& is_array(\App::$config['uid'])
|
|
||||||
&& array_key_exists($family,\App::$config['uid'])
|
|
||||||
&& array_key_exists($key, \App::$config[$uid][$family]))
|
|
||||||
unset(\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'",
|
$ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'",
|
||||||
intval($uid),
|
intval($uid),
|
||||||
@ -235,6 +266,11 @@ class PConfig {
|
|||||||
dbesc($key)
|
dbesc($key)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($family != 'hz_delpconfig') {
|
||||||
|
$hash = hash('sha256',$family.':'.$key);
|
||||||
|
set_pconfig($uid,'hz_delpconfig',$hash,$updated);
|
||||||
|
}
|
||||||
|
|
||||||
// Synchronize delete with clones.
|
// Synchronize delete with clones.
|
||||||
|
|
||||||
if(! array_key_exists('transient', \App::$config[$uid]))
|
if(! array_key_exists('transient', \App::$config[$uid]))
|
||||||
|
Reference in New Issue
Block a user