From 9c05b88bac7d8593795d1ce7ec43f2103d1f09ef Mon Sep 17 00:00:00 2001 From: Jonas Anne <jonasanne@outlook.com> Date: Fri, 9 Aug 2024 16:31:20 +0200 Subject: [PATCH] Issue #3433498: D11 compatibility fixes --- composer.json | 4 +-- .../monitoring_logging_check_drupal.info.yml | 2 +- monitoring_logging.info.yml | 2 +- src/Plugin/Logger/File.php | 25 +++++++++++++++---- tests/src/Unit/Plugin/Logger/FileTest.php | 3 ++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 5045dda..cb744de 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require": { "drupal/monitoring": "^1.12", - "php": "^8.1", - "drupal/core": "^9.4 || ^10" + "php": "^8.1 || ^8.3", + "drupal/core": "^9.4 || ^10 || ^11" } } diff --git a/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml b/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml index 7c4c0b1..9adeafa 100644 --- a/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml +++ b/modules/monitoring_logging_check_drupal/monitoring_logging_check_drupal.info.yml @@ -1,7 +1,7 @@ name: Monitoring Logging check_drupal type: module description: Provides a monitoring file logger formatter that outputs the log in a file, in a format readable by https://github.com/cytopia/check_drupal. -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^9.4 || ^10 || ^11 package: Monitoring dependencies: - monitoring_logging:monitoring_logging diff --git a/monitoring_logging.info.yml b/monitoring_logging.info.yml index 3bb5b72..0ebfa68 100644 --- a/monitoring_logging.info.yml +++ b/monitoring_logging.info.yml @@ -1,7 +1,7 @@ name: Monitoring Logging type: module description: Outputs an overview of sensor results to a log. -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^9.4 || ^10 || ^11 package: Monitoring dependencies: - monitoring:monitoring diff --git a/src/Plugin/Logger/File.php b/src/Plugin/Logger/File.php index 022e30b..428e63b 100644 --- a/src/Plugin/Logger/File.php +++ b/src/Plugin/Logger/File.php @@ -6,14 +6,17 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\File\Exception\FileException; +use Drupal\Core\File\FileExists; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginDependencyTrait; use Drupal\Core\Plugin\PluginWithFormsInterface; +use Drupal\Core\Utility\Error; use Drupal\monitoring\Result\SensorResultInterface; use Drupal\monitoring_logging\FileLogFormatterManager; use Drupal\monitoring_logging\Form\LoggerFileForm; use Drupal\monitoring_logging\LoggerBase; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -42,6 +45,13 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI */ protected $fileSystem; + /** + * The logger service. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Creates a file logger. * @@ -55,17 +65,21 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI * The file log formatter plugin manager. * @param \Drupal\Core\File\FileSystemInterface $fileSystem * The file system implementation. + * @param \Psr\Log\LoggerInterface $logger + * The logger service. */ public function __construct( array $configuration, $plugin_id, $plugin_definition, FileLogFormatterManager $fileLogFormatterManager, - FileSystemInterface $fileSystem + FileSystemInterface $fileSystem, + LoggerInterface $logger, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->fileLogFormatterManager = $fileLogFormatterManager; $this->fileSystem = $fileSystem; + $this->logger = $logger; } /** @@ -77,7 +91,8 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI $plugin_id, $plugin_definition, $container->get('plugin.manager.monitoring_file_log_formatter'), - $container->get('file_system') + $container->get('file_system'), + $container->get('logger.factory')->get('default') ); } @@ -86,10 +101,10 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI */ public function logResults(SensorResultInterface ...$results) { try { - return $this->fileSystem->saveData($this->getFormatter()->format(...$results), $this->getFile(), FileSystemInterface::EXISTS_REPLACE); + return $this->fileSystem->saveData($this->getFormatter()->format(...$results), $this->getFile(), FileExists::Replace); } catch (FileException $e) { - watchdog_exception('monitoring_logging', $e); + Error::logException($this->logger, $e); } return FALSE; } @@ -144,7 +159,7 @@ class File extends LoggerBase implements PluginWithFormsInterface, ConfigurableI return $this->fileLogFormatterManager->createInstance($this->getConfiguration()['formatter']); } catch (PluginNotFoundException $ex) { - watchdog_exception('monitoring_logging', $ex); + Error::logException($this->logger, $ex); } } return FALSE; diff --git a/tests/src/Unit/Plugin/Logger/FileTest.php b/tests/src/Unit/Plugin/Logger/FileTest.php index d563a87..f6fa4c2 100644 --- a/tests/src/Unit/Plugin/Logger/FileTest.php +++ b/tests/src/Unit/Plugin/Logger/FileTest.php @@ -6,6 +6,7 @@ use Prophecy\PhpUnit\ProphecyTrait; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\File\FileExists; use Drupal\monitoring\Result\SensorResultInterface; use Drupal\monitoring_logging\FileLogFormatterInterface; use Drupal\monitoring_logging\FileLogFormatterManager; @@ -68,7 +69,7 @@ final class FileTest extends UnitTestCase { $this->formatter->format(...$results)->willReturn($formattedText); $this->fileSystem - ->saveData($formattedText, $destination, FileSystemInterface::EXISTS_REPLACE) + ->saveData($formattedText, $destination, FileExists::Replace) ->shouldBeCalled() ->willReturn($destination); $logger = $this->getLogger([ -- GitLab