Merge branch 'refactor-logger-class-with-logger-object' into fix-code-style-for-pr-14688

This commit is contained in:
Art4 2025-01-14 09:29:35 +00:00
commit 3698ab5aaa
4 changed files with 29 additions and 24 deletions

View file

@ -15,7 +15,17 @@ use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
* Manager for the core logging instances * Bridge for the legacy Logger factory.
*
* This class can be removed after the following classes are replaced or
* refactored implementing the `\Friendica\Core\Logger\Factory\LoggerFactory`:
*
* - Friendica\Core\Logger\Factory\StreamLogger
* - Friendica\Core\Logger\Factory\SyslogLogger
* - monolog addon: Friendica\Addon\monolog\src\Factory\Monolog
*
* @see \Friendica\Core\Logger\Factory\StreamLogger
* @see \Friendica\Core\Logger\Factory\SyslogLogger
*/ */
final class LegacyLoggerFactory implements LoggerFactory final class LegacyLoggerFactory implements LoggerFactory
{ {

View file

@ -26,6 +26,7 @@ use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Network\HTTPException\NotModifiedException;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Security\OpenWebAuth; use Friendica\Security\OpenWebAuth;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
@ -296,7 +297,7 @@ class Photo extends BaseApi
return MPhoto::createPhotoForExternalResource($link['url'], (int)DI::userSession()->getLocalUserId(), $link['mimetype'] ?? '', $link['blurhash'] ?? '', $link['width'] ?? 0, $link['height'] ?? 0); return MPhoto::createPhotoForExternalResource($link['url'], (int)DI::userSession()->getLocalUserId(), $link['mimetype'] ?? '', $link['blurhash'] ?? '', $link['width'] ?? 0, $link['height'] ?? 0);
case 'contact': case 'contact':
$fields = ['uid', 'uri-id', 'url', 'nurl', 'avatar', 'photo', 'blurhash', 'xmpp', 'addr', 'network', 'failed', 'updated']; $fields = ['uid', 'uri-id', 'url', 'nurl', 'avatar', 'photo', 'blurhash', 'xmpp', 'addr', 'network', 'failed', 'updated', 'next-update'];
$contact = Contact::getById($id, $fields); $contact = Contact::getById($id, $fields);
if (empty($contact)) { if (empty($contact)) {
return false; return false;
@ -354,7 +355,7 @@ class Photo extends BaseApi
} else { } else {
// Only update federated accounts that hadn't failed before and hadn't been updated recently // Only update federated accounts that hadn't failed before and hadn't been updated recently
$update = in_array($contact['network'], Protocol::FEDERATED) && !$contact['failed'] $update = in_array($contact['network'], Protocol::FEDERATED) && !$contact['failed']
&& ((time() - strtotime($contact['updated']) > 86400)); && ($contact['next-update'] < DateTimeFormat::utcNow());
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);

View file

@ -51,6 +51,7 @@ class UpdateContact
return 0; return 0;
} }
DI::logger()->debug('Update contact', ['id' => $contact_id]);
return Worker::add($run_parameters, 'UpdateContact', $contact_id); return Worker::add($run_parameters, 'UpdateContact', $contact_id);
} }
} }

View file

@ -21,12 +21,25 @@ use Psr\Log\NullLogger;
class LoggerManagerTest extends TestCase class LoggerManagerTest extends TestCase
{ {
public function testGetLoggerReturnsPsrLogger(): void /**
* Clean the private static properties
*
* @see LoggerManager::$logger
* @see LoggerManager::$logChannel
*/
protected function tearDown(): void
{ {
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger'); $reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null); $reflectionProperty->setValue(null, null);
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logChannel');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, LogChannel::DEFAULT);
}
public function testGetLoggerReturnsPsrLogger(): void
{
$factory = new LoggerManager( $factory = new LoggerManager(
$this->createStub(IManageConfigValues::class), $this->createStub(IManageConfigValues::class),
$this->createStub(LoggerFactory::class) $this->createStub(LoggerFactory::class)
@ -37,10 +50,6 @@ class LoggerManagerTest extends TestCase
public function testGetLoggerReturnsSameObject(): void public function testGetLoggerReturnsSameObject(): void
{ {
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
$factory = new LoggerManager( $factory = new LoggerManager(
$this->createStub(IManageConfigValues::class), $this->createStub(IManageConfigValues::class),
$this->createStub(LoggerFactory::class) $this->createStub(LoggerFactory::class)
@ -56,10 +65,6 @@ class LoggerManagerTest extends TestCase
['system', 'debugging', null, false], ['system', 'debugging', null, false],
]); ]);
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
$factory = new LoggerManager( $factory = new LoggerManager(
$config, $config,
$this->createStub(LoggerFactory::class) $this->createStub(LoggerFactory::class)
@ -76,10 +81,6 @@ class LoggerManagerTest extends TestCase
['system', 'profiling', null, true], ['system', 'profiling', null, true],
]); ]);
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
$factory = new LoggerManager( $factory = new LoggerManager(
$config, $config,
$this->createStub(LoggerFactory::class) $this->createStub(LoggerFactory::class)
@ -96,10 +97,6 @@ class LoggerManagerTest extends TestCase
['system', 'profiling', null, true], ['system', 'profiling', null, true],
]); ]);
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
$factory = new LoggerManager( $factory = new LoggerManager(
$config, $config,
$this->createStub(LoggerFactory::class) $this->createStub(LoggerFactory::class)
@ -120,10 +117,6 @@ class LoggerManagerTest extends TestCase
['system', 'profiling', null, true], ['system', 'profiling', null, true],
]); ]);
$reflectionProperty = new \ReflectionProperty(LoggerManager::class, 'logger');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(null, null);
$factory = new LoggerManager( $factory = new LoggerManager(
$config, $config,
$this->createStub(LoggerFactory::class) $this->createStub(LoggerFactory::class)