You are here

function faqfield_update_7120 in FAQ Field 7

Update database tables of the field for formatable text.

File

./faqfield.install, line 78
Install, update, and uninstall functions of faqfield module.

Code

function faqfield_update_7120() {

  // Specs of updated database fields.
  $updated = array(
    // The new answer format field, holding text formatting informations.
    'answer_format' => array(
      'type' => 'varchar',
      'length' => 255,
      'not null' => FALSE,
    ),
  );

  // Get all faqfields.
  $faqfields = field_read_fields(array(
    'type' => 'faqfield',
  ));

  // Iterate through all existing field tables and alter them as needed.
  foreach ($faqfields as $faqfield) {
    $field = field_info_field($faqfield['field_name']);
    if (isset($field['storage']['details']['sql'])) {
      $tables = $field['storage']['details']['sql'];

      // Iterate through current data tables.
      foreach ($tables['FIELD_LOAD_CURRENT'] as $data_table => $table_fields) {
        if (!db_field_exists($data_table, $field['field_name'] . '_answer_format')) {

          // Add new answer_format field.
          db_add_field($data_table, $field['field_name'] . '_answer_format', $updated['answer_format']);
        }
      }

      // Iterate through revision data tables.
      foreach ($tables['FIELD_LOAD_REVISION'] as $data_table => $table_fields) {
        if (!db_field_exists($data_table, $field['field_name'] . '_answer_format')) {

          // Add new answer_format field.
          db_add_field($data_table, $field['field_name'] . '_answer_format', $updated['answer_format']);
        }
      }
    }
  }
}