]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/APContact.php
Merge pull request #9146 from tobiasd/2020.09-CHANGELOG
[friendica.git] / src / Model / APContact.php
index 68bd80f037b70068c319c936c96c57641f4161fd..d31aa5d3727f4eecebdbb6d7e9f0841b37d310b8 100644 (file)
@@ -24,15 +24,13 @@ namespace Friendica\Model;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
-use Friendica\DI;
 use Friendica\Network\Probe;
 use Friendica\Protocol\ActivityNamespace;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\Crypto;
-use Friendica\Util\Network;
-use Friendica\Util\JsonLD;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Strings;
+use Friendica\Util\JsonLD;
+use Friendica\Util\Network;
 
 class APContact
 {
@@ -304,6 +302,10 @@ class APContact
                        $apcontact['baseurl'] = null;
                }
 
+               if (empty($apcontact['subscribe'])) {
+                       $apcontact['subscribe'] = null;
+               }               
+
                if (!empty($apcontact['baseurl']) && empty($fetched_contact['gsid'])) {
                        $apcontact['gsid'] = GServer::getID($apcontact['baseurl']);
                } elseif (!empty($fetched_contact['gsid'])) {
@@ -318,13 +320,18 @@ class APContact
 
                $apcontact['updated'] = DateTimeFormat::utcNow();
 
-               DBA::update('apcontact', $apcontact, ['url' => $url], true);
-
                // We delete the old entry when the URL is changed
-               if (($url != $apcontact['url']) && DBA::exists('apcontact', ['url' => $url]) && DBA::exists('apcontact', ['url' => $apcontact['url']])) {
+               if ($url != $apcontact['url']) {
+                       Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]);
                        DBA::delete('apcontact', ['url' => $url]);
                }
 
+               if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
+                       DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
+               } else {
+                       DBA::replace('apcontact', $apcontact);
+               }
+
                Logger::info('Updated profile', ['url' => $url]);
 
                return $apcontact;
@@ -347,7 +354,7 @@ class APContact
 
                if (!DBA::exists('inbox-status', ['url' => $url])) {
                        $fields = array_merge($fields, ['url' => $url, 'created' => $now]);
-                       DBA::insert('inbox-status', $fields);
+                       DBA::replace('inbox-status', $fields);
                } else {
                        DBA::update('inbox-status', $fields, ['url' => $url]);
                }