diff --git a/src/Core/Config.php b/src/Core/Config.php index d454de3921..c046153133 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -1,6 +1,7 @@ config[$k] = $rr['v']; - } else { - $a->config[$family][$k] = $rr['v']; - self::$cache[$family][$k] = $rr['v']; - self::$in_db[$family][$k] = true; - } + $r = dba::select('config', array('v', 'k'), array('cat' => $family), array("order" => array("cat", "k"))); + while ($rr = dba::fetch($r)) { + $k = $rr['k']; + if ($family === 'config') { + $a->config[$k] = $rr['v']; + } else { + $a->config[$family][$k] = $rr['v']; + self::$cache[$family][$k] = $rr['v']; + self::$in_db[$family][$k] = true; } } } @@ -98,13 +97,11 @@ class Config { } } - $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s'", - dbesc($family), - dbesc($key) - ); + $ret = dba::select('config', array('v'), array('cat' => $family, 'k' => $key), + array("order" => array("cat", "k"), 'limit' => 1)); if (dbm::is_result($ret)) { // manage array value - $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v']) ? unserialize($ret[0]['v']) : $ret[0]['v']); + $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']); // Assign the value from the database to the cache self::$cache[$family][$key] = $val; @@ -206,11 +203,8 @@ class Config { unset(self::$cache[$family][$key]); unset(self::$in_db[$family][$key]); } - $ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'", - dbesc($family), - dbesc($key) - ); + $ret = dba::delete('config', array('cat' => $family, 'k' => $key)); return $ret; } } diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index 2cfcfc235a..6408b56ff6 100644 --- a/src/Core/PConfig.php +++ b/src/Core/PConfig.php @@ -1,6 +1,7 @@ $family, 'uid' => $uid), + array("order" => array('uid', 'cat', 'k'))); if (dbm::is_result($r)) { - foreach ($r as $rr) { + while ($rr = dba::fetch($r)) { $k = $rr['k']; $a->config[$uid][$family][$k] = $rr['v']; self::$in_db[$uid][$family][$k] = true; @@ -89,14 +89,10 @@ class PConfig { } } - $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1", - intval($uid), - dbesc($family), - dbesc($key) - ); - - if (count($ret)) { - $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); + $ret = dba::select('pconfig', array('v'), array('uid' => $uid, 'cat' => $family, 'k' => $key), + array("order" => array('uid', 'cat', 'k'), 'limit' => 1)); + if (dbm::is_result($ret)) { + $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v']) ? unserialize($ret[0]['v']) : $ret[0]['v']); $a->config[$uid][$family][$key] = $val; self::$in_db[$uid][$family][$key] = true; @@ -193,11 +189,7 @@ class PConfig { unset(self::$in_db[$uid][$family][$key]); } - $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'", - intval($uid), - dbesc($family), - dbesc($key) - ); + $ret = dba::delete('pconfig', array('uid' => $uid, 'cat' => $family, 'k' => $key)); return $ret; }