Skip to content

Instantly share code, notes, and snippets.

@plopesc
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plopesc/5cfccb1784d62bcb4e25 to your computer and use it in GitHub Desktop.
Save plopesc/5cfccb1784d62bcb4e25 to your computer and use it in GitHub Desktop.
Update the column structure for a field type.
<?php
/**
* Converts the value column from integer to float.
*/
function mymodule_update_70XX() {
$spec = array(
'type' => 'float',
'not null' => FALSE,
); // DB Column definition.
$field_name = 'your_field_name';
$field_column = 'your_column_name';
$fields = array_filter(field_info_fields(), function($item) use ($field_name) {
return $item['type'] == $field_name;
});
foreach ($fields as $field_definition) {
$data_table = 'field_data_' . $field_definition['field_name'];
$revision_table = 'field_revision_' . $field_definition['field_name'];
$field = $field_definition['field_name'] . '_' . $field_column;
db_change_field($data_table, $field, $field, $spec);
db_change_field($revision_table, $field, $field, $spec);
}
return t('Field structure updated.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment