Updating field settings with existing data

Here is short code how to update existing fields settings with data

 



db_change_field('field_data_field_price_regular', 'field_price_regular_value', 'field_price_regular_value', array(
  'type' => 'numeric',
  'precision' => 16,
  'scale' => 2,
  'not null' => FALSE,
));



// Manual database changes.
  db_query("UPDATE {field_config} SET type = 'number_decimal' WHERE field_name = 'field_price_regular'");
  db_change_field('field_data_field_price_regular', 'field_price_regular_value', 'field_price_regular_value', array(
    'type' => 'numeric',
    'precision' => '16',
    'scale' => '2',
  ));
  db_change_field('field_revision_field_price_regular', 'field_price_regular_value', 'field_price_regular_value', array(
    'type' => 'numeric',
    'precision' => '16',
    'scale' => '2',
  ));
  
    // we just need to add precision and scale to the field config settings:
    $data = unserialize(db_query("SELECT data FROM {field_config} WHERE field_name = 'field_price_regular'")->fetchField());
    $data['settings']['precision'] = 16;
    $data['settings']['scale'] = 2;

    db_update('field_config')
    ->fields(array('data' => serialize($data)))
    ->condition('field_name', 'field_price_regular')
    ->execute();
  
  // Clear caches.
  field_cache_clear(TRUE);

 

Wiki Tags: 

Povedali o nás

S ľudmi z HalfPixel sme nakoniec vždy našli vhodné riešenie, pre klienta aj pre nás.

Peter Potocar, BIgKids.sk

Nachádzate sa v okolí?

Ak ste neďaleko, príďte nás navštíviť.

Kontakt