You are here

function button_field_update_6101 in Button Field 6

Implementation of hook_update_N().

Need to create the columns associated with the last update

See also

button_field_update_6100()

File

./button_field.install, line 68
Notify CCK when this module is enabled, disabled, installed, and uninstalled so CCK can do any necessary preparation or cleanup.

Code

function button_field_update_6101() {
  $spec = array(
    'type' => 'int',
    'size' => 'tiny',
    'not null' => FALSE,
    'sortable' => FALSE,
    'views' => TRUE,
  );

  // end $spec
  // start by getting all of the button fields
  $ret = array();
  $field_result = db_query('SELECT field_name FROM {content_node_field} ' . 'WHERE type = \'%s\'', 'button_field');

  // iterate over each of the fields
  $field = db_fetch_array($field_result);
  while ($field !== FALSE) {

    // get the instances for this field
    $instance_result = db_query('SELECT type_name FROM {content_node_field_instance} ' . 'WHERE field_name = \'%s\'', $field['field_name']);

    // iterate over each of the instances, create the appropriate column
    $column = $field['field_name'] . '_value';
    $instance = db_fetch_array($instance_result);
    while ($instance !== FALSE) {

      // check to see if the column already exists
      $table = 'content_type_' . $instance['type_name'];
      if (db_column_exists($table, $column)) {

        // we want to drop the column because we're changing its type
        db_drop_field($ret, $table, $column);
      }

      // end if the columnd already exist
      db_add_field($ret, $table, $column, $spec);
      $instance = db_fetch_array($instance_result);
    }

    // end for each instance of the field
    $field = db_fetch_array($field_result);
  }

  // end for each field
  return $ret;
}