Replace Logger with DI::logger() in Model classes

This commit is contained in:
Art4 2025-01-13 10:16:02 +00:00
parent 5b4faf811f
commit a0e2c82c62
12 changed files with 253 additions and 266 deletions

View file

@ -9,7 +9,6 @@ namespace Friendica\Model;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\Database;
use Friendica\Database\DBA;
@ -101,11 +100,11 @@ class Tag
}
if ((substr($url, 0, 7) == 'https//') || (substr($url, 0, 6) == 'http//')) {
Logger::notice('Wrong scheme in url', ['url' => $url]);
DI::logger()->notice('Wrong scheme in url', ['url' => $url]);
}
$cid = Contact::getIdForURL($url, 0, false);
Logger::debug('Got id for contact', ['cid' => $cid, 'url' => $url]);
DI::logger()->debug('Got id for contact', ['cid' => $cid, 'url' => $url]);
if (empty($cid)) {
$tag = DBA::selectFirst('tag', ['name', 'type'], ['url' => $url]);
@ -141,14 +140,14 @@ class Tag
$condition = $fields;
$condition['type'] = [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION];
if (DBA::exists('post-tag', $condition)) {
Logger::info('Tag already exists', $fields);
DI::logger()->info('Tag already exists', $fields);
return;
}
}
DBA::insert('post-tag', $fields, Database::INSERT_IGNORE);
Logger::debug('Stored tag/mention', ['uri-id' => $uriId, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type]);
DI::logger()->debug('Stored tag/mention', ['uri-id' => $uriId, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type]);
}
/**
@ -170,26 +169,26 @@ class Tag
if (!empty($tag['type'])) {
$target = $tag['type'];
if ($target != self::GENERAL_COLLECTION) {
Logger::debug('Found existing type', ['type' => $tag['type'], 'url' => $url]);
DI::logger()->debug('Found existing type', ['type' => $tag['type'], 'url' => $url]);
return $target;
}
}
if ($url == ActivityPub::PUBLIC_COLLECTION) {
$target = self::PUBLIC_COLLECTION;
Logger::debug('Public collection', ['url' => $url]);
DI::logger()->debug('Public collection', ['url' => $url]);
} else {
if (DBA::exists('apcontact', ['followers' => $url])) {
$target = self::FOLLOWER_COLLECTION;
Logger::debug('Found collection via existing apcontact', ['url' => $url]);
DI::logger()->debug('Found collection via existing apcontact', ['url' => $url]);
} elseif (Contact::getIdForURL($url, 0, $fetch ? null : false)) {
$target = self::ACCOUNT;
Logger::debug('URL is an account', ['url' => $url]);
DI::logger()->debug('URL is an account', ['url' => $url]);
} elseif ($fetch && ($target != self::GENERAL_COLLECTION)) {
$content = HTTPSignature::fetch($url);
if (!empty($content['type']) && ($content['type'] == 'OrderedCollection')) {
$target = self::GENERAL_COLLECTION;
Logger::debug('URL is an ordered collection', ['url' => $url]);
DI::logger()->debug('URL is an ordered collection', ['url' => $url]);
}
}
}
@ -199,7 +198,7 @@ class Tag
}
if (empty($target)) {
Logger::debug('No type could be detected', ['url' => $url]);
DI::logger()->debug('No type could be detected', ['url' => $url]);
}
return $target;
@ -238,7 +237,7 @@ class Tag
// Also log type
$fields['type'] = $type;
Logger::error('No tag id created', $fields);
DI::logger()->error('No tag id created', $fields);
return 0;
}
@ -305,7 +304,7 @@ class Tag
*/
public static function storeFromArray(array $item, string $tags = null)
{
Logger::info('Check for tags', ['uri-id' => $item['uri-id'], 'hash' => $tags]);
DI::logger()->info('Check for tags', ['uri-id' => $item['uri-id'], 'hash' => $tags]);
if (is_null($tags)) {
$tags = self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION];
@ -336,14 +335,14 @@ class Tag
*/
public static function storeRawTagsFromBody(int $uriId, string $body)
{
Logger::info('Check for tags', ['uri-id' => $uriId]);
DI::logger()->info('Check for tags', ['uri-id' => $uriId]);
$result = BBCode::getTags($body);
if (empty($result)) {
return;
}
Logger::info('Found tags', ['uri-id' => $uriId, 'result' => $result]);
DI::logger()->info('Found tags', ['uri-id' => $uriId, 'result' => $result]);
foreach ($result as $tag) {
if (substr($tag, 0, 1) != self::TAG_CHARACTER[self::HASHTAG]) {
@ -397,7 +396,7 @@ class Tag
return;
}
Logger::debug('Removing tag/mention', ['uri-id' => $uriId, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url]);
DI::logger()->debug('Removing tag/mention', ['uri-id' => $uriId, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url]);
DBA::delete('post-tag', ['uri-id' => $uriId, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
}
@ -576,7 +575,7 @@ class Tag
break;
default:
Logger::warning('Unknown tag type found', $tag);
DI::logger()->warning('Unknown tag type found', $tag);
}
}
DBA::close($taglist);
@ -832,7 +831,7 @@ class Tag
foreach (self::getByURIId($uriId, [self::HASHTAG]) as $tag) {
foreach (self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']) as $uid) {
$uids[$uid][] = $tag['name'];
}
}
}
return $uids;