]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/JITPConfigAdapter.php
Update "mrpetovan" email address
[friendica.git] / src / Core / Config / JITPConfigAdapter.php
index 27f2ed86223f0ecdac9a4a985bcc872de65430b8..512004b50835199f0cd15ad4164046ef47239a7f 100644 (file)
@@ -1,18 +1,17 @@
 <?php
 namespace Friendica\Core\Config;
 
-use dba;
 use Friendica\BaseObject;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
 
 require_once 'include/dba.php';
 
 /**
- * JustInTime PConfigAdapter
+ * JustInTime User Configuration Adapter
  *
  * Default PConfig Adapter. Provides the best performance for pages loading few configuration variables.
  *
- * @author Hypolite Petovan <mrpetovan@gmail.com>
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
  */
 class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
 {
@@ -22,18 +21,20 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
        {
                $a = self::getApp();
 
-               $pconfigs = dba::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]);
-               if (DBM::is_result($pconfigs)) {
-                       while ($pconfig = dba::fetch($pconfigs)) {
+               $pconfigs = DBA::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]);
+               if (DBA::isResult($pconfigs)) {
+                       while ($pconfig = DBA::fetch($pconfigs)) {
                                $k = $pconfig['k'];
-                               $a->config[$uid][$cat][$k] = $pconfig['v'];
+
+                               self::getApp()->setPConfigValue($uid, $cat, $k, $pconfig['v']);
+
                                $this->in_db[$uid][$cat][$k] = true;
                        }
                } else if ($cat != 'config') {
                        // Negative caching
                        $a->config[$uid][$cat] = "!<unset>!";
                }
-               dba::close($pconfigs);
+               DBA::close($pconfigs);
        }
 
        public function get($uid, $cat, $k, $default_value = null, $refresh = false)
@@ -56,15 +57,18 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
                        }
                }
 
-               $pconfig = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
-               if (DBM::is_result($pconfig)) {
+               $pconfig = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
+               if (DBA::isResult($pconfig)) {
                        $val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
-                       $a->config[$uid][$cat][$k] = $val;
+
+                       self::getApp()->setPConfigValue($uid, $cat, $k, $val);
+
                        $this->in_db[$uid][$cat][$k] = true;
 
                        return $val;
                } else {
-                       $a->config[$uid][$cat][$k] = '!<unset>!';
+                       self::getApp()->setPConfigValue($uid, $cat, $k, '!<unset>!');
+
                        $this->in_db[$uid][$cat][$k] = false;
 
                        return $default_value;
@@ -73,8 +77,6 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
 
        public function set($uid, $cat, $k, $value)
        {
-               $a = self::getApp();
-
                // We store our setting values in a string variable.
                // So we have to do the conversion here so that the compare below works.
                // The exception are array values.
@@ -86,16 +88,15 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
                        return true;
                }
 
-               $a->config[$uid][$cat][$k] = $dbvalue;
+               self::getApp()->setPConfigValue($uid, $cat, $k, $value);
 
                // manage array value
                $dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
 
-               $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) {
                        $this->in_db[$uid][$cat][$k] = true;
-                       return $value;
                }
 
                return $result;
@@ -103,14 +104,13 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
 
        public function delete($uid, $cat, $k)
        {
-               $a = self::getApp();
+               self::getApp()->deletePConfigValue($uid, $cat, $k);
 
-               if (!empty($a->config[$uid][$cat][$k])) {
-                       unset($a->config[$uid][$cat][$k]);
+               if (!empty($this->in_db[$uid][$cat][$k])) {
                        unset($this->in_db[$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;
        }