]> git.mxchange.org Git - friendica.git/commitdiff
Avoid duplicates with feeds and "remote self"
authorMichael <heluecht@pirati.ca>
Sat, 8 Apr 2017 08:12:14 +0000 (08:12 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 8 Apr 2017 08:12:14 +0000 (08:12 +0000)
include/feed.php
include/items.php

index 2959933703103d72f2ace8dce104c7995099bc80..2117676dbab6eb9cf34c4581e81ec0450df8df12 100644 (file)
@@ -200,7 +200,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
                if ($item["plink"] == "") {
                        $item["plink"] = $xpath->evaluate('rss:link/text()', $entry)->item(0)->nodeValue;
                }
-               $item["plink"] = original_url($item["plink"]);
 
                $item["uri"] = $xpath->evaluate('atom:id/text()', $entry)->item(0)->nodeValue;
 
@@ -210,12 +209,17 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
                if ($item["uri"] == "") {
                        $item["uri"] = $item["plink"];
                }
+
+               $orig_plink = $item["plink"];
+
+               $item["plink"] = original_url($item["plink"]);
+
                $item["parent-uri"] = $item["uri"];
 
                if (!$simulate) {
                        $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
                                intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
-                       if ($r) {
+                       if (dbm::is_result($r)) {
                                logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
                                continue;
                        }
@@ -340,6 +344,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
                        // Distributed items should have a well formatted URI.
                        // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
                        if ($notify) {
+                               $item['guid'] = uri_to_guid($orig_plink, $a->get_hostname());
                                unset($item['uri']);
                                unset($item['parent-uri']);
                        }
index c2b3d7d1f5c0c50038a628b10be7a2db0f05cd5c..f3885d21f91584f3108aef6c1b81f3443a81e2b9 100644 (file)
@@ -407,10 +407,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                // We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri.
                // In difference to the call to "uri_to_guid" several lines below we add the hash of our own host.
                // This is done because our host is the original creator of the post.
-               if (isset($arr['plink'])) {
-                       $arr['guid'] = uri_to_guid($arr['plink'], $a->get_hostname());
-               } elseif (isset($arr['uri'])) {
-                       $arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname());
+               if (!isset($arr['guid'])) {
+                       if (isset($arr['plink'])) {
+                               $arr['guid'] = uri_to_guid($arr['plink'], $a->get_hostname());
+                       } elseif (isset($arr['uri'])) {
+                               $arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname());
+                       }
                }
        }