Commit ae778f23 authored by q0rban's avatar q0rban Committed by jmuzz
Browse files

Issue #2141781 by segi, Jody Lynn, q0rban, jstoller, juampy: Fixed updates and...

Issue #2141781 by segi, Jody Lynn, q0rban, jstoller, juampy: Fixed updates and indexes for revision_id.
parent 44bec681
......@@ -276,7 +276,9 @@ function field_collection_update_7004() {
$revision_id_column = sprintf('%s_revision_id', $field_name);
// Add index on revision_id column.
db_add_index($table, $revision_id_column, array($revision_id_column));
if (!db_index_exists($table, $revision_id_column)) {
db_add_index($table, $revision_id_column, array($revision_id_column));
}
}
}
}
......@@ -300,3 +302,29 @@ function field_collection_update_7005() {
}
}
}
/**
* Ensures revision_id indexes are present at field_config table.
*/
function field_collection_update_7006() {
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE type = 'field_collection'");
foreach ($result as $field_config) {
$data = unserialize($field_config->data);
// Skip this record if the revision_id index is already present.
if (isset($data['indexes']['revision_id'])) {
continue;
}
// Otherwise, add the revision_id index and update the record.
$data['indexes']['revision_id'] = array('revision_id');
$data = serialize($data);
$num_updated = db_update('field_config')
->fields(array('data' => $data))
->condition('id', $field_config->id)
->execute();
// If for some reason the update failed, throw an exception.
if ($num_updated != 1) {
$t_args['@field'] = $field_config->field_name;
throw new DrupalUpdateException(t('An error was detected when attempting to update field configuration for field @field.', $t_args));
}
}
}
Markdown is supported
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