From: Art4 Date: Mon, 18 Nov 2024 23:30:37 +0000 (+0000) Subject: fix errors in all models X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=92eff402af76eeaba6468dd76ae1a13fc473e188;p=friendica.git fix errors in all models --- diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 27bf3aedab..10534498ac 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -178,7 +178,7 @@ class APContact try { $curlResult = HTTPSignature::fetchRaw($url); - $failed = empty($curlResult) || empty($curlResult->getBodyString()) || + $failed = empty($curlResult->getBodyString()) || (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410)); if (!$failed) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index a561c00c02..e007afc2d8 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2364,6 +2364,8 @@ class Contact $cache_avatar = !DBA::exists('contact', ['nurl' => $contact['nurl'], 'self' => true]); } + $fields = []; + if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || $cache_avatar) { if (Avatar::deleteCache($contact)) { $force = true; @@ -2380,6 +2382,8 @@ class Contact Logger::debug('Use default avatar', ['id' => $cid, 'uid' => $uid]); } + $local_uid = 0; + // Use the data from the self account if (empty($fields)) { $local_uid = User::getIdForURL($contact['url']); @@ -2411,8 +2415,15 @@ class Contact if ($update) { $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true); if ($photos) { - $fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'blurhash' => $photos[3], 'avatar-date' => DateTimeFormat::utcNow()]; - $update = !empty($fields); + $fields = [ + 'avatar' => $avatar, + 'photo' => $photos[0], + 'thumb' => $photos[1], + 'micro' => $photos[2], + 'blurhash' => $photos[3], + 'avatar-date' => DateTimeFormat::utcNow(), + ]; + $update = true; Logger::debug('Created new cached avatars', ['id' => $cid, 'uid' => $uid, 'owner-uid' => $local_uid]); } else { $update = false; diff --git a/src/Model/Event.php b/src/Model/Event.php index 7c68588b43..210f601691 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -333,7 +333,7 @@ class Event $item['uri'] = $event['uri']; $item['uri-id'] = ItemURI::getIdByURI($event['uri']); $item['guid'] = $event['guid']; - $item['plink'] = $arr['plink'] ?? ''; + $item['plink'] = ''; $item['post-type'] = Item::PT_EVENT; $item['wall'] = $event['cid'] ? 0 : 1; $item['contact-id'] = $contact['id']; diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index e6bcf35068..b48818437c 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -128,7 +128,7 @@ class Engagement return ($ret && !$exists) ? $engagement['uri-id'] : 0; } - public static function getContentSize(array $item): int + public static function getContentSize(array $item): int { $body = ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body']; $body = BBCode::removeAttachment($body); @@ -318,6 +318,8 @@ class Engagement $result = Post::selectPosts(['author-addr', 'author-nick', 'author-contact-type'], ['thr-parent-id' => $uri_id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE, 'author-contact-type' => [Contact::TYPE_RELAY, Contact::TYPE_COMMUNITY]]); while ($reshare = Post::fetch($result)) { + $prefix = ''; + switch ($reshare['author-contact-type']) { case Contact::TYPE_RELAY: $prefix = ' application_'; diff --git a/src/Model/Post/Link.php b/src/Model/Post/Link.php index 021e8a84b7..d97d316b9c 100644 --- a/src/Model/Post/Link.php +++ b/src/Model/Post/Link.php @@ -113,9 +113,6 @@ class Link try { $curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]); - if (empty($curlResult) || !$curlResult->isSuccess()) { - return []; - } } catch (\Exception $exception) { Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]); return []; diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 8ed516f322..548cb3e24f 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -699,7 +699,7 @@ class Media if (preg_match_all("/\[url\](https?:.*?)\[\/url\]/ism", $body, $matches)) { foreach ($matches[1] as $url) { Logger::info('Got page url (link without description)', ['uri-id' => $uriid, 'url' => $url]); - $result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false, $network); + $result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false); if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA])) { self::revertHTMLType($uriid, $url, $fullbody); Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]); @@ -715,7 +715,7 @@ class Media if (preg_match_all("/\[url\=(https?:.*?)\].*?\[\/url\]/ism", $body, $matches)) { foreach ($matches[1] as $url) { Logger::info('Got page url (link with description)', ['uri-id' => $uriid, 'url' => $url]); - $result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false, $network); + $result = self::insert(['uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $url], false); if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA])) { self::revertHTMLType($uriid, $url, $fullbody); Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]);