Skip to content
Snippets Groups Projects
Commit 0c8931dd authored by Angie Byron's avatar Angie Byron
Browse files

#986992 follow-up by yched, saintiss: Fix to field_sql_storage_update_7001().

parent 75a7c31c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -136,40 +136,42 @@ function field_sql_storage_update_7001(&$sandbox) {
$table = key($sandbox['tables']);
$type = array_shift($sandbox['tables']);
// Add the 'entity_type' column.
if (!db_field_exists($table, 'entity_type')) {
$column = array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type this data is attached to.',
);
db_add_field($table, 'entity_type', $column);
// Populate the 'entity_type' column based on the 'etid' column.
foreach ($sandbox['etids'] as $etid => $entity_type) {
db_update($table)
->fields(array('entity_type' => $entity_type))
->condition('etid', $etid)
->execute();
if (db_table_exists($table)) {
// Add the 'entity_type' column.
if (!db_field_exists($table, 'entity_type')) {
$column = array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type this data is attached to.',
);
db_add_field($table, 'entity_type', $column);
// Populate the 'entity_type' column based on the 'etid' column.
foreach ($sandbox['etids'] as $etid => $entity_type) {
db_update($table)
->fields(array('entity_type' => $entity_type))
->condition('etid', $etid)
->execute();
}
// Index the new column.
db_add_index($table, 'entity_type', array('entity_type'));
}
// Index the new column.
db_add_index($table, 'entity_type', array('entity_type'));
}
// Use the 'entity_type' column in the primary key.
db_drop_primary_key($table);
$primary_keys = array(
'data' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
'revision' => array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'),
);
db_add_primary_key($table, $primary_keys[$type]);
// Use the 'entity_type' column in the primary key.
db_drop_primary_key($table);
$primary_keys = array(
'data' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
'revision' => array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'),
);
db_add_primary_key($table, $primary_keys[$type]);
// Drop the 'etid' column.
if (db_field_exists($table, 'etid')) {
db_drop_field($table, 'etid');
// Drop the 'etid' column.
if (db_field_exists($table, 'etid')) {
db_drop_field($table, 'etid');
}
}
// Report progress.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment