function workspace_update_field_storage_definitions in Workspace 8
Updates definitions of entity's type columns.
Parameters
string $entity_type_id: The type of entity.
string[] $columns: The list of column names.
string[] $tables: The list of tables to update the columns in.
Throws
\Exception
2 calls to workspace_update_field_storage_definitions()
- workspace_update_8106 in ./
workspace.install - Update workspace pointer name field again.
- workspace_update_8107 in ./
workspace.install - Make sure replication_status is a integer field type.
File
- ./
workspace.install, line 124 - Install, update and uninstall functions for the workspace module.
Code
function workspace_update_field_storage_definitions($entity_type_id, array $columns, array $tables) {
$database = \Drupal::database();
/* @var \Drupal\Core\Field\BaseFieldDefinition[] $base_field_definitions */
$base_field_definitions = \Drupal::service('entity_field.manager')
->getBaseFieldDefinitions($entity_type_id);
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$existing_data = [];
foreach ($tables as $table) {
// Store existing data in memory.
$data = $database
->select($table)
->fields($table)
->execute()
->fetchAll(\PDO::FETCH_ASSOC);
// Truncate the table to unfreeze modification of its schema only in
// case it's not empty.
if (!empty($data)) {
$database
->truncate($table)
->execute();
$existing_data[$table] = $data;
}
}
foreach ($columns as $column) {
$definition_update_manager
->updateFieldStorageDefinition($base_field_definitions[$column]);
}
// Put the data back into the table.
foreach ($existing_data as $table => $entries) {
foreach ($entries as $entry) {
$database
->insert($table)
->fields($entry)
->execute();
}
}
}