Commit 619b2749 authored by catch's avatar catch

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

parent b5ff72a6
......@@ -2338,13 +2338,12 @@ function install_config_import_batch() {
\Drupal::configFactory()->getEditable('system.site')->set('uuid', $system_site['uuid'])->save();
// Create the storage comparer and the config importer.
$config_manager = \Drupal::service('config.manager');
$storage_comparer = new StorageComparer($sync, \Drupal::service('config.storage'), $config_manager);
$storage_comparer = new StorageComparer($sync, \Drupal::service('config.storage'));
$storage_comparer->createChangelist();
$config_importer = new ConfigImporter(
$storage_comparer,
\Drupal::service('event_dispatcher'),
$config_manager,
\Drupal::service('config.manager'),
\Drupal::service('lock.persistent'),
\Drupal::service('config.typed'),
\Drupal::service('module_handler'),
......@@ -2409,14 +2408,13 @@ function install_config_download_translations(&$install_state) {
function install_config_revert_install_changes() {
global $install_state;
$config_manager = \Drupal::service('config.manager');
$storage_comparer = new StorageComparer(\Drupal::service('config.storage.sync'), \Drupal::service('config.storage'), $config_manager);
$storage_comparer = new StorageComparer(\Drupal::service('config.storage.sync'), \Drupal::service('config.storage'));
$storage_comparer->createChangelist();
if ($storage_comparer->hasChanges()) {
$config_importer = new ConfigImporter(
$storage_comparer,
\Drupal::service('event_dispatcher'),
$config_manager,
\Drupal::service('config.manager'),
\Drupal::service('lock.persistent'),
\Drupal::service('config.typed'),
\Drupal::service('module_handler'),
......
......@@ -40,13 +40,6 @@ class StorageComparer implements StorageComparerInterface {
*/
protected $targetStorages;
/**
* The configuration manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
/**
* 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
* Storage object used to write configuration.
* @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
// raw configuration object are not costly.
$this->sourceCacheStorage = new MemoryBackend();
......@@ -111,8 +104,11 @@ public function __construct(StorageInterface $source_storage, StorageInterface $
$target_storage,
$this->targetCacheStorage
);
$this->configManager = $config_manager;
$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);
}
}
/**
......
......@@ -339,11 +339,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
if (!$form_state->getErrors()) {
$source_storage = new StorageReplaceDataWrapper($this->configStorage);
$source_storage->replaceData($config_name, $data);
$storage_comparer = new StorageComparer(
$source_storage,
$this->configStorage,
$this->configManager
);
$storage_comparer = new StorageComparer($source_storage, $this->configStorage);
if (!$storage_comparer->createChangelist()->hasChanges()) {
$form_state->setErrorByName('import', $this->t('There are no changes to import.'));
......
......@@ -180,7 +180,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t('Import all'),
];
$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()) {
$form['no_changes'] = [
'#type' => 'table',
......@@ -199,7 +199,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// A list of changes will be displayed, so check if the user should be
// warned of potential losses to configuration.
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()) {
$change_list = [];
foreach ($snapshot_comparer->getAllCollectionNames() as $collection) {
......
......@@ -136,8 +136,7 @@ public function testInstallUninstall() {
// Ensure that we have no configuration changes to import.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->assertIdentical($storage_comparer->createChangelist()->getChangelist(), $storage_comparer->getEmptyChangelist());
......
......@@ -38,8 +38,7 @@ protected function setUp() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -40,8 +40,7 @@ protected function setUp() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -39,8 +39,7 @@ protected function setUp() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -44,8 +44,7 @@ protected function setUp() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -44,8 +44,7 @@ protected function setUp() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -49,8 +49,7 @@ protected function setUp() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -38,13 +38,12 @@ public function testSnapshot() {
$active = $this->container->get('config.storage');
$sync = $this->container->get('config.storage.sync');
$snapshot = $this->container->get('config.storage.snapshot');
$config_manager = $this->container->get('config.manager');
$config_name = 'config_test.system';
$config_key = 'foo';
$new_data = 'foobar';
$active_snapshot_comparer = new StorageComparer($active, $snapshot, $config_manager);
$sync_snapshot_comparer = new StorageComparer($sync, $snapshot, $config_manager);
$active_snapshot_comparer = new StorageComparer($active, $snapshot);
$sync_snapshot_comparer = new StorageComparer($sync, $snapshot);
// Verify that we have an initial snapshot that matches the active
// configuration. This has to be true as no config should be installed.
......
......@@ -52,8 +52,7 @@ public function testDeleteThroughImport() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$config_importer = new ConfigImporter(
$storage_comparer->createChangelist(),
......
......@@ -22,8 +22,7 @@ protected function configImporter() {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
$this->container->get('config.storage')
);
$this->configImporter = new ConfigImporter(
$storage_comparer,
......
......@@ -22,11 +22,6 @@ class StorageComparerTest extends UnitTestCase {
*/
protected $targetStorage;
/**
* @var \Drupal\Core\Config\ConfigManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configManager;
/**
* The storage comparer to test.
*
......@@ -44,8 +39,7 @@ class StorageComparerTest extends UnitTestCase {
protected function setUp() {
$this->sourceStorage = $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->configManager);
$this->storageComparer = new StorageComparer($this->sourceStorage, $this->targetStorage);
}
protected function getConfigData() {
......@@ -244,4 +238,13 @@ public function testCreateChangelistUpdate() {
$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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment