diff -u b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php --- b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -75,13 +75,6 @@ protected $database; /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** * Constructs a SqlContentEntityStorageSchema. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -102,36 +95,29 @@ } /** - * @return \Drupal\Core\State\StateInterface - */ - protected function state() { - if (!isset($this->state)) { - $this->state = \Drupal::state(); - } - return $this->state; - } - - /** * {@inheritdoc} */ public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) { return $entity_type->getStorageClass() != $original->getStorageClass() || + $entity_type->getKeys() != $original->getKeys() || $entity_type->isRevisionable() != $original->isRevisionable() || - $entity_type->isTranslatable() != $original->isTranslatable() || - // Detect changes in key or index definitions. - $this->getEntitySchemaData($entity_type, $this->getEntitySchema($entity_type, TRUE)) != $this->loadEntitySchemaData($original); + $entity_type->isTranslatable() != $original->isTranslatable(); } /** * {@inheritdoc} */ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { + $table_mapping = $this->storage->getTableMapping(); + return $storage_definition->hasCustomStorage() != $original->hasCustomStorage() || $storage_definition->getSchema() != $original->getSchema() || $storage_definition->isRevisionable() != $original->isRevisionable() || - $this->requiresFieldDataMigration($storage_definition, $original); + $storage_definition->isTranslatable() != $original->isTranslatable() || + $table_mapping->allowsSharedTableStorage($storage_definition) != $table_mapping->allowsSharedTableStorage($original) || + $table_mapping->requiresDedicatedTableStorage($storage_definition) != $table_mapping->requiresDedicatedTableStorage($original); } /** @@ -161,30 +147,7 @@ * {@inheritdoc} */ public function requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - // If the base table is empty, there are no entities, and therefore, no - // field data that we care about preserving. - if ($this->tableIsEmpty($this->storage->getBaseTable())) { - return FALSE; - } - - $table_mapping = $this->storage->getTableMapping(); - - // If the field changes its custom storage status, we will need to create or - // drop its schema. In any case we cannot migrate its data as custom storage - // is involved. Otherwise if a field is moved from a shared table to a - // dedicated table or viceversa we need a data migration. - $custom_storage = $storage_definition->hasCustomStorage() || $original->hasCustomStorage(); - $shared_table_changed = $table_mapping->allowsSharedTableStorage($storage_definition) != $table_mapping->allowsSharedTableStorage($original); - $dedicated_table_changed = $table_mapping->requiresDedicatedTableStorage($storage_definition) != $table_mapping->requiresDedicatedTableStorage($original); - if (!$custom_storage && ($shared_table_changed || $dedicated_table_changed)) { - return TRUE; - } - // If columns change we may need data manipulation, which we cannot handle. - if ($storage_definition->getColumns() != $original->getColumns()) { - return TRUE; - } - - return FALSE; + return !$this->storage->countFieldData($original, TRUE); } /** @@ -210,8 +173,6 @@ $this->createDedicatedTableSchema($field_storage_definition); } } - - $this->saveEntitySchemaData($entity_type, $schema); } /** @@ -698,32 +659,6 @@ } /** - * Loads stored schema data for the given entity type definition. - * - * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type - * The entity type definition. - * - * @return array - * The entity schema data array. - */ - protected function loadEntitySchemaData(ContentEntityTypeInterface $entity_type) { - return $this->state()->get('entity.schema.handler.' . $entity_type->id() . '.schema_data') ?: array(); - } - - /** - * Stores schema data for the given entity type definition. - * - * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type - * The entity type definition. - * @param array $schema - * The entity schema data array. - */ - protected function saveEntitySchemaData(ContentEntityTypeInterface $entity_type, $schema) { - $data = $this->getEntitySchemaData($entity_type, $schema); - $this->state()->set('entity.schema.handler.' . $entity_type->id() . '.schema_data', $data); - } - - /** * Initializes common information for a base table. * * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type diff -u b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php --- b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\ContentEntityType; use Drupal\Core\Entity\Sql\DefaultTableMapping; +use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema; use Drupal\Tests\UnitTestCase; /** @@ -1026,15 +1027,7 @@ ->method('schema') ->will($this->returnValue($db_schema_handler)); - $state = $this->getMock('Drupal\Core\State\StateInterface'); - $this->storageSchema = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema') - ->setConstructorArgs(array($this->entityManager, $this->entityType, $this->storage, $connection)) - ->setMethods(array('state')) - ->getMock(); - $this->storageSchema - ->expects($this->any()) - ->method('state') - ->will($this->returnValue($state)); + $this->storageSchema = new SqlContentEntityStorageSchema($this->entityManager, $this->entityType, $this->storage, $connection); } /** diff -u b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php --- b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -338,15 +338,7 @@ ->setMethods(array('getStorageSchema')) ->getMock(); - $state = $this->getMock('Drupal\Core\State\StateInterface'); - $schema_handler = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema') - ->setConstructorArgs(array($this->entityManager, $this->entityType, $storage, $this->connection)) - ->setMethods(array('state')) - ->getMock(); - $schema_handler - ->expects($this->any()) - ->method('state') - ->will($this->returnValue($state)); + $schema_handler = new SqlContentEntityStorageSchema($this->entityManager, $this->entityType, $storage, $this->connection); $storage ->expects($this->any())