#986992 follow-up by yched, sun: Robustify upgrade path.
parent
15ec48062c
commit
2d9916e6f6
|
@ -113,27 +113,31 @@ function field_sql_storage_update_7001(&$sandbox) {
|
||||||
$sandbox['tables'] = array();
|
$sandbox['tables'] = array();
|
||||||
$results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
|
$results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
|
||||||
->fields('fc')
|
->fields('fc')
|
||||||
|
->condition('storage_module', 'field_sql_storage')
|
||||||
->execute();
|
->execute();
|
||||||
foreach ($results as $field) {
|
foreach ($results as $field) {
|
||||||
if ($field['deleted']) {
|
if ($field['deleted']) {
|
||||||
$sandbox['tables'][] = "field_deleted_data_{$field['id']}";
|
$sandbox['tables']["field_deleted_data_{$field['id']}"] = 'data';
|
||||||
$sandbox['tables'][] = "field_deleted_revision_{$field['id']}";
|
$sandbox['tables']["field_deleted_revision_{$field['id']}"] = 'revision';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sandbox['tables'][] = "field_data_{$field['field_name']}";
|
$sandbox['tables']["field_data_{$field['field_name']}"] = 'data';
|
||||||
$sandbox['tables'][] = "field_revision_{$field['field_name']}";
|
$sandbox['tables']["field_revision_{$field['field_name']}"] = 'revision';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reset($sandbox['tables']);
|
||||||
|
|
||||||
$sandbox['total'] = count($sandbox['tables']);
|
$sandbox['total'] = count($sandbox['tables']);
|
||||||
$sandbox['progress'] = 0;
|
$sandbox['progress'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sandbox['tables']) {
|
if ($sandbox['tables']) {
|
||||||
$table = array_pop($sandbox['tables']);
|
// Grab the next table to process.
|
||||||
|
$table = key($sandbox['tables']);
|
||||||
|
$type = array_shift($sandbox['tables']);
|
||||||
|
|
||||||
if (db_table_exists($table)) {
|
// Add the 'entity_type' column.
|
||||||
// Add the 'entity_type' column.
|
if (!db_field_exists($table, 'entity_type')) {
|
||||||
$column = array(
|
$column = array(
|
||||||
'type' => 'varchar',
|
'type' => 'varchar',
|
||||||
'length' => 128,
|
'length' => 128,
|
||||||
|
@ -151,12 +155,20 @@ function field_sql_storage_update_7001(&$sandbox) {
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add indexes for the 'entity_type' column.
|
// Index the new column.
|
||||||
db_drop_primary_key($table);
|
|
||||||
db_add_primary_key($table, array('entity_type', 'entity_id', 'deleted', 'delta', 'language'));
|
|
||||||
db_add_index($table, 'entity_type', array('entity_type'));
|
db_add_index($table, 'entity_type', array('entity_type'));
|
||||||
|
}
|
||||||
|
|
||||||
// Drop the 'etid' column.
|
// 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');
|
db_drop_field($table, 'etid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +190,25 @@ function field_sql_storage_update_7001(&$sandbox) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix primary keys in field revision data tables.
|
||||||
|
*/
|
||||||
|
function field_sql_storage_update_7002() {
|
||||||
|
$results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
|
||||||
|
->fields('fc')
|
||||||
|
->condition('storage_module', 'field_sql_storage')
|
||||||
|
->execute();
|
||||||
|
foreach ($results as $field) {
|
||||||
|
// Revision tables of deleted fields do not need to be fixed, since no new
|
||||||
|
// data is written to them.
|
||||||
|
if (!$field['deleted']) {
|
||||||
|
$table = "field_revision_{$field['field_name']}";
|
||||||
|
db_drop_primary_key($table);
|
||||||
|
db_add_primary_key($table, array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @} End of "defgroup field-updates-6.x-to-7.x"
|
* @} End of "defgroup field-updates-6.x-to-7.x"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -159,7 +159,6 @@ function _field_sql_storage_schema($field) {
|
||||||
'description' => 'The sequence number for this data item, used for multi-value fields',
|
'description' => 'The sequence number for this data item, used for multi-value fields',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// @todo Is the primary key needed at all ?
|
|
||||||
'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
|
'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
|
||||||
'indexes' => array(
|
'indexes' => array(
|
||||||
'entity_type' => array('entity_type'),
|
'entity_type' => array('entity_type'),
|
||||||
|
@ -196,12 +195,10 @@ function _field_sql_storage_schema($field) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the revision table. The primary key includes
|
// Construct the revision table.
|
||||||
// revision_id but not entity_id so that multiple revision loads can
|
|
||||||
// use the IN operator.
|
|
||||||
$revision = $current;
|
$revision = $current;
|
||||||
$revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})";
|
$revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})";
|
||||||
$revision['primary key'] = array('entity_type', 'revision_id', 'deleted', 'delta', 'language');
|
$revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language');
|
||||||
$revision['fields']['revision_id']['not null'] = TRUE;
|
$revision['fields']['revision_id']['not null'] = TRUE;
|
||||||
$revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';
|
$revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue