]> git.mxchange.org Git - friendica.git/commitdiff
Issue 4997: Avoid database duplicates
authorMichael <heluecht@pirati.ca>
Thu, 10 May 2018 12:49:28 +0000 (12:49 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 10 May 2018 12:49:28 +0000 (12:49 +0000)
src/Protocol/Diaspora.php
src/Protocol/PortableContact.php

index 981abb0831defaec2816419afe5ec16b307cbc7b..08ce315281716dab523533d37ea9c9bddafff918 100644 (file)
@@ -920,7 +920,7 @@ class Diaspora
                        // Note that Friendica contacts will return a "Diaspora person"
                        // if Diaspora connectivity is enabled on their server
                        if ($r && ($r["network"] === NETWORK_DIASPORA)) {
-                               self::addFContact($r, $update);
+                               self::updateFContact($r);
 
                                // Fetch the updated or added contact
                                $person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
@@ -936,70 +936,21 @@ class Diaspora
        /**
         * @brief Updates the fcontact table
         *
-        * @param array $arr    The fcontact data
-        * @param bool  $update Update or insert?
-        *
-        * @return string The id of the fcontact entry
+        * @param array $arr The fcontact data
         */
-       private static function addFContact($arr, $update = false)
+       private static function updateFContact($arr)
        {
-               if ($update) {
-                       $r = q(
-                               "UPDATE `fcontact` SET
-                                       `name` = '%s',
-                                       `photo` = '%s',
-                                       `request` = '%s',
-                                       `nick` = '%s',
-                                       `addr` = '%s',
-                                       `guid` = '%s',
-                                       `batch` = '%s',
-                                       `notify` = '%s',
-                                       `poll` = '%s',
-                                       `confirm` = '%s',
-                                       `alias` = '%s',
-                                       `pubkey` = '%s',
-                                       `updated` = '%s'
-                               WHERE `url` = '%s' AND `network` = '%s'",
-                               dbesc($arr["name"]),
-                               dbesc($arr["photo"]),
-                               dbesc($arr["request"]),
-                               dbesc($arr["nick"]),
-                               dbesc(strtolower($arr["addr"])),
-                               dbesc($arr["guid"]),
-                               dbesc($arr["batch"]),
-                               dbesc($arr["notify"]),
-                               dbesc($arr["poll"]),
-                               dbesc($arr["confirm"]),
-                               dbesc($arr["alias"]),
-                               dbesc($arr["pubkey"]),
-                               dbesc(DateTimeFormat::utcNow()),
-                               dbesc($arr["url"]),
-                               dbesc($arr["network"])
-                       );
-               } else {
-                       $r = q(
-                               "INSERT INTO `fcontact` (`url`,`name`,`photo`,`request`,`nick`,`addr`, `guid`,
-                                       `batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated`)
-                               VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
-                               dbesc($arr["url"]),
-                               dbesc($arr["name"]),
-                               dbesc($arr["photo"]),
-                               dbesc($arr["request"]),
-                               dbesc($arr["nick"]),
-                               dbesc($arr["addr"]),
-                               dbesc($arr["guid"]),
-                               dbesc($arr["batch"]),
-                               dbesc($arr["notify"]),
-                               dbesc($arr["poll"]),
-                               dbesc($arr["confirm"]),
-                               dbesc($arr["network"]),
-                               dbesc($arr["alias"]),
-                               dbesc($arr["pubkey"]),
-                               dbesc(DateTimeFormat::utcNow())
-                       );
-               }
+               $fields = ['name' => $arr["name"], 'photo' => $arr["photo"],
+                       'request' => $arr["request"], 'nick' => $arr["nick"],
+                       'addr' => strtolower($arr["addr"]), 'guid' => $arr["guid"],
+                       'batch' => $arr["batch"], 'notify' => $arr["notify"],
+                       'poll' => $arr["poll"], 'confirm' => $arr["confirm"],
+                       'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"],
+                       'updated' => DateTimeFormat::utcNow()];
+
+               $condition = ['url' => $arr["url"], 'network' => $arr["network"]];
 
-               return $r;
+               dba::update('fcontact', $fields, $condition, true);
        }
 
        /**
index d737f4d5afeb6ed4076510a9442b18cf1cace549..5a4436e372502e00dc0aacaa5e85cd476ad069d5 100644 (file)
@@ -1427,7 +1427,7 @@ class PortableContact
                        }
 
                        foreach ($tags as $tag) {
-                               dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag]);
+                               dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag], true);
                        }
                }