NodeStorageSchema
class NodeStorageSchema extends SqlContentEntityStorageSchema (View source)
Defines the node schema handler.
Traits
Provides dependency injection friendly methods for serialization.
Helper methods for EntityTypeListenerInterface.
Properties
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
from SqlContentEntityStorageSchema |
| protected EntityFieldManagerInterface | $entityFieldManager | The entity field manager service. |
from SqlContentEntityStorageSchema |
| protected ContentEntityTypeInterface | $entityType | The entity type this schema builder is responsible for. |
from SqlContentEntityStorageSchema |
| protected FieldStorageDefinitionInterface[] | $fieldStorageDefinitions | The storage field definitions for this entity type. |
from SqlContentEntityStorageSchema |
| protected SqlContentEntityStorage | $storage | The storage object for the given entity type. |
from SqlContentEntityStorageSchema |
| protected array | $schema | A static cache of the generated schema array. |
from SqlContentEntityStorageSchema |
| protected Connection | $database | The database connection to be used. |
from SqlContentEntityStorageSchema |
| protected KeyValueStoreInterface | $installedStorageSchema | The key-value collection for tracking installed storage schema. |
from SqlContentEntityStorageSchema |
| protected KeyValueStoreInterface | $updateBackupRepository | The key-value collection for tracking entity update backup repository. |
from SqlContentEntityStorageSchema |
| protected DeletedFieldsRepositoryInterface | $deletedFieldsRepository | The deleted fields repository. |
from SqlContentEntityStorageSchema |
Methods
{@inheritdoc}
Allows subscribers to prepare their schema before data copying.
Allows subscribers to do any cleanup necessary after data copying.
Copies entity data from the original storage to the temporary one.
Handles the case when an error occurs during the data copying step.
Constructs a SqlContentEntityStorageSchema.
Gets the keyvalue collection for tracking the installed schema.
Gets the deleted fields repository.
Gets the key/value collection for tracking the entity update backups.
Refreshes the table mapping with updated definitions.
Checks if the changes to the entity type requires storage schema changes.
Detects whether there is a change in the shared table structure.
Detects whether any table name got renamed in an entity type update.
Checks if the changes to the storage definition requires schema changes.
Gets the schema data for the given field storage definition.
Checks if existing data would be lost if the schema changes were applied.
Checks if existing data would be lost if the schema changes were applied.
Reacts to the update of the entity type.
Reacts to the creation of the fieldable entity type.
Gets a string to be used as a prefix for a temporary table mapping object.
Reacts to the creation of a field storage definition.
Reacts to the update of a field storage definition.
Reacts to the deletion of a field storage definition.
Performs final cleanup after all data of a field has been purged.
Returns a SELECT query suitable for inserting data into a dedicated table.
Checks that we are dealing with the correct entity type.
Gets the entity schema for the specified entity type.
Gets entity schema definitions for index and key definitions.
Gets an index schema array for a given field.
Gets a unique key schema array for a given field.
Gets field schema data for the given key.
Generates a safe schema identifier (name of an index, column name etc.).
Gets field foreign keys.
Loads stored schema data for the given entity type definition.
Stores schema data for the given entity type definition.
Deletes schema data for the given entity type definition.
Loads stored schema data for the given field storage definition.
Stores schema data for the given field storage definition.
Deletes schema data for the given field storage definition.
Initializes common information for a base table.
Initializes common information for a revision table.
Initializes common information for a data table.
Initializes common information for a revision data table.
Adds defaults to a table schema definition.
Processes the gathered schema for a base table.
Processes the gathered schema for a base table.
Processes the specified entity key.
Processes the schema for a field storage definition.
Performs the specified operation on a field.
Creates the schema for a field stored in a dedicated table.
Creates the schema for a field stored in a shared table.
Deletes the schema for a field stored in a dedicated table.
Deletes the schema for a field stored in a shared table.
Updates the schema for a field stored in a shared table.
Updates the schema for a field stored in a shared table.
Creates the specified entity schema indexes and keys.
Deletes the specified entity schema indexes and keys.
Checks whether a field property has NULL values.
Gets the schema for a single field definition.
Adds an index for the specified field to the given schema definition.
Adds a unique key for the specified field to the given schema definition.
Adds a foreign key for the specified field to the given schema definition.
Gets the SQL schema for a dedicated table.
Gets the name to be used for the given entity index.
Generates an index name for a field data table.
Checks whether a database table is non-existent or empty.
Compares schemas to check for changes in the column definitions.
Returns a list of column schema keys affecting data storage.
Creates an index, dropping it if already existing.
Creates a unique key, dropping it if already existing.
Typecasts values to proper datatypes.
Details
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)
{@inheritdoc}
protected
preUpdateEntityTypeSchema(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)
Allows subscribers to prepare their schema before data copying.
protected
postUpdateEntityTypeSchema(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)
Allows subscribers to do any cleanup necessary after data copying.
protected
copyData(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox)
Copies entity data from the original storage to the temporary one.
protected
handleEntityTypeSchemaUpdateExceptionOnDataCopy(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $sandbox)
Handles the case when an error occurs during the data copying step.
__construct(EntityTypeManagerInterface $entity_type_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database, EntityFieldManagerInterface $entity_field_manager)
Constructs a SqlContentEntityStorageSchema.
protected KeyValueStoreInterface
installedStorageSchema()
Gets the keyvalue collection for tracking the installed schema.
protected DeletedFieldsRepositoryInterface
deletedFieldsRepository()
Gets the deleted fields repository.
protected KeyValueStoreInterface
updateBackupRepository()
Gets the key/value collection for tracking the entity update backups.
protected DefaultTableMapping
getTableMapping(EntityTypeInterface $entity_type, array $storage_definitions = NULL)
Refreshes the table mapping with updated definitions.
bool
requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Checks if the changes to the entity type requires storage schema changes.
protected bool
hasSharedTableStructureChange(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Detects whether there is a change in the shared table structure.
protected bool
hasSharedTableNameChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Detects whether any table name got renamed in an entity type update.
bool
requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Checks if the changes to the storage definition requires schema changes.
protected array
getSchemaFromStorageDefinition(FieldStorageDefinitionInterface $storage_definition)
Gets the schema data for the given field storage definition.
bool
requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Checks if existing data would be lost if the schema changes were applied.
If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresEntityStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresEntityStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresEntityStorageSchemaChanges() is TRUE.
This function can return FALSE if any of these conditions apply:
- There are no existing entities for the entity type.
- There are existing entities, but the schema changes can be applied without losing their data (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
- The only entity data that would be lost are ones that are not valid for the new definition (e.g., if changing an entity type from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).
When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.
bool
requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Checks if existing data would be lost if the schema changes were applied.
If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresFieldStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresFieldStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresFieldStorageSchemaChanges() is TRUE.
This function can return FALSE if any of these conditions apply:
- There are no existing entities for the entity type to which this field is attached.
- There are existing entities, but none with existing values for this field.
- There are existing field values, but the schema changes can be applied without losing them (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
- The only field values that would be lost are ones that are not valid for the new definition (e.g., if changing a field from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).
When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.
onEntityTypeCreate(EntityTypeInterface $entity_type)
Reacts to the creation of the entity type.
onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Reacts to the update of the entity type.
onEntityTypeDelete(EntityTypeInterface $entity_type)
Reacts to the deletion of the entity type.
onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)
Reacts to the creation of the fieldable entity type.
static string
getTemporaryTableMappingPrefix(EntityTypeInterface $entity_type, array $field_storage_definitions, string $first_prefix_part = 'tmp_')
| internal |
Gets a string to be used as a prefix for a temporary table mapping object.
onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)
Reacts to the creation of a field storage definition.
onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Reacts to the update of a field storage definition.
onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)
Reacts to the deletion of a field storage definition.
finalizePurge(FieldStorageDefinitionInterface $storage_definition)
Performs final cleanup after all data of a field has been purged.
protected SelectInterface
getSelectQueryForFieldStorageDeletion(string $table_name, array $shared_table_field_columns, array $dedicated_table_field_columns, string $base_table = NULL)
Returns a SELECT query suitable for inserting data into a dedicated table.
protected bool
checkEntityType(EntityTypeInterface $entity_type)
Checks that we are dealing with the correct entity type.
protected array
getEntitySchema(ContentEntityTypeInterface $entity_type, bool $reset = FALSE)
Gets the entity schema for the specified entity type.
Entity types may override this method in order to optimize the generated schema of the entity tables. However, only cross-field optimizations should be added here; e.g., an index spanning multiple fields. Optimizations that apply to a single field have to be added via SqlContentEntityStorageSchema::getSharedTableFieldSchema() instead.
protected array
getEntitySchemaTables(TableMappingInterface $table_mapping)
Gets a list of entity type tables.
protected array
getEntitySchemaData(ContentEntityTypeInterface $entity_type, array $schema)
Gets entity schema definitions for index and key definitions.
protected array
getFieldIndexes(string $field_name, array $field_schema, array $column_mapping)
Gets an index schema array for a given field.
protected array
getFieldUniqueKeys(string $field_name, array $field_schema, array $column_mapping)
Gets a unique key schema array for a given field.
protected array
getFieldSchemaData(string $field_name, array $field_schema, array $column_mapping, string $schema_key)
Gets field schema data for the given key.
protected string
getFieldSchemaIdentifierName(string $entity_type_id, string $field_name, string|null $key = NULL)
Generates a safe schema identifier (name of an index, column name etc.).
protected array
getFieldForeignKeys(string $field_name, array $field_schema, array $column_mapping)
Gets field foreign keys.
protected array
loadEntitySchemaData(EntityTypeInterface $entity_type)
Loads stored schema data for the given entity type definition.
protected
saveEntitySchemaData(EntityTypeInterface $entity_type, array $schema)
Stores schema data for the given entity type definition.
protected
deleteEntitySchemaData(EntityTypeInterface $entity_type)
Deletes schema data for the given entity type definition.
protected array
loadFieldSchemaData(FieldStorageDefinitionInterface $storage_definition)
Loads stored schema data for the given field storage definition.
protected
saveFieldSchemaData(FieldStorageDefinitionInterface $storage_definition, array $schema)
Stores schema data for the given field storage definition.
protected
deleteFieldSchemaData(FieldStorageDefinitionInterface $storage_definition)
Deletes schema data for the given field storage definition.
protected array
initializeBaseTable(ContentEntityTypeInterface $entity_type)
Initializes common information for a base table.
protected array
initializeRevisionTable(ContentEntityTypeInterface $entity_type)
Initializes common information for a revision table.
protected array
initializeDataTable(ContentEntityTypeInterface $entity_type)
Initializes common information for a data table.
protected array
initializeRevisionDataTable(ContentEntityTypeInterface $entity_type)
Initializes common information for a revision data table.
protected
addTableDefaults($schema)
Adds defaults to a table schema definition.
protected array
processDataTable(ContentEntityTypeInterface $entity_type, array $schema)
Processes the gathered schema for a base table.
protected array
processRevisionDataTable(ContentEntityTypeInterface $entity_type, array $schema)
Processes the gathered schema for a base table.
protected
processIdentifierSchema(array $schema, string $key)
Processes the specified entity key.
protected
processFieldStorageSchema(array $field_storage_schema)
Processes the schema for a field storage definition.
protected
performFieldSchemaOperation(string $operation, FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original = NULL)
Performs the specified operation on a field.
This figures out whether the field is stored in a dedicated or shared table and forwards the call to the proper handler.
protected
createDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, bool $only_save = FALSE)
Creates the schema for a field stored in a dedicated table.
protected
createSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, bool $only_save = FALSE)
Creates the schema for a field stored in a shared table.
protected
deleteDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition)
Deletes the schema for a field stored in a dedicated table.
protected
deleteSharedTableSchema(FieldStorageDefinitionInterface $storage_definition)
Deletes the schema for a field stored in a shared table.
protected
updateDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Updates the schema for a field stored in a shared table.
protected
updateSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Updates the schema for a field stored in a shared table.
protected
createEntitySchemaIndexes(array $entity_schema, FieldStorageDefinitionInterface $storage_definition = NULL)
Creates the specified entity schema indexes and keys.
protected
deleteEntitySchemaIndexes(array $entity_schema_data, FieldStorageDefinitionInterface $storage_definition = NULL)
Deletes the specified entity schema indexes and keys.
protected bool
hasNullFieldPropertyData(string $table_name, string $column_name)
Checks whether a field property has NULL values.
protected array
getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, string $table_name, array $column_mapping)
Gets the schema for a single field definition.
Entity types may override this method in order to optimize the generated schema for given field. While all optimizations that apply to a single field have to be added here, all cross-field optimizations should be via SqlContentEntityStorageSchema::getEntitySchema() instead; e.g., an index spanning multiple fields.
protected
addSharedTableFieldIndex(FieldStorageDefinitionInterface $storage_definition, array $schema, bool $not_null = FALSE, int $size = NULL)
Adds an index for the specified field to the given schema definition.
protected
addSharedTableFieldUniqueKey(FieldStorageDefinitionInterface $storage_definition, array $schema)
Adds a unique key for the specified field to the given schema definition.
Also adds a 'not null' constraint, because many databases do not reliably support unique keys on null columns.
protected
addSharedTableFieldForeignKey(FieldStorageDefinitionInterface $storage_definition, array $schema, string $foreign_table, string $foreign_column)
Adds a foreign key for the specified field to the given schema definition.
protected array
getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ContentEntityTypeInterface $entity_type = NULL)
Gets the SQL schema for a dedicated table.
protected string
getEntityIndexName(ContentEntityTypeInterface $entity_type, string $index)
Gets the name to be used for the given entity index.
protected string
getFieldIndexName(FieldStorageDefinitionInterface $storage_definition, string $index)
Generates an index name for a field data table.
protected bool
isTableEmpty(string $table_name)
Checks whether a database table is non-existent or empty.
Empty tables can be dropped and recreated without data loss.
protected bool
hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Compares schemas to check for changes in the column definitions.
protected string[]
getColumnSchemaRelevantKeys()
Returns a list of column schema keys affecting data storage.
When comparing schema definitions, only changes in certain properties actually affect how data is stored and thus, if applied, may imply data manipulation.
protected
addIndex(string $table, string $name, array $specifier, array $schema)
Creates an index, dropping it if already existing.
protected
addUniqueKey(string $table, string $name, array $specifier)
Creates a unique key, dropping it if already existing.
static mixed
castValue(array $info, mixed $value)
| internal |
Typecasts values to proper datatypes.
MySQL PDO silently casts, e.g. FALSE and '' to 0, when inserting the value into an integer column, but PostgreSQL PDO does not. Use the schema information to correctly typecast the value.