diff --git a/core/lib/Drupal/Core/Config/StorageComparer.php b/core/lib/Drupal/Core/Config/StorageComparer.php index 39b6c52..1e72fb6 100644 --- a/core/lib/Drupal/Core/Config/StorageComparer.php +++ b/core/lib/Drupal/Core/Config/StorageComparer.php @@ -195,16 +195,24 @@ protected function addChangelistUpdate() { } } - public function addChangelistRename() { - // Renames will be present in both create and delete lists + /** + * Creates the rename changelist. + * + * The list of renames is created from the different source and target names + * with same uuid, these changes will be removed from the create and delete + * lists. For example, renamed content types should be not removed, but + * updated with the related nodes. + */ + protected function addChangelistRename() { + // Renames will be present in both create and delete lists. $create_uuids = array(); - foreach ($this->getSourceStorage()->readMultiple(array_diff($this->getSourceNames(), $this->getTargetNames())) as $create_id => $data) { + foreach ($this->getSourceStorage()->readMultiple(array_diff($this->sourceNames, $this->targetNames)) as $create_id => $data) { if (isset($data['uuid'])) { $create_uuids[$data['uuid']] = $create_id; } } $renames = array(); - foreach ($this->getTargetStorage()->readMultiple(array_diff($this->getTargetNames(), $this->getSourceNames())) as $delete_id => $data) { + foreach ($this->getTargetStorage()->readMultiple(array_diff($this->targetNames, $this->sourceNames)) as $delete_id => $data) { if (isset($data['uuid']) && isset($create_uuids[$data['uuid']])) { $renames[] = $delete_id . '::' . $create_uuids[$data['uuid']]; @@ -216,7 +224,6 @@ public function addChangelistRename() { } // Reverse the array until we can manage dependencies. $this->addChangeList('rename', array_reverse($renames)); - return $this; } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php index f862cce..7997d48 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php @@ -94,47 +94,5 @@ public function testRenamed() { //$this->configImporter->import(); } - public function testSameName() { - $type_name = Unicode::strtolower($this->randomName(16)); - $content_type = entity_create('node_type', array( - 'type' => $type_name, - 'name' => 'first node type', - )); - $content_type->save(); - /** @var \Drupal\Core\Config\StorageInterface $active */ - $active = $this->container->get('config.storage'); - /** @var \Drupal\Core\Config\StorageInterface $staging */ - $staging = $this->container->get('config.storage.staging'); - - $config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id(); - $this->copyConfig($active, $staging); - - // Change the machine name of the content type. This wil rename 5 configuration - // entities: the node type, the body field, the body field instance, the - // entity form display and the entity view displays for teaser and default. - $content_type->delete(); - $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.'); - // Recreate with the same type - this will have a different UUID. - $content_type = entity_create('node_type', array( - 'type' => $type_name, - 'name' => 'second node type', - )); - $content_type->save(); - - $this->configImporter->reset(); - $this->assertEqual(6, count($this->configImporter->getUnprocessed('create')), 'There are 6 configuration items to create.'); - $this->assertEqual(6, count($this->configImporter->getUnprocessed('delete')), 'There are 6 configuration items to delete.'); - $this->assertEqual(0, count($this->configImporter->getUnprocessed('update')), 'There are no configuration items to update.'); - $this->assertEqual(0, count($this->configImporter->getUnprocessed('rename')), 'There are no configuration items to rename.'); - - $this->configImporter->import(); - - // Verify that there is nothing more to import. - $this->assertFalse($this->configImporter->reset()->hasUnprocessedChanges()); - $content_type = entity_load('node_type', $type_name); - $this->assertEqual('first node type', $content_type->label()); - } - - }