From 6d8643bd0490a9e6dd72f0b8885c5d6fef2ab1fb Mon Sep 17 00:00:00 2001 From: Adam G-H <32250-phenaproxima@users.noreply.drupalcode.org> Date: Thu, 12 Sep 2024 14:39:55 +0000 Subject: [PATCH] Issue #3437951: StageBase does not need to use a NullLogger --- package_manager/src/StageBase.php | 8 ++++---- src/CronUpdateRunner.php | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/package_manager/src/StageBase.php b/package_manager/src/StageBase.php index fd7b62925e..23fe713ae3 100644 --- a/package_manager/src/StageBase.php +++ b/package_manager/src/StageBase.php @@ -35,7 +35,6 @@ use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use Psr\Log\NullLogger; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** @@ -207,7 +206,6 @@ abstract class StageBase implements LoggerAwareInterface { protected readonly FailureMarker $failureMarker, ) { $this->tempStore = $tempStoreFactory->get('package_manager_stage'); - $this->setLogger(new NullLogger()); } /** @@ -543,7 +541,7 @@ abstract class StageBase implements LoggerAwareInterface { $this->checkOwnership(); if ($this->tempStore->get(self::TEMPSTORE_APPLY_TIME_KEY) === $this->time->getRequestTime()) { - $this->logger->warning('Post-apply tasks are running in the same request during which staged changes were applied to the active code base. This can result in unpredictable behavior.'); + $this->logger?->warning('Post-apply tasks are running in the same request during which staged changes were applied to the active code base. This can result in unpredictable behavior.'); } // Rebuild the container and clear all caches, to ensure that new services // are picked up. @@ -629,7 +627,9 @@ abstract class StageBase implements LoggerAwareInterface { if (isset($error)) { // Ensure the error is logged for post-mortem diagnostics. - Error::logException($this->logger, $error); + if ($this->logger) { + Error::logException($this->logger, $error); + } if ($on_error) { $on_error(); } diff --git a/src/CronUpdateRunner.php b/src/CronUpdateRunner.php index 04ce6f8cec..5c2d8107d5 100644 --- a/src/CronUpdateRunner.php +++ b/src/CronUpdateRunner.php @@ -10,7 +10,6 @@ use Drupal\Core\Utility\Error; use Drupal\package_manager\PathLocator; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use Psr\Log\NullLogger; /** * Runs updates as a detached background process after regular cron tasks. @@ -76,9 +75,7 @@ class CronUpdateRunner implements CronInterface, LoggerAwareInterface { private readonly PathLocator $pathLocator, private readonly CronInterface $inner, private readonly CommandExecutor $commandExecutor, - ) { - $this->setLogger(new NullLogger()); - } + ) {} /** * Runs the terminal update command. @@ -92,18 +89,20 @@ class CronUpdateRunner implements CronInterface, LoggerAwareInterface { $pid = $this->commandExecutor->start($process); } catch (\Throwable $throwable) { - Error::logException($this->logger, $throwable, 'Unable to start background update.'); + if ($this->logger) { + Error::logException($this->logger, $throwable, 'Unable to start background update.'); + } } if ($process->isTerminated()) { if ($process->getExitCode() !== 0) { - $this->logger->error('Background update failed: %message', [ + $this->logger?->error('Background update failed: %message', [ '%message' => $process->getErrorOutput(), ]); } } elseif (empty($pid)) { - $this->logger->error('Background update failed because the process did not start within 5 seconds.'); + $this->logger?->error('Background update failed because the process did not start within 5 seconds.'); } } -- GitLab