function field_collection_update_7006 in Field collection 7
Ensures revision_id indexes are present at field_config table.
File
- ./
field_collection.install, line 316 - Install, update and uninstall functions for the field_collection module.
Code
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));
}
}
}