fix errors in all models

This commit is contained in:
Art4 2024-11-18 23:30:37 +00:00
parent c61ae5da42
commit 92eff402af
6 changed files with 20 additions and 10 deletions

View file

@ -178,7 +178,7 @@ class APContact
try { try {
$curlResult = HTTPSignature::fetchRaw($url); $curlResult = HTTPSignature::fetchRaw($url);
$failed = empty($curlResult) || empty($curlResult->getBodyString()) || $failed = empty($curlResult->getBodyString()) ||
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410)); (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
if (!$failed) { if (!$failed) {

View file

@ -2364,6 +2364,8 @@ class Contact
$cache_avatar = !DBA::exists('contact', ['nurl' => $contact['nurl'], 'self' => true]); $cache_avatar = !DBA::exists('contact', ['nurl' => $contact['nurl'], 'self' => true]);
} }
$fields = [];
if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || $cache_avatar) { if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || $cache_avatar) {
if (Avatar::deleteCache($contact)) { if (Avatar::deleteCache($contact)) {
$force = true; $force = true;
@ -2380,6 +2382,8 @@ class Contact
Logger::debug('Use default avatar', ['id' => $cid, 'uid' => $uid]); Logger::debug('Use default avatar', ['id' => $cid, 'uid' => $uid]);
} }
$local_uid = 0;
// Use the data from the self account // Use the data from the self account
if (empty($fields)) { if (empty($fields)) {
$local_uid = User::getIdForURL($contact['url']); $local_uid = User::getIdForURL($contact['url']);
@ -2411,8 +2415,15 @@ class Contact
if ($update) { if ($update) {
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true); $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
if ($photos) { if ($photos) {
$fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'blurhash' => $photos[3], 'avatar-date' => DateTimeFormat::utcNow()]; $fields = [
$update = !empty($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]); Logger::debug('Created new cached avatars', ['id' => $cid, 'uid' => $uid, 'owner-uid' => $local_uid]);
} else { } else {
$update = false; $update = false;

View file

@ -333,7 +333,7 @@ class Event
$item['uri'] = $event['uri']; $item['uri'] = $event['uri'];
$item['uri-id'] = ItemURI::getIdByURI($event['uri']); $item['uri-id'] = ItemURI::getIdByURI($event['uri']);
$item['guid'] = $event['guid']; $item['guid'] = $event['guid'];
$item['plink'] = $arr['plink'] ?? ''; $item['plink'] = '';
$item['post-type'] = Item::PT_EVENT; $item['post-type'] = Item::PT_EVENT;
$item['wall'] = $event['cid'] ? 0 : 1; $item['wall'] = $event['cid'] ? 0 : 1;
$item['contact-id'] = $contact['id']; $item['contact-id'] = $contact['id'];

View file

@ -318,6 +318,8 @@ class Engagement
$result = Post::selectPosts(['author-addr', 'author-nick', 'author-contact-type'], $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]]); ['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)) { while ($reshare = Post::fetch($result)) {
$prefix = '';
switch ($reshare['author-contact-type']) { switch ($reshare['author-contact-type']) {
case Contact::TYPE_RELAY: case Contact::TYPE_RELAY:
$prefix = ' application_'; $prefix = ' application_';

View file

@ -113,9 +113,6 @@ class Link
try { try {
$curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]); $curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
if (empty($curlResult) || !$curlResult->isSuccess()) {
return [];
}
} catch (\Exception $exception) { } catch (\Exception $exception) {
Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]); Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]);
return []; return [];

View file

@ -699,7 +699,7 @@ class Media
if (preg_match_all("/\[url\](https?:.*?)\[\/url\]/ism", $body, $matches)) { if (preg_match_all("/\[url\](https?:.*?)\[\/url\]/ism", $body, $matches)) {
foreach ($matches[1] as $url) { foreach ($matches[1] as $url) {
Logger::info('Got page url (link without description)', ['uri-id' => $uriid, 'url' => $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])) { if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA])) {
self::revertHTMLType($uriid, $url, $fullbody); self::revertHTMLType($uriid, $url, $fullbody);
Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]); 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)) { if (preg_match_all("/\[url\=(https?:.*?)\].*?\[\/url\]/ism", $body, $matches)) {
foreach ($matches[1] as $url) { foreach ($matches[1] as $url) {
Logger::info('Got page url (link with description)', ['uri-id' => $uriid, 'url' => $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])) { if ($result && !in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA])) {
self::revertHTMLType($uriid, $url, $fullbody); self::revertHTMLType($uriid, $url, $fullbody);
Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]); Logger::debug('Revert HTML type', ['uri-id' => $uriid, 'url' => $url]);