Commit 39f13618 authored by mjd's avatar mjd Committed by fago
Browse files

Issue #1877800 by Matthew Davidson | wipeout_dude: Fixed Field collection...

Issue #1877800 by Matthew Davidson | wipeout_dude: Fixed Field collection Beta4 -> Beta5 upgrade fails.
parent fd1eaee6
......@@ -110,7 +110,10 @@ function field_collection_update_7001() {
// Set default to 0 temporarily.
'initial' => 0,
);
db_add_field('field_collection_item', 'revision_id', $revision_id_spec);
// Field may already exist due to bug in 7.x-1.0-beta5.
if (!db_field_exists('field_collection_item', 'revision_id')) {
db_add_field('field_collection_item', 'revision_id', $revision_id_spec);
}
// Initialize the revision_id to be the same as the item_id.
db_update('field_collection_item')
......@@ -124,7 +127,10 @@ function field_collection_update_7001() {
'not null' => TRUE,
'default' => 0,
);
db_add_field('field_collection_item', 'archived', $archived_spec);
// Field may already exist due to bug in 7.x-1.0-beta5.
if (!db_field_exists('field_collection_item', 'archived')) {
db_add_field('field_collection_item', 'archived', $archived_spec);
}
// Create the new table. It is important to explicitly define the schema here
// rather than use the hook_schema definition: http://drupal.org/node/150220.
......@@ -153,6 +159,10 @@ function field_collection_update_7001() {
),
),
);
// Table may already exist due to bug in 7.x-1.0-beta5.
if (db_table_exists('field_collection_item_revision')) {
db_drop_table('field_collection_item_revision');
}
db_create_table('field_collection_item_revision', $schema['field_collection_item_revision']);
// Fill the new table with the correct data.
......@@ -170,6 +180,10 @@ function field_collection_update_7001() {
}
// Update the field_collection_field_schema columns for all tables.
// Add a revision_id column.
$revision_id_spec['description'] = 'The field collection item revision id.';
// Because $value_column below can be null, so must $revision_id_column.
$revision_id_spec['not null'] = FALSE;
foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
$table_prefixes = array('field_data', 'field_revision');
foreach ($table_prefixes as $table_prefix) {
......@@ -178,9 +192,13 @@ function field_collection_update_7001() {
$value_column = sprintf('%s_value', $field_name);
$revision_id_column = sprintf('%s_revision_id', $field_name);
// Add a revision_id column.
$revision_id_spec['description'] = 'The field collection item revision id.';
db_add_field($table, $revision_id_column, $revision_id_spec);
// Field may already exist due to bug in 7.x-1.0-beta5.
if (!db_field_exists($table, $revision_id_column)) {
db_add_field($table, $revision_id_column, $revision_id_spec);
}
else {
db_change_field($table, $revision_id_column, $revision_id_column, $revision_id_spec);
}
// Initialize the revision_id to be the same as the item_id.
db_update($table)
......@@ -213,3 +231,32 @@ function field_collection_update_7002() {
drupal_set_message("Deleted $count orphaned field collection items.");
}
}
/**
* Update field_collection_field_schema columns for all tables.
*/
function field_collection_update_7003() {
// Revision_id column.
$revision_id_spec = array(
'type' => 'int',
'not null' => FALSE,
'description' => 'The field collection item revision id.',
'initial' => 0,
);
// Update the field_collection_field_schema columns for all tables,
// in case the buggy beta5 version of field_collection_update_7001()
// completed without complaint.
foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
$table_prefixes = array('field_data', 'field_revision');
foreach ($table_prefixes as $table_prefix) {
$table = sprintf('%s_%s', $table_prefix, $field_name);
$value_column = sprintf('%s_value', $field_name);
$revision_id_column = sprintf('%s_revision_id', $field_name);
db_change_field($table, $revision_id_column, $revision_id_column, $revision_id_spec);
}
}
// Need to get the system up-to-date so drupal_schema_fields_sql() will work.
$schema = drupal_get_schema('field_collection_item_revision', TRUE);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment