Replace Logger with $this->logger in Module classes

This commit is contained in:
Art4 2025-01-13 11:00:50 +00:00
parent 105c737609
commit 8643231019
5 changed files with 19 additions and 24 deletions

View file

@ -8,7 +8,6 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Attach as MAttach; use Friendica\Model\Attach as MAttach;
@ -43,7 +42,7 @@ class Attach extends BaseModule
$data = MAttach::getData($item); $data = MAttach::getData($item);
if (is_null($data)) { if (is_null($data)) {
Logger::notice('NULL data for attachment with id ' . $item['id']); $this->logger->notice('NULL data for attachment with id ' . $item['id']);
throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('Item was not found.')); throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('Item was not found.'));
} }

View file

@ -12,7 +12,6 @@ use Friendica\Content\ContactSelector;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Content\Widget; use Friendica\Content\Widget;
use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Theme; use Friendica\Core\Theme;
@ -121,7 +120,7 @@ class Contact extends BaseModule
try { try {
UpdateContact::add(Worker::PRIORITY_HIGH, $contact_id); UpdateContact::add(Worker::PRIORITY_HIGH, $contact_id);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
Logger::notice($e->getMessage(), ['contact' => $contact]); DI::logger()->notice($e->getMessage(), ['contact' => $contact]);
} }
} }

View file

@ -8,7 +8,6 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\OpenWebAuthToken; use Friendica\Model\OpenWebAuthToken;
@ -60,7 +59,7 @@ class Owa extends BaseModule
$verified = HTTPSignature::verifyMagic($contact['pubkey']); $verified = HTTPSignature::verifyMagic($contact['pubkey']);
if ($verified && $verified['header_signed'] && $verified['header_valid']) { if ($verified && $verified['header_signed'] && $verified['header_valid']) {
Logger::debug('OWA header', ['addr' => $contact['addr'], 'data' => $verified]); $this->logger->debug('OWA header', ['addr' => $contact['addr'], 'data' => $verified]);
$ret['success'] = true; $ret['success'] = true;
$token = Strings::getRandomHex(32); $token = Strings::getRandomHex(32);
@ -77,10 +76,10 @@ class Owa extends BaseModule
openssl_public_encrypt($token, $result, $contact['pubkey']); openssl_public_encrypt($token, $result, $contact['pubkey']);
$ret['encrypted_token'] = Strings::base64UrlEncode($result); $ret['encrypted_token'] = Strings::base64UrlEncode($result);
} else { } else {
Logger::info('OWA fail', ['id' => $contact['id'], 'addr' => $contact['addr'], 'url' => $contact['url']]); $this->logger->info('OWA fail', ['id' => $contact['id'], 'addr' => $contact['addr'], 'url' => $contact['url']]);
} }
} else { } else {
Logger::info('Contact not found', ['handle' => $handle]); $this->logger->info('Contact not found', ['handle' => $handle]);
} }
} }
} }

View file

@ -8,7 +8,6 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\Contact\Header; use Friendica\Contact\Header;
use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
@ -104,11 +103,11 @@ class Photo extends BaseApi
} }
if (empty($id)) { if (empty($id)) {
Logger::notice('No picture id was detected', ['parameters' => $this->parameters, 'query' => DI::args()->getQueryString()]); $this->logger->notice('No picture id was detected', ['parameters' => $this->parameters, 'query' => DI::args()->getQueryString()]);
throw new HTTPException\NotFoundException(DI::l10n()->t('The Photo is not available.')); throw new HTTPException\NotFoundException(DI::l10n()->t('The Photo is not available.'));
} }
$photo = self::getPhotoById($id, $this->parameters['type'], $customsize ?: Proxy::PIXEL_SMALL); $photo = $this->getPhotoById($id, $this->parameters['type'], $customsize ?: Proxy::PIXEL_SMALL);
} else { } else {
$photoid = pathinfo($this->parameters['name'], PATHINFO_FILENAME); $photoid = pathinfo($this->parameters['name'], PATHINFO_FILENAME);
$scale = 0; $scale = 0;
@ -172,7 +171,7 @@ class Photo extends BaseApi
$data = microtime(true) - $stamp; $data = microtime(true) - $stamp;
if (empty($imgdata)) { if (empty($imgdata)) {
Logger::warning('Invalid photo', ['id' => $photo['id']]); $this->logger->warning('Invalid photo', ['id' => $photo['id']]);
if (in_array($photo['backend-class'], [ExternalResource::NAME])) { if (in_array($photo['backend-class'], [ExternalResource::NAME])) {
$reference = json_decode($photo['backend-ref'], true); $reference = json_decode($photo['backend-ref'], true);
$error = DI::l10n()->t('Invalid external resource with url %s.', $reference['url']); $error = DI::l10n()->t('Invalid external resource with url %s.', $reference['url']);
@ -232,7 +231,7 @@ class Photo extends BaseApi
$rest = $total - ($fetch + $data + $checksum + $output); $rest = $total - ($fetch + $data + $checksum + $output);
if (!is_null($scale) && ($scale < 4)) { if (!is_null($scale) && ($scale < 4)) {
Logger::debug('Performance:', [ $this->logger->debug('Performance:', [
'scale' => $scale, 'resource' => $photo['resource-id'], 'scale' => $scale, 'resource' => $photo['resource-id'],
'total' => number_format($total, 3), 'fetch' => number_format($fetch, 3), 'total' => number_format($total, 3), 'fetch' => number_format($fetch, 3),
'data' => number_format($data, 3), 'checksum' => number_format($checksum, 3), 'data' => number_format($data, 3), 'checksum' => number_format($checksum, 3),
@ -251,7 +250,7 @@ class Photo extends BaseApi
* @param int $customsize Custom size (?) * @param int $customsize Custom size (?)
* @return array|bool Array on success, false on error * @return array|bool Array on success, false on error
*/ */
private static function getPhotoById(int $id, string $type, int $customsize) private function getPhotoById(int $id, string $type, int $customsize)
{ {
switch ($type) { switch ($type) {
case 'preview': case 'preview':
@ -359,25 +358,25 @@ class Photo extends BaseApi
if ($update) { if ($update) {
$curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::IMAGE, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]); $curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::IMAGE, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
$update = !$curlResult->isSuccess() && ($curlResult->getReturnCode() == 404); $update = !$curlResult->isSuccess() && ($curlResult->getReturnCode() == 404);
Logger::debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); $this->logger->debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
} }
if ($update) { if ($update) {
try { try {
UpdateContact::add(Worker::PRIORITY_LOW, $id); UpdateContact::add(Worker::PRIORITY_LOW, $id);
Logger::info('Invalid file, contact update initiated', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); $this->logger->info('Invalid file, contact update initiated', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
Logger::notice($e->getMessage(), ['id' => $id, 'contact' => $contact]); $this->logger->notice($e->getMessage(), ['id' => $id, 'contact' => $contact]);
} }
} else { } else {
Logger::info('Invalid file', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); $this->logger->info('Invalid file', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
} }
} }
if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) { if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) {
Logger::info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]); $this->logger->info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]);
$mimetext = ''; $mimetext = '';
} }
if (!empty($mimetext)) { if (!empty($mimetext)) {
Logger::debug('Expected Content-Type', ['mime' => $mimetext, 'url' => $url]); $this->logger->debug('Expected Content-Type', ['mime' => $mimetext, 'url' => $url]);
} }
} }

View file

@ -14,7 +14,6 @@ use Friendica\Content\Text\BBCode;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\Worker; use Friendica\Core\Worker;
@ -89,7 +88,7 @@ class Register extends BaseModule
if ($max_dailies) { if ($max_dailies) {
$count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']); $count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']);
if ($count >= $max_dailies) { if ($count >= $max_dailies) {
Logger::notice('max daily registrations exceeded.'); $this->logger->notice('max daily registrations exceeded.');
DI::sysmsg()->addNotice(DI::l10n()->t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.')); DI::sysmsg()->addNotice(DI::l10n()->t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.'));
return ''; return '';
} }
@ -250,7 +249,7 @@ class Register extends BaseModule
// Is there text in the tar pit? // Is there text in the tar pit?
if (!empty($arr['email'])) { if (!empty($arr['email'])) {
Logger::info('Tar pit', $arr); $this->logger->info('Tar pit', $arr);
DI::sysmsg()->addNotice(DI::l10n()->t('You have entered too much information.')); DI::sysmsg()->addNotice(DI::l10n()->t('You have entered too much information.'));
DI::baseUrl()->redirect('register/'); DI::baseUrl()->redirect('register/');
} }
@ -273,7 +272,7 @@ class Register extends BaseModule
} }
if ($arr['email'] != $arr['repeat']) { if ($arr['email'] != $arr['repeat']) {
Logger::info('Mail mismatch', $arr); $this->logger->info('Mail mismatch', $arr);
DI::sysmsg()->addNotice(DI::l10n()->t('Please enter the identical mail address in the second field.')); DI::sysmsg()->addNotice(DI::l10n()->t('Please enter the identical mail address in the second field.'));
$regdata = ['email' => $arr['email'], 'nickname' => $arr['nickname'], 'username' => $arr['username']]; $regdata = ['email' => $arr['email'], 'nickname' => $arr['nickname'], 'username' => $arr['username']];
DI::baseUrl()->redirect('register?' . http_build_query($regdata)); DI::baseUrl()->redirect('register?' . http_build_query($regdata));