Skip to content

Instantly share code, notes, and snippets.

@rindevich
Created November 25, 2016 12:53
Show Gist options
  • Save rindevich/ce6e231e3b43b303304dfcbc35a8ab70 to your computer and use it in GitHub Desktop.
Save rindevich/ce6e231e3b43b303304dfcbc35a8ab70 to your computer and use it in GitHub Desktop.
<?php
/*
* Change type for existing Field. Drupal.
*/
$field = 'field_example';
db_change_field('field_data_' . $field, $field . '_value', $field . '_value', array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
));
db_change_field('field_revision_' . $field, $field . '_value', $field . '_value', array(
'type' => 'numeric',
'precision' => 10,
'scale' => 2,
'not null' => FALSE,
));
$s = db_query("SELECT * FROM {field_config} where field_name = :name", array(':name' => $field))->fetchObject();
$data = unserialize($s->data);
$data['settings'] = array(
'precision' => '10',
'scale' => '2',
'decimal_separator' => '.',
);
$data = serialize($data);
db_update('field_config')
->fields(array(
'data' => serialize($data),
'type' => 'number_decimal',
))
->condition('field_name', $field)
->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment