]> git.mxchange.org Git - friendica.git/commitdiff
Ensure non-NULL values in $data array in Contact::updateAvatar
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 9 Mar 2020 15:12:33 +0000 (11:12 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 9 Mar 2020 15:13:09 +0000 (11:13 -0400)
- Throw Exception instead of returning false if contact doesn't exist
- Address https://github.com/friendica/friendica/issues/7998#issuecomment-596271239

src/Model/Contact.php

index 0e542316dbabbd0d1890fbda2339af5f6142d555..f60a362c57689ce22b3f14e88f6f98101db23736 100644 (file)
@@ -1913,17 +1913,23 @@ class Contact
         *
         * @return array Returns array of the different avatar sizes
         * @throws HTTPException\InternalServerErrorException
+        * @throws HTTPException\NotFoundException
         * @throws \ImagickException
         */
        public static function updateAvatar($avatar, $uid, $cid, $force = false)
        {
                $contact = DBA::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid, 'self' => false]);
                if (!DBA::isResult($contact)) {
-                       return false;
-               } else {
-                       $data = [$contact["photo"], $contact["thumb"], $contact["micro"]];
+                       Logger::error('Contact not found', ['cid' => $cid]);
+                       throw new HTTPException\NotFoundException('Contact not found');
                }
 
+               $data = [
+                       $contact['photo'] ?? '',
+                       $contact['thumb'] ?? '',
+                       $contact['micro'] ?? '',
+               ];
+
                foreach ($data as $image_uri) {
                        $image_rid = Photo::ridFromURI($image_uri);
                        if ($image_rid && !Photo::exists(['resource-id' => $image_rid, 'uid' => $uid])) {