You are here

function webform_update_6308 in Webform 6.3

Convert "Include in e-mail" from the component-level to a per e-mail setting.

File

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

Code

function webform_update_6308() {
  $ret = array();

  // Add the new column to the e-mail table.
  db_add_field($ret, 'webform_emails', 'excluded_components', array(
    'type' => 'text',
    'not null' => TRUE,
    'initial' => '',
  ));

  // Build up our EXCLUSION lists, finding all components not in e-mails.
  $result = db_query("SELECT nid, cid FROM {webform_component} WHERE email = 0 ORDER BY nid");
  $nid = 0;
  $excluded_components = array();
  while ($row = db_fetch_object($result)) {
    if ($nid != $row->nid) {
      if (!empty($excluded_components)) {
        db_query("UPDATE {webform_emails} SET excluded_components = '%s' WHERE nid = %d", implode(',', $excluded_components), $nid);
      }
      $nid = $row->nid;
      $excluded_components = array();
    }
    $excluded_components[] = $row->cid;
  }

  // One last query for the last form in the list.
  if (!empty($excluded_components)) {
    db_query("UPDATE {webform_emails} SET excluded_components = '%s' WHERE nid = %d", implode(',', $excluded_components), $nid);
  }
  db_drop_field($ret, 'webform_component', 'email');
  return $ret;
}