]> git.mxchange.org Git - friendica.git/blobdiff - include/Core/Config.php
Merge pull request #3044 from rabuzarus/20161224_-_update_perfect_scrollbar
[friendica.git] / include / Core / Config.php
index de371eb7f34592654034b70f4dac14984058477d..7b7045a9ee3ed2f3fe00989d97db6cba13e9959f 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 namespace Friendica\Core;
+
+use dbm;
+
 /**
  * @file include/Core/Config.php
  *
@@ -30,10 +33,10 @@ class Config {
         * @return void
         */
        public static function load($family) {
-               global $a;
+               $a = get_app();
 
                $r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s' ORDER BY `cat`, `k`, `id`", dbesc($family));
-               if (count($r)) {
+               if (dbm::is_result($r)) {
                        foreach ($r as $rr) {
                                $k = $rr['k'];
                                if ($family === 'config') {
@@ -72,7 +75,7 @@ class Config {
         */
        public static function get($family, $key, $default_value = null, $refresh = false) {
 
-               global $a;
+               $a = get_app();
 
                if (!$refresh) {
                        // Looking if the whole family isn't set
@@ -100,8 +103,7 @@ class Config {
                        $a->config[$family][$key] = $val;
 
                        return $val;
-               }
-               else {
+               } else {
                        $a->config[$family][$key] = '!<unset>!';
                }
                return $default_value;
@@ -124,37 +126,37 @@ class Config {
         * @return mixed Stored $value or false if the database update failed
         */
        public static function set($family, $key, $value) {
-               global $a;
+               $a = get_app();
+
+               $stored = self::get($family, $key);
+
+               if ($stored == $value) {
+                       return true;
+               }
 
                $a->config[$family][$key] = $value;
 
                // manage array value
-               $dbvalue = (is_array($value) ? serialize($value):$value);
+               $dbvalue = (is_array($value) ? serialize($value) : $value);
                $dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue);
 
-               // The "INSERT" command is very cost intense. It saves performance to do it this way.
-               $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1",
-                       dbesc($family),
-                       dbesc($key)
-               );
-
-               if (!$ret) {
+               if (is_null($stored)) {
                        $ret = q("INSERT INTO `config` (`cat`, `k`, `v`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
                                dbesc($family),
                                dbesc($key),
                                dbesc($dbvalue),
                                dbesc($dbvalue)
                        );
-               } elseif ($ret[0]['v'] != $dbvalue) {
+               } else {
                        $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
                                dbesc($dbvalue),
                                dbesc($family),
                                dbesc($key)
                        );
                }
-               if ($ret)
+               if ($ret) {
                        return $value;
-
+               }
                return $ret;
        }
 
@@ -172,9 +174,10 @@ class Config {
         */
        public static function delete($family, $key) {
 
-               global $a;
-               if (x($a->config[$family],$key))
+               $a = get_app();
+               if (x($a->config[$family],$key)) {
                        unset($a->config[$family][$key]);
+               }
                $ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'",
                        dbesc($family),
                        dbesc($key)