You are here

vat_number.install in VAT Number 7

File

vat_number.install
View source
<?php

/*
 * Implementation of hook_field_schema()
 * http://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_schema/7
 */
function vat_number_field_schema($field) {
  $columns = array(
    'value' => array(
      'description' => 'VAT Number',
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
    ),
  );
  $indexes = array(
    'value' => array(
      'value',
    ),
  );
  return array(
    'columns' => $columns,
    'indexes' => $indexes,
  );
}

/**
 * Change column from _vat_number to _value.
 */
function vat_number_update_7001(&$sandbox = NULL) {
  $ret = array();
  $fields = array();
  foreach (field_info_fields() as $field) {
    if ($field['type'] == 'vat_number') {
      $fields[] = $field;
    }
  }
  foreach ($fields as $field) {
    $tables = array(
      _field_sql_storage_tablename($field),
      _field_sql_storage_revision_tablename($field),
    );
    foreach ($tables as $table) {
      $field_name = $field['field_name'];
      $column_old = $field_name . '_vat_number';
      $column_new = $field_name . '_value';
      $spec = array(
        'description' => 'Vat Number',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      );
      db_change_field($table, $column_old, $column_new, $spec);

      // old and new col are same
    }
  }
  return t('Database column name updated.');
}

Functions

Namesort descending Description
vat_number_field_schema
vat_number_update_7001 Change column from _vat_number to _value.