From cb11dd234abfb1bc18e40901ab0b143594b81149 Mon Sep 17 00:00:00 2001 From: phenaproxima <phenaproxima@205645.no-reply.drupal.org> Date: Wed, 26 Oct 2022 15:09:33 +0000 Subject: [PATCH] Issue #3317599 by phenaproxima: Log an error if protected Stage constants are overridden --- package_manager/src/Stage.php | 4 ++++ package_manager/tests/src/Kernel/StageTest.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/package_manager/src/Stage.php b/package_manager/src/Stage.php index f04fa31b2d..a6ca9a157e 100644 --- a/package_manager/src/Stage.php +++ b/package_manager/src/Stage.php @@ -242,9 +242,13 @@ class Stage implements LoggerAwareInterface { $this->setLogger(new NullLogger()); if (self::TEMPSTORE_METADATA_KEY !== static::TEMPSTORE_METADATA_KEY) { @trigger_error('Overriding ' . __CLASS__ . '::TEMPSTORE_METADATA_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.', E_USER_DEPRECATED); + \Drupal::logger('package_manager') + ->error(__CLASS__ . '::TEMPSTORE_METADATA_KEY is overridden by ' . static::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.'); } if (self::TEMPSTORE_LOCK_KEY !== static::TEMPSTORE_LOCK_KEY) { @trigger_error('Overriding ' . __CLASS__ . '::TEMPSTORE_LOCK_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.', E_USER_DEPRECATED); + \Drupal::logger('package_manager') + ->error(__CLASS__ . '::TEMPSTORE_LOCK_KEY is overridden by ' . static::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.'); } } diff --git a/package_manager/tests/src/Kernel/StageTest.php b/package_manager/tests/src/Kernel/StageTest.php index 0c955bfebf..a49a9cb19b 100644 --- a/package_manager/tests/src/Kernel/StageTest.php +++ b/package_manager/tests/src/Kernel/StageTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\package_manager\Kernel; use Drupal\Component\Datetime\Time; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Extension\ModuleUninstallValidatorException; +use Drupal\Core\Logger\RfcLogLevel; use Drupal\package_manager\Event\PostApplyEvent; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\StageEvent; @@ -393,6 +394,11 @@ class StageTest extends PackageManagerKernelTestBase { * @group legacy */ public function testConstructorDeprecations(): void { + $logger = new TestLogger(); + $this->container->get('logger.factory') + ->get('package_manager') + ->addLogger($logger); + $this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() without the $path_factory argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3310706.'); $this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() without the $failure_marker argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3311257.'); $this->expectDeprecation('Overriding Drupal\package_manager\Stage::TEMPSTORE_METADATA_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.'); @@ -408,6 +414,8 @@ class StageTest extends PackageManagerKernelTestBase { $this->container->get('tempstore.shared'), $this->container->get('datetime.time') ); + $this->assertTrue($logger->hasRecord('Drupal\package_manager\Stage::TEMPSTORE_METADATA_KEY is overridden by ' . TestStageOverriddenConstants::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.', RfcLogLevel::ERROR)); + $this->assertTrue($logger->hasRecord('Drupal\package_manager\Stage::TEMPSTORE_LOCK_KEY is overridden by ' . TestStageOverriddenConstants::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.', RfcLogLevel::ERROR)); } /** -- GitLab