X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConfig%2FPreloadPConfigAdapter.php;h=ebccb018bce6a85eb0776fd525cff8bdadbb68f6;hb=8dc5b04be7cd9cb2eb77ed9824815efe27369bee;hp=af77598389af025268305f369b45f6dbc37f058f;hpb=850d9b4c0b595e00e5cd7ec40a2e8c0f0569738f;p=friendica.git diff --git a/src/Core/Config/PreloadPConfigAdapter.php b/src/Core/Config/PreloadPConfigAdapter.php index af77598389..ebccb018bc 100644 --- a/src/Core/Config/PreloadPConfigAdapter.php +++ b/src/Core/Config/PreloadPConfigAdapter.php @@ -2,11 +2,9 @@ namespace Friendica\Core\Config; -use dba; use Exception; -use Friendica\App; use Friendica\BaseObject; -use Friendica\Database\DBM; +use Friendica\Database\DBA; require_once 'include/dba.php'; @@ -15,7 +13,7 @@ require_once 'include/dba.php'; * * Minimizes the number of database queries to retrieve configuration values at the cost of memory. * - * @author Hypolite Petovan + * @author Hypolite Petovan */ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter { @@ -32,20 +30,28 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter return; } - $pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]); - while ($pconfig = dba::fetch($pconfigs)) { + if (empty($uid)) { + return; + } + + $pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]); + while ($pconfig = DBA::fetch($pconfigs)) { self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']); } - dba::close($pconfigs); + DBA::close($pconfigs); $this->config_loaded = true; } public function get($uid, $cat, $k, $default_value = null, $refresh = false) { + if (!$this->config_loaded) { + $this->load($uid, $cat); + } + if ($refresh) { - $config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]); - if (DBM::is_result($config)) { + $config = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]); + if (DBA::isResult($config)) { self::getApp()->setPConfigValue($uid, $cat, $k, $config['v']); } else { self::getApp()->deletePConfigValue($uid, $cat, $k); @@ -59,6 +65,9 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter public function set($uid, $cat, $k, $value) { + if (!$this->config_loaded) { + $this->load($uid, $cat); + } // We store our setting values as strings. // So we have to do the conversion here so that the compare below works. // The exception are array values. @@ -73,7 +82,7 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter // manage array value $dbvalue = is_array($value) ? serialize($value) : $value; - $result = dba::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true); + $result = DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true); if (!$result) { throw new Exception('Unable to store config value in [' . $uid . '][' . $cat . '][' . $k . ']'); } @@ -83,9 +92,13 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter public function delete($uid, $cat, $k) { + if (!$this->config_loaded) { + $this->load($uid, $cat); + } + self::getApp()->deletePConfigValue($uid, $cat, $k); - $result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]); + $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]); return $result; }