diff --git a/core/lib/Drupal/Core/Config/ConfigUUIDException.php b/core/lib/Drupal/Core/Config/ConfigUUIDException.php new file mode 100644 index 0000000..72087f0 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigUUIDException.php @@ -0,0 +1,13 @@ +entityType) + ->condition('uuid', $entity->uuid()) + ->execute(); + $matched_entity = reset($matching_entities); + if (!empty($matched_entity) && ($matched_entity != $entity->id())) { + throw new ConfigUUIDException(sprintf('1 Attempt to save a configuration object %s with UUID %s when this UUID is already used for %s', $this->id(), $this->uuid(), $matched_entity)); + } + + if (!$entity->isNew()) { + $original = $this->loadUnchanged($entity->id()); + // Ensure that the UUID cannot be changed for an existing entity. + if ($original->uuid() != $entity->uuid()) { + throw new ConfigUUIDException(sprintf('2 Attempt to save a configuration entity %s with UUID %s when this entity already exists with UUID %s', $entity->id(), $entity->uuid(), $original->uuid())); + } + } } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStorageControllerTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStorageControllerTest.php new file mode 100644 index 0000000..efb9a14 --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStorageControllerTest.php @@ -0,0 +1,64 @@ + 'Configuration entity UUID conflict', + 'description' => 'Tests staging and importing config entities with IDs and UUIDs that match existing config.', + 'group' => 'Configuration', + ); + } + + /** + * Tests importing fields and instances with changed IDs or UUIDs. + */ + public function testUUIDConflict() { + $entity_type = 'config_test'; + $id = 'test_1'; + // Load the original field and instance entities. + entity_create($entity_type, array('id' => $id))->save(); + $entity = entity_load($entity_type, $id); + + $original_properties = $entity->getExportProperties(); + + // Override with a new UUID and try to save. + $uuid = new Uuid(); + $new_uuid = $uuid->generate(); + $entity->set('uuid', $new_uuid); + + try { + $entity->save(); + $this->fail('Exception thrown when attempting to save a configuration entity with a UUID that does not match the existing UUID.'); + } + catch (ConfigUUIDException $e) { + $this->pass(format_string('Exception thrown when attempting to save a configuration entity with a UUID that does not match existing data: %e.', array('%e' => $e))); + } + + // Ensure that the config entity was not corrupted. + $entity = entity_load('config_test', $entity->id(), TRUE); + $this->assertIdentical($entity->getExportProperties(), $original_properties); + } + +} diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php index 60f020e..969cad2 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php @@ -55,6 +55,13 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface { public $label; /** + * The UUID for this entity. + * + * @var string + */ + public $uuid = NULL; + + /** * The array of image effects for this image style. * * @var string