From 0d6f4b7088cd35d385f7d38a5e7335cbab46b6c4 Mon Sep 17 00:00:00 2001 From: omkar podey <58183-omkar.podey@users.noreply.drupalcode.org> Date: Sat, 10 Dec 2022 12:42:22 +0000 Subject: [PATCH] Issue #3325716 by omkar.podey: Deprecate config factory in Stage --- .../src/ExtensionUpdater.php | 21 +++++ ...tomaticUpdatesExtensionsKernelTestBase.php | 4 +- .../src/PackageManagerUninstallValidator.php | 3 +- package_manager/src/Stage.php | 4 + package_manager/src/UnusedConfigFactory.php | 82 +++++++++++++++++++ .../src/ApiController.php | 4 +- .../Kernel/PackageManagerKernelTestBase.php | 5 +- .../tests/src/Kernel/StageTest.php | 1 + src/CronUpdater.php | 5 ++ src/Updater.php | 21 +++++ 10 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 package_manager/src/UnusedConfigFactory.php diff --git a/automatic_updates_extensions/src/ExtensionUpdater.php b/automatic_updates_extensions/src/ExtensionUpdater.php index 99031f8b30..8468f7bc6d 100644 --- a/automatic_updates_extensions/src/ExtensionUpdater.php +++ b/automatic_updates_extensions/src/ExtensionUpdater.php @@ -5,12 +5,24 @@ declare(strict_types = 1); namespace Drupal\automatic_updates_extensions; use Drupal\automatic_updates\Exception\UpdateException; +use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\package_manager\Exception\ApplyFailedException; +use Drupal\package_manager\FailureMarker; use Drupal\package_manager\LegacyVersionUtility; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Exception\StageValidationException; +use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; +use Drupal\package_manager\UnusedConfigFactory; +use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; +use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; +use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; +use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service to perform updates for modules and themes. @@ -21,6 +33,15 @@ use Drupal\package_manager\Stage; */ class ExtensionUpdater extends Stage { + /** + * {@inheritdoc} + * + * @todo Remove this in https://www.drupal.org/i/3303167 + */ + public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $temp_store_factory, TimeInterface $time, PathFactoryInterface $path_factory = NULL, FailureMarker $failure_marker = NULL) { + parent::__construct(new UnusedConfigFactory(), $path_locator, $beginner, $stager, $committer, $file_system, $event_dispatcher, $temp_store_factory, $time, $path_factory, $failure_marker); + } + /** * Begins the update. * diff --git a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php index a812dd174e..2aeb8477ca 100644 --- a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php +++ b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\automatic_updates_extensions\Kernel; use Drupal\automatic_updates_extensions\ExtensionUpdater; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\package_manager\Exception\StageValidationException; +use Drupal\package_manager\UnusedConfigFactory; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; use Drupal\Tests\package_manager\Kernel\TestPathFactory; use Drupal\Tests\package_manager\Kernel\TestStageTrait; @@ -109,7 +110,8 @@ abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdates */ protected function createExtensionUpdater(): TestExtensionUpdater { return new TestExtensionUpdater( - $this->container->get('config.factory'), + // @todo Remove this in https://www.drupal.org/i/3303167 + new UnusedConfigFactory(), $this->container->get('package_manager.path_locator'), $this->container->get('package_manager.beginner'), $this->container->get('package_manager.stager'), diff --git a/package_manager/src/PackageManagerUninstallValidator.php b/package_manager/src/PackageManagerUninstallValidator.php index 1317b963c2..4c9f74acef 100644 --- a/package_manager/src/PackageManagerUninstallValidator.php +++ b/package_manager/src/PackageManagerUninstallValidator.php @@ -28,7 +28,8 @@ final class PackageManagerUninstallValidator implements ModuleUninstallValidator */ public function validate($module) { $stage = new Stage( - $this->container->get('config.factory'), + // @todo Remove this in https://www.drupal.org/i/3303167 + new UnusedConfigFactory(), $this->container->get('package_manager.path_locator'), $this->container->get('package_manager.beginner'), $this->container->get('package_manager.stager'), diff --git a/package_manager/src/Stage.php b/package_manager/src/Stage.php index 384421675d..13acf5e876 100644 --- a/package_manager/src/Stage.php +++ b/package_manager/src/Stage.php @@ -232,6 +232,10 @@ class Stage implements LoggerAwareInterface { $this->time = $time; $this->tempStoreFactory = $temp_store_factory; $this->tempStore = $temp_store_factory->get('package_manager_stage'); + if (!$config_factory instanceof UnusedConfigFactory) { + // @todo Remove this in https://www.drupal.org/i/3303167 + @trigger_error('Calling ' . __METHOD__ . '() with the $config_factory argument is deprecated in automatic_updates:8.x-2.6 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3325718.', E_USER_DEPRECATED); + } if (empty($path_factory)) { @trigger_error('Calling ' . __METHOD__ . '() 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.', E_USER_DEPRECATED); $path_factory = new PathFactory(); diff --git a/package_manager/src/UnusedConfigFactory.php b/package_manager/src/UnusedConfigFactory.php new file mode 100644 index 0000000000..1493bdc0f0 --- /dev/null +++ b/package_manager/src/UnusedConfigFactory.php @@ -0,0 +1,82 @@ +<?php + +declare(strict_types = 1); + +namespace Drupal\package_manager; + +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Config\ConfigFactoryOverrideInterface; + +/** + * Dummy Class. + * + * @internal + * + * @todo Remove this in https://www.drupal.org/i/3303167 + */ +final class UnusedConfigFactory implements ConfigFactoryInterface { + + /** + * {@inheritdoc} + */ + public function get($name) { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function getEditable($name) { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function loadMultiple(array $names) { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function reset($name = NULL) { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function rename($old_name, $new_name) { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function getCacheKeys() { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function clearStaticCache() { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function listAll($prefix = '') { + throw new \LogicException(); + } + + /** + * {@inheritdoc} + */ + public function addOverride(ConfigFactoryOverrideInterface $config_factory_override) { + throw new \LogicException(); + } + +} diff --git a/package_manager/tests/modules/package_manager_test_api/src/ApiController.php b/package_manager/tests/modules/package_manager_test_api/src/ApiController.php index a660880615..555e465b41 100644 --- a/package_manager/tests/modules/package_manager_test_api/src/ApiController.php +++ b/package_manager/tests/modules/package_manager_test_api/src/ApiController.php @@ -8,6 +8,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; +use Drupal\package_manager\UnusedConfigFactory; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -57,7 +58,8 @@ class ApiController extends ControllerBase { */ public static function create(ContainerInterface $container) { $stage = new Stage( - $container->get('config.factory'), + // @todo Remove this in https://www.drupal.org/i/3303167 + new UnusedConfigFactory(), $container->get('package_manager.path_locator'), $container->get('package_manager.beginner'), $container->get('package_manager.stager'), diff --git a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php index cbcad1a0a8..e3b18480cd 100644 --- a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php +++ b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php @@ -8,6 +8,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\KernelTests\KernelTestBase; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\StatusCheckTrait; +use Drupal\package_manager\UnusedConfigFactory; use Drupal\package_manager\Validator\DiskSpaceValidator; use Drupal\package_manager\Exception\StageException; use Drupal\package_manager\Exception\StageValidationException; @@ -21,6 +22,7 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Utils; use org\bovigo\vfs\vfsStream; +use PHPStan\Rules\Arrays\UnpackIterableInArrayRule; use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface; use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; use PhpTuf\ComposerStager\Infrastructure\Value\Path\AbstractPath; @@ -131,7 +133,8 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { */ protected function createStage(): TestStage { return new TestStage( - $this->container->get('config.factory'), + // @todo Remove this in https://www.drupal.org/i/3303167 + new UnusedConfigFactory(), $this->container->get('package_manager.path_locator'), $this->container->get('package_manager.beginner'), $this->container->get('package_manager.stager'), diff --git a/package_manager/tests/src/Kernel/StageTest.php b/package_manager/tests/src/Kernel/StageTest.php index 66c7551f1f..949bf3c861 100644 --- a/package_manager/tests/src/Kernel/StageTest.php +++ b/package_manager/tests/src/Kernel/StageTest.php @@ -402,6 +402,7 @@ class StageTest extends PackageManagerKernelTestBase { ->get('package_manager') ->addLogger($logger); + $this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() with the $config_factory argument is deprecated in automatic_updates:8.x-2.6 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3325718.'); $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.'); diff --git a/src/CronUpdater.php b/src/CronUpdater.php index c46932b70c..3ca7530d64 100644 --- a/src/CronUpdater.php +++ b/src/CronUpdater.php @@ -11,6 +11,7 @@ use Drupal\Core\Url; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\StageValidationException; use Drupal\package_manager\ProjectInfo; +use Drupal\package_manager\UnusedConfigFactory; use Drupal\update\ProjectRelease; use GuzzleHttp\Psr7\Uri as GuzzleUri; use Symfony\Component\HttpFoundation\Response; @@ -92,7 +93,11 @@ class CronUpdater extends Updater { * Additional arguments to pass to the parent constructor. */ public function __construct(ReleaseChooser $release_chooser, LoggerChannelFactoryInterface $logger_factory, MailManagerInterface $mail_manager, StatusCheckMailer $status_check_mailer, StateInterface $state, ...$arguments) { + $config_factory = $arguments[0]; + $arguments[0] = new UnusedConfigFactory(); parent::__construct(...$arguments); + // @todo Remove this in https://www.drupal.org/i/3303167 + $this->configFactory = $config_factory; $this->releaseChooser = $release_chooser; $this->logger = $logger_factory->get('automatic_updates'); $this->mailManager = $mail_manager; diff --git a/src/Updater.php b/src/Updater.php index 7a73c0cae6..4880400eb7 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -5,11 +5,23 @@ declare(strict_types = 1); namespace Drupal\automatic_updates; use Drupal\automatic_updates\Exception\UpdateException; +use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\StageValidationException; +use Drupal\package_manager\FailureMarker; +use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; +use Drupal\package_manager\UnusedConfigFactory; +use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; +use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; +use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; +use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service to perform updates. @@ -21,6 +33,15 @@ use Drupal\package_manager\Stage; */ class Updater extends Stage { + /** + * {@inheritdoc} + * + * @todo Remove this in https://www.drupal.org/i/3303167 + */ + public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $temp_store_factory, TimeInterface $time, PathFactoryInterface $path_factory = NULL, FailureMarker $failure_marker = NULL) { + parent::__construct(new UnusedConfigFactory(), $path_locator, $beginner, $stager, $committer, $file_system, $event_dispatcher, $temp_store_factory, $time, $path_factory, $failure_marker); + } + /** * Begins the update. * -- GitLab