diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 4a40a9e..b8f98d0 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -460,7 +460,7 @@ public function loadByProperties(array $values = array()) { * {@inheritdoc} */ public function getQuery($conjunction = 'AND') { - return \Drupal::entityQuery($this->getEntityTypeId(), $conjunction); + return \Drupal::service($this->getQueryServicename())->get($this->entityType, $conjunction); } } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 36459b7..0b1aeb9 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -179,17 +179,11 @@ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterfac */ public function requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original) { $original_storage_class = $original->getStorageClass(); - - // If the original storage class is different, then there might be existing - // entities in that storage even if the new storage's base table is empty. - if ($entity_type->getStorageClass() != $original_storage_class) { - if (!class_exists($original_storage_class)) { - return TRUE; - } - $original_storage = $this->entityManager->createHandlerInstance($original_storage_class, $original); - return $original_storage->hasData(); + if (!class_exists($original_storage_class)) { + return TRUE; } - return $this->storage->hasData(); + $original_storage = $this->entityManager->createHandlerInstance($original_storage_class, $original); + return $original_storage->hasData(); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index 32f0bd9..4aaa11a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -1062,13 +1062,13 @@ public function providerTestRequiresEntityDataMigration() { ->getMock(); $updated_entity_type_definition->expects($this->any()) ->method('getStorageClass') - ->willReturn('foo'); + ->willReturn('\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema'); // A class that exists, *any* class. $original_entity_type_definition = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeInterface') ->disableOriginalConstructor() ->getMock(); $original_entity_type_definition->expects($this->any()) ->method('getStorageClass') - ->willReturn('foo'); + ->willReturn('\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema'); // A class that exists, *any* class. $original_entity_type_definition_other_nonexisting = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeInterface') ->disableOriginalConstructor() ->getMock(); @@ -1084,15 +1084,15 @@ public function providerTestRequiresEntityDataMigration() { return [ // Case 1: same storage class, ::hasData() === TRUE. - [$updated_entity_type_definition, $original_entity_type_definition, TRUE, NULL, TRUE], + [$updated_entity_type_definition, $original_entity_type_definition, TRUE, TRUE], // Case 2: same storage class, ::hasData() === FALSE. - [$updated_entity_type_definition, $original_entity_type_definition, FALSE, NULL, FALSE], + [$updated_entity_type_definition, $original_entity_type_definition, FALSE, FALSE], // Case 3: different storage class, original storage class does not exist. - [$updated_entity_type_definition, $original_entity_type_definition_other_nonexisting, NULL, NULL, TRUE], + [$updated_entity_type_definition, $original_entity_type_definition_other_nonexisting, NULL, TRUE], // Case 4: different storage class, original storage class exists, ::hasData() === TRUE. - [$updated_entity_type_definition, $original_entity_type_definition_other_existing, NULL, TRUE, TRUE], + [$updated_entity_type_definition, $original_entity_type_definition_other_existing, TRUE, TRUE], // Case 5: different storage class, original storage class exists, ::hasData() === FALSE. - [$updated_entity_type_definition, $original_entity_type_definition_other_existing, NULL, FALSE, FALSE], + [$updated_entity_type_definition, $original_entity_type_definition_other_existing, FALSE, FALSE], ]; } @@ -1101,7 +1101,7 @@ public function providerTestRequiresEntityDataMigration() { * * @dataProvider providerTestRequiresEntityDataMigration */ - public function testRequiresEntityDataMigration($updated_entity_type_definition, $original_entity_type_definition, $storage_has_data, $original_storage_has_data, $migration_required) { + public function testRequiresEntityDataMigration($updated_entity_type_definition, $original_entity_type_definition, $original_storage_has_data, $migration_required) { $this->entityType = new ContentEntityType(array( 'id' => 'entity_test', 'entity_keys' => array('id' => 'id'), @@ -1115,10 +1115,9 @@ public function testRequiresEntityDataMigration($updated_entity_type_definition, ->method('hasData') ->willReturn($original_storage_has_data); - // Assert hasData() is not called when $storage_has_data === NULL. - $this->storage->expects($this->exactly(is_null($storage_has_data) ? 0 : 1)) - ->method('hasData') - ->willReturn($storage_has_data); + // Assert hasData() is never called on the new storage definition. + $this->storage->expects($this->never()) + ->method('hasData'); $connection = $this->getMockBuilder('Drupal\Core\Database\Connection') ->disableOriginalConstructor() diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 3af7076..3a37f90 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -1202,10 +1202,10 @@ public function testHasData() { ->getMock(); $factory->expects($this->once()) ->method('get') - ->with('entity_test', 'AND') + ->with($this->entityType, 'AND') ->willReturn($query); - $this->container->set('entity.query', $factory); + $this->container->set('entity.query.sql', $factory); $database = $this->getMockBuilder('Drupal\Core\Database\Connection') ->disableOriginalConstructor()