Issue #2993271 by bircher, Upchuk: Remove unused ConfigManager dependency in StorageComparer

8.7.x
Nathaniel Catchpole 2018-11-28 11:51:39 +00:00
parent b5ff72a64f
commit 619b274918
15 changed files with 34 additions and 51 deletions

View File

@ -2338,13 +2338,12 @@ function install_config_import_batch() {
\Drupal::configFactory()->getEditable('system.site')->set('uuid', $system_site['uuid'])->save(); \Drupal::configFactory()->getEditable('system.site')->set('uuid', $system_site['uuid'])->save();
// Create the storage comparer and the config importer. // Create the storage comparer and the config importer.
$config_manager = \Drupal::service('config.manager'); $storage_comparer = new StorageComparer($sync, \Drupal::service('config.storage'));
$storage_comparer = new StorageComparer($sync, \Drupal::service('config.storage'), $config_manager);
$storage_comparer->createChangelist(); $storage_comparer->createChangelist();
$config_importer = new ConfigImporter( $config_importer = new ConfigImporter(
$storage_comparer, $storage_comparer,
\Drupal::service('event_dispatcher'), \Drupal::service('event_dispatcher'),
$config_manager, \Drupal::service('config.manager'),
\Drupal::service('lock.persistent'), \Drupal::service('lock.persistent'),
\Drupal::service('config.typed'), \Drupal::service('config.typed'),
\Drupal::service('module_handler'), \Drupal::service('module_handler'),
@ -2409,14 +2408,13 @@ function install_config_download_translations(&$install_state) {
function install_config_revert_install_changes() { function install_config_revert_install_changes() {
global $install_state; global $install_state;
$config_manager = \Drupal::service('config.manager'); $storage_comparer = new StorageComparer(\Drupal::service('config.storage.sync'), \Drupal::service('config.storage'));
$storage_comparer = new StorageComparer(\Drupal::service('config.storage.sync'), \Drupal::service('config.storage'), $config_manager);
$storage_comparer->createChangelist(); $storage_comparer->createChangelist();
if ($storage_comparer->hasChanges()) { if ($storage_comparer->hasChanges()) {
$config_importer = new ConfigImporter( $config_importer = new ConfigImporter(
$storage_comparer, $storage_comparer,
\Drupal::service('event_dispatcher'), \Drupal::service('event_dispatcher'),
$config_manager, \Drupal::service('config.manager'),
\Drupal::service('lock.persistent'), \Drupal::service('lock.persistent'),
\Drupal::service('config.typed'), \Drupal::service('config.typed'),
\Drupal::service('module_handler'), \Drupal::service('module_handler'),

View File

@ -40,13 +40,6 @@ class StorageComparer implements StorageComparerInterface {
*/ */
protected $targetStorages; protected $targetStorages;
/**
* The configuration manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
/** /**
* List of changes to between the source storage and the target storage. * List of changes to between the source storage and the target storage.
* *
@ -96,9 +89,9 @@ class StorageComparer implements StorageComparerInterface {
* @param \Drupal\Core\Config\StorageInterface $target_storage * @param \Drupal\Core\Config\StorageInterface $target_storage
* Storage object used to write configuration. * Storage object used to write configuration.
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* The configuration manager. * (deprecated) The configuration manager. The $config_manager parameter is deprecated since version 8.7.0 and will be removed in 9.0.0.
*/ */
public function __construct(StorageInterface $source_storage, StorageInterface $target_storage, ConfigManagerInterface $config_manager) { public function __construct(StorageInterface $source_storage, StorageInterface $target_storage, ConfigManagerInterface $config_manager = NULL) {
// Wrap the storages in a static cache so that multiple reads of the same // Wrap the storages in a static cache so that multiple reads of the same
// raw configuration object are not costly. // raw configuration object are not costly.
$this->sourceCacheStorage = new MemoryBackend(); $this->sourceCacheStorage = new MemoryBackend();
@ -111,8 +104,11 @@ class StorageComparer implements StorageComparerInterface {
$target_storage, $target_storage,
$this->targetCacheStorage $this->targetCacheStorage
); );
$this->configManager = $config_manager;
$this->changelist[StorageInterface::DEFAULT_COLLECTION] = $this->getEmptyChangelist(); $this->changelist[StorageInterface::DEFAULT_COLLECTION] = $this->getEmptyChangelist();
if ($config_manager !== NULL) {
@trigger_error('The storage comparer does not need a config manager. The parameter is deprecated since version 8.7.0 and will be removed in 9.0.0. Omit the third parameter. See https://www.drupal.org/node/2993271.', E_USER_DEPRECATED);
}
} }
/** /**

View File

@ -339,11 +339,7 @@ class ConfigSingleImportForm extends ConfirmFormBase {
if (!$form_state->getErrors()) { if (!$form_state->getErrors()) {
$source_storage = new StorageReplaceDataWrapper($this->configStorage); $source_storage = new StorageReplaceDataWrapper($this->configStorage);
$source_storage->replaceData($config_name, $data); $source_storage->replaceData($config_name, $data);
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer($source_storage, $this->configStorage);
$source_storage,
$this->configStorage,
$this->configManager
);
if (!$storage_comparer->createChangelist()->hasChanges()) { if (!$storage_comparer->createChangelist()->hasChanges()) {
$form_state->setErrorByName('import', $this->t('There are no changes to import.')); $form_state->setErrorByName('import', $this->t('There are no changes to import.'));

View File

@ -180,7 +180,7 @@ class ConfigSync extends FormBase {
'#value' => $this->t('Import all'), '#value' => $this->t('Import all'),
]; ];
$source_list = $this->syncStorage->listAll(); $source_list = $this->syncStorage->listAll();
$storage_comparer = new StorageComparer($this->syncStorage, $this->activeStorage, $this->configManager); $storage_comparer = new StorageComparer($this->syncStorage, $this->activeStorage);
if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) { if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
$form['no_changes'] = [ $form['no_changes'] = [
'#type' => 'table', '#type' => 'table',
@ -199,7 +199,7 @@ class ConfigSync extends FormBase {
// A list of changes will be displayed, so check if the user should be // A list of changes will be displayed, so check if the user should be
// warned of potential losses to configuration. // warned of potential losses to configuration.
if ($this->snapshotStorage->exists('core.extension')) { if ($this->snapshotStorage->exists('core.extension')) {
$snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager); $snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage);
if (!$form_state->getUserInput() && $snapshot_comparer->createChangelist()->hasChanges()) { if (!$form_state->getUserInput() && $snapshot_comparer->createChangelist()->hasChanges()) {
$change_list = []; $change_list = [];
foreach ($snapshot_comparer->getAllCollectionNames() as $collection) { foreach ($snapshot_comparer->getAllCollectionNames() as $collection) {

View File

@ -136,8 +136,7 @@ class ConfigImportAllTest extends ModuleTestBase {
// Ensure that we have no configuration changes to import. // Ensure that we have no configuration changes to import.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->assertIdentical($storage_comparer->createChangelist()->getChangelist(), $storage_comparer->getEmptyChangelist()); $this->assertIdentical($storage_comparer->createChangelist()->getChangelist(), $storage_comparer->getEmptyChangelist());

View File

@ -38,8 +38,7 @@ class ConfigUninstallViaCliImportTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -40,8 +40,7 @@ class ContentTranslationConfigImportTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -39,8 +39,7 @@ class ConfigImportRecreateTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -44,8 +44,7 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -44,8 +44,7 @@ class ConfigImporterMissingContentTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -49,8 +49,7 @@ class ConfigImporterTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -38,13 +38,12 @@ class ConfigSnapshotTest extends KernelTestBase {
$active = $this->container->get('config.storage'); $active = $this->container->get('config.storage');
$sync = $this->container->get('config.storage.sync'); $sync = $this->container->get('config.storage.sync');
$snapshot = $this->container->get('config.storage.snapshot'); $snapshot = $this->container->get('config.storage.snapshot');
$config_manager = $this->container->get('config.manager');
$config_name = 'config_test.system'; $config_name = 'config_test.system';
$config_key = 'foo'; $config_key = 'foo';
$new_data = 'foobar'; $new_data = 'foobar';
$active_snapshot_comparer = new StorageComparer($active, $snapshot, $config_manager); $active_snapshot_comparer = new StorageComparer($active, $snapshot);
$sync_snapshot_comparer = new StorageComparer($sync, $snapshot, $config_manager); $sync_snapshot_comparer = new StorageComparer($sync, $snapshot);
// Verify that we have an initial snapshot that matches the active // Verify that we have an initial snapshot that matches the active
// configuration. This has to be true as no config should be installed. // configuration. This has to be true as no config should be installed.

View File

@ -52,8 +52,7 @@ class ContentEntityNullStorageTest extends KernelTestBase {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$config_importer = new ConfigImporter( $config_importer = new ConfigImporter(
$storage_comparer->createChangelist(), $storage_comparer->createChangelist(),

View File

@ -22,8 +22,7 @@ trait ConfigTestTrait {
// Set up the ConfigImporter object for testing. // Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer( $storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'), $this->container->get('config.storage.sync'),
$this->container->get('config.storage'), $this->container->get('config.storage')
$this->container->get('config.manager')
); );
$this->configImporter = new ConfigImporter( $this->configImporter = new ConfigImporter(
$storage_comparer, $storage_comparer,

View File

@ -22,11 +22,6 @@ class StorageComparerTest extends UnitTestCase {
*/ */
protected $targetStorage; protected $targetStorage;
/**
* @var \Drupal\Core\Config\ConfigManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configManager;
/** /**
* The storage comparer to test. * The storage comparer to test.
* *
@ -44,8 +39,7 @@ class StorageComparerTest extends UnitTestCase {
protected function setUp() { protected function setUp() {
$this->sourceStorage = $this->getMock('Drupal\Core\Config\StorageInterface'); $this->sourceStorage = $this->getMock('Drupal\Core\Config\StorageInterface');
$this->targetStorage = $this->getMock('Drupal\Core\Config\StorageInterface'); $this->targetStorage = $this->getMock('Drupal\Core\Config\StorageInterface');
$this->configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface'); $this->storageComparer = new StorageComparer($this->sourceStorage, $this->targetStorage);
$this->storageComparer = new StorageComparer($this->sourceStorage, $this->targetStorage, $this->configManager);
} }
protected function getConfigData() { protected function getConfigData() {
@ -244,4 +238,13 @@ class StorageComparerTest extends UnitTestCase {
$this->assertEmpty($this->storageComparer->getChangelist('delete')); $this->assertEmpty($this->storageComparer->getChangelist('delete'));
} }
/**
* @expectedDeprecation The storage comparer does not need a config manager. The parameter is deprecated since version 8.7.0 and will be removed in 9.0.0. Omit the third parameter. See https://www.drupal.org/node/2993271.
* @group legacy
*/
public function testConfigManagerDeprecation() {
$configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface');
new StorageComparer($this->sourceStorage, $this->targetStorage, $configManager);
}
} }