]> git.mxchange.org Git - friendica.git/commitdiff
Hybrid mode for non resolvable contacts
authorMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 16:00:06 +0000 (16:00 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 16:00:06 +0000 (16:00 +0000)
src/Model/Tag.php
static/dbstructure.config.php

index 7627872590ed08b52cc7181a15d67b15d21455c6..6de872a9e58f3438a9e4285a1c25b8b076efce6d 100644 (file)
@@ -23,7 +23,7 @@ namespace Friendica\Model;
 
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
-use Friendica\Model\Contact;
+use Friendica\Util\Strings;
 
 /**
  * Class Tag
@@ -69,6 +69,9 @@ class Tag
                        return;
                }
 
+               $cid = 0;
+               $tagid = 0;
+
                if (in_array($type, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION])) {
                        if (empty($url)) {
                                // No mention without a contact url
@@ -77,13 +80,18 @@ class Tag
 
                        Logger::info('Get ID for contact', ['url' => $url]);
 
-                       $cid = Contact::getIdForURL($url, 0, true);
-                       if (empty($cid)) {
-                               Logger::error('No contact found', ['url' => $url]);
-                               return;
+                       $condition = ['nurl' => Strings::normaliseLink($url), 'uid' => 0, 'deleted' => false];
+                       $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
+                       if (DBA::isResult($contact)) {
+                               $cid = $contact['id'];
+                       } else {
+                               // The contact wasn't found in the system (most likely some dead account)
+                               // We ensure that we only store a single entry by overwriting the previous name
+                               DBA::update('tag', ['name' => substr($name, 0, 96)], ['url' => $url]);
                        }
-                       $tagid = 0;
-               } else {
+               }
+
+               if (empty($cid)) {
                        $fields = ['name' => substr($name, 0, 96)];
 
                        if (!empty($url) && ($url != $name)) {
@@ -102,7 +110,6 @@ class Tag
                                Logger::error('No tag id created', $fields);
                                return;
                        }
-                       $cid = 0;
                }
 
                DBA::insert('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid], true);
index e0c3c5b70e154627d71bbfca58ddcc299585b681..d6bd418f8abe5bb0265cf30e4975fb3bd1bb8af4 100755 (executable)
@@ -1301,7 +1301,8 @@ return [
                ],
                "indexes" => [
                        "PRIMARY" => ["id"],
-                       "type_name_url" => ["UNIQUE", "name", "url"]
+                       "type_name_url" => ["UNIQUE", "name", "url"],
+                       "url" => ["url"]
                ]
        ],
        "post-tag" => [