protected function SqlContentEntityStorageSchema::hasColumnChanges

protected SqlContentEntityStorageSchema::hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Compares schemas to check for changes in the column definitions.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: Current field storage definition.

\Drupal\Core\Field\FieldStorageDefinitionInterface $original: The original field storage definition.

Return value

bool Returns TRUE if there are schema changes in the column definitions.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 1946

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

protected function hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
  if ($storage_definition->getColumns() != $original->getColumns()) {
    // Base field definitions have schema data stored in the original
    // definition.
    return TRUE;
  }

  if (!$storage_definition->hasCustomStorage()) {
    $keys = array_flip($this->getColumnSchemaRelevantKeys());
    $definition_schema = $this->getSchemaFromStorageDefinition($storage_definition);
    foreach ($this->loadFieldSchemaData($original) as $table => $table_schema) {
      foreach ($table_schema['fields'] as $name => $spec) {
        $definition_spec = array_intersect_key($definition_schema[$table]['fields'][$name], $keys);
        $stored_spec = array_intersect_key($spec, $keys);
        if ($definition_spec != $stored_spec) {
          return TRUE;
        }
      }
    }
  }

  return FALSE;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Sql!SqlContentEntityStorageSchema.php/function/SqlContentEntityStorageSchema::hasColumnChanges/8.1.x