|
/** |
|
* Fix up the field collection tables in anticipation of field_collection_update_7002(). |
|
*/ |
|
function mymodule_update_7006() { |
|
// Add the archived column |
|
$archived_spec = array( |
|
'description' => 'Boolean indicating whether the field collection item is archived.', |
|
'type' => 'int', |
|
'not null' => TRUE, |
|
'default' => 0, |
|
); |
|
db_add_field('field_collection_item', 'archived', $archived_spec); |
|
return "Prep database for field_collection_update_7002()."; |
|
} |
|
|
|
/** |
|
* They went back to using value instead of item_id for the field schema. |
|
*/ |
|
function mymodule_update_7007() { |
|
$value_spec = array( |
|
'type' => 'int', |
|
'not null' => TRUE, |
|
'description' => 'The field collection item id.', |
|
// Set default to 0 temporarily. |
|
'initial' => 0, |
|
); |
|
|
|
// Update the field_collection_field_schema columns for all tables. |
|
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); |
|
$item_id_column = sprintf('%s_item_id', $field_name); |
|
$value_column = sprintf('%s_value', $field_name); |
|
|
|
// Add a value column. |
|
$value_spec['description'] = 'The field collection item id.'; |
|
db_add_field($table, $value_column, $value_spec); |
|
|
|
// Initialize the value to be the same as the item_id. |
|
db_update($table) |
|
->expression($value_column, $item_id_column) |
|
->execute(); |
|
} |
|
} |
|
return "Prep database for field_collection_update_7002()."; |
|
} |
|
|
|
/** |
|
* Drop the now-irrelevant item_id column to make debugging code that was using |
|
* the old structure easier. Also drop field_name from |
|
* field_collection_item_revision and add the index. |
|
*/ |
|
function mymodule_update_7008() { |
|
db_drop_field('field_collection_item_revision', 'field_name'); |
|
db_add_index('field_collection_item_revision', 'item_id', array('item_id')); |
|
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); |
|
$item_id_column = sprintf('%s_item_id', $field_name); |
|
|
|
db_drop_field($table, $item_id_column); |
|
} |
|
} |
|
return "Drop field_name from field_collection_item_revision, index item_id, |
|
add foreign key, and drop item_id columns from Field Collection field |
|
tables."; |
|
} |