]> git.mxchange.org Git - friendica.git/commitdiff
Fix Issue #2816
authorHypolite Petovan <ben.lort@gmail.com>
Sun, 2 Oct 2016 01:40:41 +0000 (21:40 -0400)
committerHypolite Petovan <ben.lort@gmail.com>
Sun, 2 Oct 2016 01:40:41 +0000 (21:40 -0400)
- Change (P)Config::set to use INSERT >>> ON DUPLICATE KEY UPDATE
- Add DB update

include/Core/Config.php
include/Core/PConfig.php
update.php

index 5703558cf336f93103b53659d3e5598286d7daf7..e5515efafc43b75ff600069c1360c57d0af17531 100644 (file)
@@ -126,37 +126,19 @@ class Config {
        public static function set($family,$key,$value) {
                global $a;
 
-               // If $a->config[$family] has been previously set to '!<unset>!', then
-               // $a->config[$family][$key] will evaluate to $a->config[$family][0], and
-               // $a->config[$family][$key] = $value will be equivalent to
-               // $a->config[$family][0] = $value[0] (this causes infuriating bugs),
-               // so unset the family before assigning a value to a family's key
-               if($a->config[$family] === '!<unset>!')
-                       unset($a->config[$family]);
+               $a->config[$family][$key] = $value;
 
                // manage array value
                $dbvalue = (is_array($value)?serialize($value):$value);
                $dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue);
-               if(is_null(self::get($family,$key,null,true))) {
-                       $a->config[$family][$key] = $value;
-                       $ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
-                               dbesc($family),
-                               dbesc($key),
-                               dbesc($dbvalue)
-                       );
-                       if($ret)
-                               return $value;
-                       return $ret;
-               }
 
-               $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
-                       dbesc($dbvalue),
+               $ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' )
+ON DUPLICATE KEY UPDATE `v` = '%s'",
                        dbesc($family),
-                       dbesc($key)
+                       dbesc($key),
+                       dbesc($dbvalue),
+                       dbesc($dbvalue)
                );
-
-               $a->config[$family][$key] = $value;
-
                if($ret)
                        return $value;
                return $ret;
index 2bc08667a7f2f431e72686f32333971dd8e8a1bf..082f1c05c2f85d3097f2daf9655987611631d476 100644 (file)
@@ -126,27 +126,16 @@ class PConfig {
                // manage array value
                $dbvalue = (is_array($value)?serialize($value):$value);
 
-               if(is_null(self::get($uid,$family,$key,null, true))) {
-                       $a->config[$uid][$family][$key] = $value;
-                       $ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' ) ",
-                               intval($uid),
-                               dbesc($family),
-                               dbesc($key),
-                               dbesc($dbvalue)
-                       );
-                       if($ret)
-                               return $value;
-                       return $ret;
-               }
-               $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
-                       dbesc($dbvalue),
+               $a->config[$uid][$family][$key] = $value;
+
+               $ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' )
+ON DUPLICATE KEY UPDATE `v` = '%s'",
                        intval($uid),
                        dbesc($family),
-                       dbesc($key)
+                       dbesc($key),
+                       dbesc($dbvalue),
+                       dbesc($dbvalue)
                );
-
-               $a->config[$uid][$family][$key] = $value;
-
                if($ret)
                        return $value;
                return $ret;
index 31f7852a2f12b5c069ad63b1b903fdb7cb9e9046..55db8bca9c69b97b6137b1d6a49ff69e8a48c1a8 100644 (file)
@@ -1677,7 +1677,7 @@ function update_1190() {
                        $idx = array_search($plugin, $plugins_arr);
                        if ($idx !== false){
                                unset($plugins_arr[$idx]);
-                               //delete forumlist manually from addon and hook table 
+                               //delete forumlist manually from addon and hook table
                                // since uninstall_plugin() don't work here
                                q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
                                q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
@@ -1728,3 +1728,13 @@ function update_1202() {
        $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
                dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP));
 }
+
+function update_1210() {
+       // Convert config indexes to unique, old_alter_table=1 removes duplicates on ALTER IGNORE
+       $r = q("SET session old_alter_table=1;");
+       $r = q("ALTER TABLE config DROP INDEX cat_k");
+       $r = q("ALTER IGNORE TABLE config ADD UNIQUE INDEX cat_k (cat, k)");
+
+       $r = q("ALTER TABLE pconfig DROP INDEX uid_cat_k");
+       $r = q("ALTER IGNORE TABLE pconfig ADD UNIQUE INDEX uid_cat_k (uid, cat, k)");
+}
\ No newline at end of file