]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge pull request #8117 from annando/inbox
[friendica.git] / src / Model / Contact.php
index 0262a4a9fddb581cb06b2d09a9abf04364a643c8..e6c00b1e3c6e1fa518d6cb86a154d55153f8edef 100644 (file)
@@ -269,29 +269,37 @@ class Contact
         * @brief Get the basepath for a given contact link
         *
         * @param string $url The contact link
+        * @param boolean $dont_update Don't update the contact
         *
         * @return string basepath
-        * @return boolean $dont_update Don't update the contact
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
        public static function getBasepath($url, $dont_update = false)
        {
-               $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
+               $contact = DBA::selectFirst('contact', ['id', 'baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
+               if (!DBA::isResult($contact)) {
+                       return '';
+               }
+
                if (!empty($contact['baseurl'])) {
                        return $contact['baseurl'];
                } elseif ($dont_update) {
                        return '';
                }
 
-               self::updateFromProbeByURL($url, true);
+               // Update the existing contact
+               self::updateFromProbe($contact['id'], '', true);
 
-               $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
-               if (!empty($contact['baseurl'])) {
-                       return $contact['baseurl'];
+               // And fetch the result
+               $contact = DBA::selectFirst('contact', ['baseurl'], ['id' => $contact['id']]);
+               if (empty($contact['baseurl'])) {
+                       Logger::info('No baseurl for contact', ['url' => $url]);
+                       return '';
                }
 
-               return '';
+               Logger::info('Found baseurl for contact', ['url' => $url, 'baseurl' => $contact['baseurl']]);
+               return $contact['baseurl'];
        }
 
        /**
@@ -1888,6 +1896,14 @@ class Contact
                        $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])) {
+                               Logger::info('Regenerating avatar', ['contact uid' => $uid, 'cid' => $cid, 'missing photo' => $image_rid, 'avatar' => $contact['avatar']]);
+                               $force = true;
+                       }
+               }
+
                if (($contact["avatar"] != $avatar) || $force) {
                        $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
 
@@ -2212,7 +2228,7 @@ class Contact
        {
                $result = ['cid' => -1, 'success' => false, 'message' => ''];
 
-               $a = \get_app();
+               $a = DI::app();
 
                // remove ajax junk, e.g. Twitter
                $url = str_replace('/#!/', '/', $url);
@@ -2674,26 +2690,23 @@ class Contact
         * Remove the unavailable contact ids from the provided list
         *
         * @param array $contact_ids Contact id list
+        * @return array
         * @throws \Exception
         */
-       public static function pruneUnavailable(array &$contact_ids)
+       public static function pruneUnavailable(array $contact_ids)
        {
                if (empty($contact_ids)) {
-                       return;
-               }
-
-               $str = DBA::escape(implode(',', $contact_ids));
-
-               $stmt = DBA::p("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0");
-
-               $return = [];
-               while($contact = DBA::fetch($stmt)) {
-                       $return[] = $contact['id'];
+                       return [];
                }
 
-               DBA::close($stmt);
+               $contacts = Contact::selectToArray(['id'], [
+                       'id'      => $contact_ids,
+                       'blocked' => false,
+                       'pending' => false,
+                       'archive' => false,
+               ]);
 
-               $contact_ids = $return;
+               return array_column($contacts, 'id');
        }
 
        /**