Replace Logger with DI::logger() in Contact namespace

This commit is contained in:
Art4 2025-01-12 21:14:33 +00:00
parent bf3004e4bf
commit cb7534c823

View file

@ -47,36 +47,36 @@ class Avatar
if (($avatar != $contact['avatar']) || $force) { if (($avatar != $contact['avatar']) || $force) {
self::deleteCache($contact); self::deleteCache($contact);
Logger::debug('Avatar file name changed', ['new' => $avatar, 'old' => $contact['avatar']]); DI::logger()->debug('Avatar file name changed', ['new' => $avatar, 'old' => $contact['avatar']]);
} elseif (self::isCacheFile($contact['photo']) && self::isCacheFile($contact['thumb']) && self::isCacheFile($contact['micro'])) { } elseif (self::isCacheFile($contact['photo']) && self::isCacheFile($contact['thumb']) && self::isCacheFile($contact['micro'])) {
$fields['photo'] = $contact['photo']; $fields['photo'] = $contact['photo'];
$fields['thumb'] = $contact['thumb']; $fields['thumb'] = $contact['thumb'];
$fields['micro'] = $contact['micro']; $fields['micro'] = $contact['micro'];
Logger::debug('Using existing cache files', ['uri-id' => $contact['uri-id'], 'fields' => $fields]); DI::logger()->debug('Using existing cache files', ['uri-id' => $contact['uri-id'], 'fields' => $fields]);
return $fields; return $fields;
} }
try { try {
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
} catch (\Exception $exception) { } catch (\Exception $exception) {
Logger::notice('Avatar is invalid', ['avatar' => $avatar, 'exception' => $exception]); DI::logger()->notice('Avatar is invalid', ['avatar' => $avatar, 'exception' => $exception]);
return $fields; return $fields;
} }
if (!$fetchResult->isSuccess()) { if (!$fetchResult->isSuccess()) {
Logger::debug('Fetching was unsuccessful', ['avatar' => $avatar]); DI::logger()->debug('Fetching was unsuccessful', ['avatar' => $avatar]);
return $fields; return $fields;
} }
$img_str = $fetchResult->getBodyString(); $img_str = $fetchResult->getBodyString();
if (empty($img_str)) { if (empty($img_str)) {
Logger::debug('Avatar is invalid', ['avatar' => $avatar]); DI::logger()->debug('Avatar is invalid', ['avatar' => $avatar]);
return $fields; return $fields;
} }
$image = new Image($img_str, $fetchResult->getContentType(), $avatar); $image = new Image($img_str, $fetchResult->getContentType(), $avatar);
if (!$image->isValid()) { if (!$image->isValid()) {
Logger::debug('Avatar picture is invalid', ['avatar' => $avatar]); DI::logger()->debug('Avatar picture is invalid', ['avatar' => $avatar]);
return $fields; return $fields;
} }
@ -89,7 +89,7 @@ class Avatar
$fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB, $timestamp); $fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB, $timestamp);
$fields['micro'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_MICRO, $timestamp); $fields['micro'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_MICRO, $timestamp);
Logger::debug('Storing new avatar cache', ['uri-id' => $contact['uri-id'], 'fields' => $fields]); DI::logger()->debug('Storing new avatar cache', ['uri-id' => $contact['uri-id'], 'fields' => $fields]);
return $fields; return $fields;
} }
@ -155,36 +155,36 @@ class Avatar
if (!file_exists($dirpath)) { if (!file_exists($dirpath)) {
if (!@mkdir($dirpath, $dir_perm) && !file_exists($dirpath)) { if (!@mkdir($dirpath, $dir_perm) && !file_exists($dirpath)) {
Logger::warning('Directory could not be created', ['directory' => $dirpath]); DI::logger()->warning('Directory could not be created', ['directory' => $dirpath]);
} }
} elseif ((($old_perm = fileperms($dirpath) & 0777) != $dir_perm) && !chmod($dirpath, $dir_perm)) { } elseif ((($old_perm = fileperms($dirpath) & 0777) != $dir_perm) && !chmod($dirpath, $dir_perm)) {
Logger::warning('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]); DI::logger()->warning('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]);
} }
if ((($old_group = filegroup($dirpath)) != $group) && !chgrp($dirpath, $group)) { if ((($old_group = filegroup($dirpath)) != $group) && !chgrp($dirpath, $group)) {
Logger::warning('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]); DI::logger()->warning('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]);
} }
} }
if (!file_put_contents($filepath, $image->asString())) { if (!file_put_contents($filepath, $image->asString())) {
Logger::warning('File could not be created', ['file' => $filepath]); DI::logger()->warning('File could not be created', ['file' => $filepath]);
} }
$old_perm = fileperms($filepath) & 0666; $old_perm = fileperms($filepath) & 0666;
$old_group = filegroup($filepath); $old_group = filegroup($filepath);
if (($old_perm != $file_perm) && !chmod($filepath, $file_perm)) { if (($old_perm != $file_perm) && !chmod($filepath, $file_perm)) {
Logger::warning('File permissions could not be changed', ['file' => $filepath, 'old' => $old_perm, 'new' => $file_perm]); DI::logger()->warning('File permissions could not be changed', ['file' => $filepath, 'old' => $old_perm, 'new' => $file_perm]);
} }
if (($old_group != $group) && !chgrp($filepath, $group)) { if (($old_group != $group) && !chgrp($filepath, $group)) {
Logger::warning('File group could not be changed', ['file' => $filepath, 'old' => $old_group, 'new' => $group]); DI::logger()->warning('File group could not be changed', ['file' => $filepath, 'old' => $old_group, 'new' => $group]);
} }
DI::profiler()->stopRecording(); DI::profiler()->stopRecording();
if (!file_exists($filepath)) { if (!file_exists($filepath)) {
Logger::warning('Avatar cache file could not be stored', ['file' => $filepath]); DI::logger()->warning('Avatar cache file could not be stored', ['file' => $filepath]);
return ''; return '';
} }
@ -257,7 +257,7 @@ class Avatar
$localFile = self::getCacheFile($avatar); $localFile = self::getCacheFile($avatar);
if (!empty($localFile)) { if (!empty($localFile)) {
@unlink($localFile); @unlink($localFile);
Logger::debug('Unlink avatar', ['avatar' => $avatar, 'local' => $localFile]); DI::logger()->debug('Unlink avatar', ['avatar' => $avatar, 'local' => $localFile]);
} }
} }
@ -277,11 +277,11 @@ class Avatar
if (!file_exists($basepath)) { if (!file_exists($basepath)) {
// We only automatically create the folder when it is in the web root // We only automatically create the folder when it is in the web root
if (strpos($basepath, DI::basePath()) !== 0) { if (strpos($basepath, DI::basePath()) !== 0) {
Logger::warning('Base directory does not exist', ['directory' => $basepath]); DI::logger()->warning('Base directory does not exist', ['directory' => $basepath]);
return ''; return '';
} }
if (!mkdir($basepath, 0775)) { if (!mkdir($basepath, 0775)) {
Logger::warning('Base directory could not be created', ['directory' => $basepath]); DI::logger()->warning('Base directory could not be created', ['directory' => $basepath]);
return ''; return '';
} }
} }