]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Fix various Notices
[friendica.git] / src / Model / Contact.php
index 9e870d505486c0d3266aa3113467e43daf32bf72..51d162ae22181ce07673b87da3bd4d245c4e85f8 100644 (file)
@@ -676,7 +676,7 @@ class Contact
        public static function updateSelfFromUserID($uid, $update_avatar = false)
        {
                $fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'avatar', 'prvkey', 'pubkey',
-                       'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
+                       'xmpp', 'matrix', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
                        'photo', 'thumb', 'micro', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco', 'network'];
                $self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
                if (!DBA::isResult($self)) {
@@ -690,7 +690,7 @@ class Contact
                }
 
                $fields = ['name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
-                       'country-name', 'pub_keywords', 'xmpp', 'net-publish'];
+                       'country-name', 'pub_keywords', 'xmpp', 'matrix', 'net-publish'];
                $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
                if (!DBA::isResult($profile)) {
                        return false;
@@ -702,7 +702,7 @@ class Contact
                        'avatar-date' => $self['avatar-date'], 'location' => Profile::formatLocation($profile),
                        'about' => $profile['about'], 'keywords' => $profile['pub_keywords'],
                        'contact-type' => $user['account-type'], 'prvkey' => $user['prvkey'],
-                       'pubkey' => $user['pubkey'], 'xmpp' => $profile['xmpp'], 'network' => Protocol::DFRN];
+                       'pubkey' => $user['pubkey'], 'xmpp' => $profile['xmpp'], 'matrix' => $profile['matrix'], 'network' => Protocol::DFRN];
 
                // it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
                $fields['url'] = DI::baseUrl() . '/profile/' . $user['nickname'];
@@ -1929,11 +1929,6 @@ class Contact
         */
        private static function updateContact(int $id, int $uid, string $old_url, string $new_url, array $fields)
        {
-               if (Strings::normaliseLink($new_url) != Strings::normaliseLink($old_url)) {
-                       Logger::notice('New URL differs from old URL', ['old' => $old_url, 'new' => $new_url]);
-                       return;
-               }
-
                if (!DBA::update('contact', $fields, ['id' => $id])) {
                        Logger::info('Couldn\'t update contact.', ['id' => $id, 'fields' => $fields]);
                        return;
@@ -2064,11 +2059,11 @@ class Contact
                 */
 
                // These fields aren't updated by this routine:
-               // 'xmpp', 'sensitive'
+               // 'sensitive'
 
                $fields = ['uid', 'uri-id', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
                        'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
-                       'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item'];
+                       'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item', 'xmpp', 'matrix'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
                if (!DBA::isResult($contact)) {
                        return false;
@@ -2106,6 +2101,12 @@ class Contact
 
                $updated = DateTimeFormat::utcNow();
 
+               if (Strings::normaliseLink($contact['url']) != Strings::normaliseLink($ret['url'])) {
+                       Logger::notice('New URL differs from old URL', ['id' => $id, 'uid' => $uid, 'old' => $contact['url'], 'new' => $ret['url']]);
+                       self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated]);
+                       return false;
+               }
+
                // We must not try to update relay contacts via probe. They are no real contacts.
                // We check after the probing to be able to correct falsely detected contact types.
                if (($contact['contact-type'] == self::TYPE_RELAY) &&
@@ -2319,7 +2320,7 @@ class Contact
         * @throws HTTPException\NotFoundException
         * @throws \ImagickException
         */
-       public static function createFromProbe(int $uid, $url, $network = '')
+       public static function createFromProbeForUser(int $uid, $url, $network = '')
        {
                $result = ['cid' => -1, 'success' => false, 'message' => ''];
 
@@ -2580,7 +2581,7 @@ class Contact
        {
                $contact = self::getById($cid, ['url']);
 
-               $result = self::createFromProbe($uid, $contact['url']);
+               $result = self::createFromProbeForUser($uid, $contact['url']);
 
                return $result['cid'];
        }
@@ -2738,7 +2739,7 @@ class Contact
                                }
                        } elseif (DBA::isResult($user) && in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
                                if (($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) && ($network != Protocol::DIASPORA)) {
-                                       self::createFromProbe($importer['uid'], $url, $network);
+                                       self::createFromProbeForUser($importer['uid'], $url, $network);
                                }
 
                                $condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];
@@ -2756,12 +2757,14 @@ class Contact
                return null;
        }
 
-       public static function removeFollower($importer, $contact)
+       public static function removeFollower(array $contact)
        {
-               if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) {
+               if (!empty($contact['rel']) && (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING))) {
                        DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]);
-               } else {
+               } elseif (!empty($contact['id'])) {
                        self::remove($contact['id']);
+               } else {
+                       DI::logger()->info('Couldn\'t remove follower because of invalid contact array', ['contact' => $contact]);
                }
        }