]> git.mxchange.org Git - friendica.git/commitdiff
Handle rare case where contact doesn't exist in Model\Group::getIdsByContactId
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 25 Jul 2022 13:13:42 +0000 (09:13 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 25 Jul 2022 16:07:42 +0000 (12:07 -0400)
- Address https://github.com/friendica/friendica/issues/11632#issuecomment-1193953621

src/Model/Group.php

index 268680a165b79cd7e90e5ae96c190764c7a9af11..4dec84c3a3cb0ed7c826bbf5911f5f6ce6e586a0 100644 (file)
@@ -138,25 +138,29 @@ class Group
         */
        public static function getIdsByContactId(int $cid): array
        {
-               $return = [];
+               $contact = Contact::getById($cid, ['rel']);
+               if (!$contact) {
+                       return [];
+               }
+
+               $groupIds = [];
 
                $stmt = DBA::select('group_member', ['gid'], ['contact-id' => $cid]);
                while ($group = DBA::fetch($stmt)) {
-                       $return[] = $group['gid'];
+                       $groupIds[] = $group['gid'];
                }
                DBA::close($stmt);
 
                // Meta-groups
-               $contact = Contact::getById($cid, ['rel']);
                if ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND) {
-                       $return[] = self::FOLLOWERS;
+                       $groupIds[] = self::FOLLOWERS;
                }
 
                if ($contact['rel'] == Contact::FRIEND) {
-                       $return[] = self::MUTUALS;
+                       $groupIds[] = self::MUTUALS;
                }
 
-               return $return;
+               return $groupIds;
        }
 
        /**