You are here

function webform_update_7301 in Webform 7.3

Same name and namespace in other branches
  1. 7.4 webform.install \webform_update_7301()

Allow the confirmation format column to have a NULL value.

File

./webform.install, line 493
Webform module install/schema hooks.

Code

function webform_update_7301() {

  // These changes are modeled after user_update_7010().
  db_change_field('webform', 'confirmation_format', 'confirmation_format', array(
    'description' => 'The {filter_format}.format of the confirmation message.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));
  db_update('webform')
    ->fields(array(
    'confirmation_format' => NULL,
  ))
    ->condition('confirmation', '')
    ->condition('confirmation_format', 0)
    ->execute();
  $existing_formats = db_query("SELECT format FROM {filter_format}")
    ->fetchCol();
  $default_format = variable_get('filter_default_format', 1);

  // Since Webform may be updated separately from Drupal core, not all format
  // names may be numbers when running this update.
  $numeric_formats = array();
  foreach ($existing_formats as $format_name) {
    if (is_numeric($format_name)) {
      $numeric_formats[] = (int) $format_name;
    }
  }
  $query = db_update('webform')
    ->fields(array(
    'confirmation_format' => $default_format,
  ))
    ->isNotNull('confirmation_format');
  if (!empty($numeric_formats)) {
    $query
      ->condition('confirmation_format', $numeric_formats, 'NOT IN');
  }
  $query
    ->execute();
}