You are here

webform.install in Webform 5.2

File

webform.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function webform_install() {
  $success = TRUE;
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $success = $success && db_query("CREATE TABLE if not exists {webform} (\n        nid int(10) unsigned NOT NULL default '0',\n        confirmation text,\n        teaser tinyint not null default '0',\n        submit_text varchar(255) default NULL,\n        submit_limit tinyint  not null default '-1',\n        submit_interval int not null default '-1',\n        email varchar(255) default NULL,\n        email_from_name varchar(255) default NULL,\n        email_from_address varchar(255) default NULL,\n        email_subject varchar(255) default NULL,\n        additional_validate text default NULL,\n        additional_submit text default NULL,\n        PRIMARY KEY  (nid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      $success = $success && db_query("CREATE TABLE if not exists {webform_component} (\n        nid int(10) unsigned NOT NULL default '0',\n        cid smallint unsigned NOT NULL default '0',\n        pid smallint unsigned NOT NULL default '0',\n        form_key varchar(128) default NULL,\n        name varchar(255) default NULL,\n        type varchar(16) default NULL,\n        value text default NULL,\n        extra text,\n        mandatory tinyint NOT NULL default '0',\n        email tinyint NOT NULL default '0',\n        weight smallint NOT NULL default '0',\n        PRIMARY KEY  (nid, cid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      $success = $success && db_query("CREATE TABLE if not exists {webform_roles} (\n        nid int(10) unsigned NOT NULL default '0',\n        rid int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY (nid, rid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      $success = $success && db_query("CREATE TABLE if not exists {webform_submissions} (\n        sid int(10) unsigned NOT NULL default '0',\n        nid int(10) unsigned NOT NULL default '0',\n        uid int(10) unsigned NOT NULL default '0',\n        submitted int(11) NOT NULL default '0',\n        remote_addr varchar(128),\n        PRIMARY KEY (sid),\n        UNIQUE KEY sid_nid (sid, nid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      $success = $success && db_query("CREATE TABLE if not exists {webform_submitted_data} (\n        nid int(10) unsigned NOT NULL default '0',\n        sid int(10) unsigned NOT NULL default '0',\n        cid smallint unsigned NOT NULL default '0',\n        no tinyint unsigned NOT NULL default '0',\n        data longtext,\n        PRIMARY KEY  (sid, cid, no),\n        INDEX nid (nid),\n        INDEX sid_nid (sid, nid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      $success = $success && db_query("CREATE TABLE {webform} (\n        nid integer NOT NULL default '0',\n        confirmation text NOT NULL default '',\n        teaser smallint NOT NULL default '0',\n        submit_text varchar(255) default NULL,\n        submit_limit smallint NOT NULL default '-1',\n        submit_interval integer NOT NULL default '-1',\n        email varchar(255) NOT NULL default '',\n        email_from_name varchar(255) NOT NULL default '',\n        email_from_address varchar(255) NOT NULL default '',\n        email_subject varchar(255) NOT NULL default '',\n        additional_validate text default NULL,\n        additional_submit text default NULL,\n        PRIMARY KEY (nid)\n        )");
      $success = $success && db_query("CREATE TABLE {webform_component} (\n        nid integer NOT NULL default '0',\n        cid smallint NOT NULL default '0',\n        pid smallint NOT NULL default '0',\n        form_key varchar(128) default NULL,\n        name varchar(255) NOT NULL default '',\n        type varchar(16) NOT NULL default '',\n        value text NOT NULL default '',\n        extra text NOT NULL default '',\n        mandatory smallint NOT NULL default '0',\n        email smallint NOT NULL default '0',\n        weight smallint NOT NULL default '0',\n        PRIMARY KEY (nid, cid)\n        )");
      $success = $success && db_query("CREATE TABLE {webform_roles} (\n        nid integer NOT NULL default '0',\n        rid integer NOT NULL default '0',\n        PRIMARY KEY (nid, rid)\n        )");
      $success = $success && db_query("CREATE TABLE {webform_submissions} (\n        sid serial UNIQUE,\n        nid integer NOT NULL default '0',\n        uid integer NOT NULL default '0',\n        submitted integer NOT NULL default '0',\n        remote_addr varchar(128) NOT NULL default '',\n        PRIMARY KEY (sid)\n        )");
      $success = $success && db_query("CREATE UNIQUE INDEX {webform_submissions}_sid_nid_key ON {webform_submissions} (sid, nid)");
      $success = $success && db_query("CREATE TABLE {webform_submitted_data} (\n        nid integer NOT NULL default '0',\n        sid integer NOT NULL default '0',\n        cid smallint NOT NULL default '0',\n        no smallint NOT NULL default '0',\n        data text NOT NULL default '',\n        PRIMARY KEY  (sid, cid, no)\n        )");
      $success = $success && db_query("CREATE INDEX {webform_submitted_data}_nid_idx ON {webform_submitted_data} (sid)");
      $success = $success && db_query("CREATE INDEX {webform_submitted_data}_sid_nid_idx ON {webform_submitted_data} (sid, nid)");
      break;
  }
  $success = $success && db_query("UPDATE {system} SET weight = -1 WHERE name='webform' AND type='module'");
  if ($success) {
    drupal_set_message(t('Webform module installed module tables successfully.'));
  }
  else {
    drupal_set_message(t('The installation of webform module was unsuccessful.'), 'error');
  }
}

/**
 * Implementation of hook_uninstall().
 */
function webform_uninstall() {

  // Unset webform variables.
  variable_del('webform_use_cookies');
  variable_del('webform_debug');
  variable_del('webform_enable_fieldset');
  variable_del('webform_default_from_address');
  variable_del('webform_default_from_name');
  variable_del('webform_default_subject');
  variable_del('webform_csv_delimiter');
  $component_list = array();
  $path = drupal_get_path('module', 'webform') . '/components';
  $files = file_scan_directory($path, '^.*\\.inc$');
  foreach ($files as $filename => $file) {
    variable_del('webform_enable_' . $file->name, 1);
  }

  // Delete uploaded files.
  $filepath = file_create_path('webform');
  _webform_recursive_delete($filepath);

  // Drop tables.
  db_query("DROP TABLE {webform}");
  db_query("DROP TABLE {webform_component}");
  db_query("DROP TABLE {webform_roles}");
  db_query("DROP TABLE {webform_submissions}");
  db_query("DROP TABLE {webform_submitted_data}");
}

/**
 * Schema changes include component id's (cid) keys in the webform_component
 * and webform_submitted_data tables.
 */
function webform_update_1() {
  $ret = array();

  // Start the normal update.
  $ret[] = update_sql('CREATE TABLE {webform_tmp} ( ' . " nid int(10) unsigned NOT NULL default '0', " . " sid int(10) unsigned NOT NULL default '0', " . " cid int(10) unsigned NOT NULL default '0', " . " no int(10) unsigned NOT NULL default '0', " . ' data longtext, ' . ' PRIMARY KEY  (nid, sid, cid, no) ' . ')');
  $result = db_query('SELECT ws.nid, ws.sid, wc.cid, ws.name, ws.data ' . ' FROM {webform_submitted_data} ws, {webform_component} wc ' . ' WHERE ws.nid = wc.nid ' . ' AND ws.name = wc.name ');
  while ($row = db_fetch_object($result)) {
    $data = unserialize($row->data);
    if (is_array($data)) {
      foreach ($data as $k => $v) {
        db_query("INSERT INTO {webform_tmp} (nid, sid, cid, no, data) VALUES (%d, %d, %d, %d, '%s')", $row->nid, $row->sid, $row->cid, $k, $v);
      }
    }
    else {
      db_query("INSERT INTO {webform_tmp} (nid, sid, cid, no, data) VALUES (%d, %d, %d, %d, '%s')", $row->nid, $row->sid, $row->cid, 0, $row->data);
    }
  }
  $ret[] = update_sql('DROP TABLE {webform_submitted_data}');
  $ret[] = update_sql('ALTER TABLE {webform_tmp} RENAME TO {webform_submitted_data}');
  $ret[] = update_sql('CREATE TABLE {webform_submissions} ( ' . " nid int(10) unsigned NOT NULL default '0', " . " sid int(10) unsigned NOT NULL default '0', " . " submitted int(11) NOT NULL default '0', " . ' PRIMARY KEY (nid, sid) ' . ')');
  return $ret;
}

/**
 * Schema changes 2: Added redirect_post column in webform table.
 */
function webform_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {webform} ADD redirect_post int(1) UNSIGNED NOT NULL DEFAULT '0'");
      break;
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {webform} ADD redirect_post int(1) UNSIGNED NOT NULL DEFAULT '0' AFTER confirmation");
      break;
  }
  return $ret;
}

/**
 * Schema change 3: Update to UTF8
 */
function webform_update_3() {
  return _system_update_utf8(array(
    'webform',
    'webform_component',
    'webform_role_node',
    'webform_submissions',
    'webform_submitted_data',
  ));
}

/**
 * Schema change 4: Remove the webform_role_node table, node access can be handled by other modules made for this purpose.
 * Add additional columns to webform_submissions for recording of repeated submissions (IP Address, Browser, etc).
 * Add additional columns to webform for setting submission limitations
 * Change 'maintain webforms' permission into two seperate perms: 'edit webforms', 'access webform results'
 */
function webform_update_4() {
  $ret[] = update_sql('DROP TABLE if exists {webform_role_node}');
  $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD user varchar(128) AFTER submitted');
  $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD remote_addr varchar(128) AFTER user');
  $ret[] = update_sql("ALTER TABLE {webform} ADD submit_limit int(2) NOT NULL DEFAULT '-1' AFTER redirect_post");
  $ret[] = update_sql("ALTER TABLE {webform} ADD submit_interval int(10) NOT NULL DEFAULT '157784630' AFTER submit_limit");

  // 5 years in seconds.
  // Split 'maintain webforms' permissions into both 'edit webforms' and 'access webform results'.
  $result = db_query('SELECT rid, perm FROM {permission}');
  while ($row = db_fetch_object($result)) {
    if (strpos($row->perm, 'maintain webforms') !== FALSE) {
      $updated_perm = str_replace('maintain webforms', 'edit webforms, access webform results', $row->perm);
      db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $updated_perm, $row->rid);
    }
  }
  return $ret;
}

/**
 * Update MySQL sequence name to be cross-database compatible.
 */
function webform_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query('LOCK TABLES {sequences} WRITE');
      $ret[] = update_sql(sprintf("UPDATE {sequences} SET name = '%s' WHERE name = '%s'", db_prefix_tables('{webform_submissions}_sid'), db_prefix_tables('{webform_submissions}_id')));
      db_query('UNLOCK TABLES');
      break;
  }
  return $ret;
}

/**
 * Add a parent ID to all components, allowing nested fieldsets.
 */
function webform_update_6() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {webform_component} ADD pid integer NOT NULL DEFAULT '0'");
      break;
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql('ALTER TABLE {webform_component} ADD pid int(10) NOT NULL DEFAULT 0 AFTER cid');
      break;
  }
  return $ret;
}

/**
 * Allow much larger default values for components.
 */
function webform_update_7() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_change_column($ret, 'webform_component', 'value', 'value', 'TEXT', array(
        'not null' => FALSE,
        'default' => 'NULL',
      ));
      break;
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql('ALTER TABLE {webform_component} CHANGE value value TEXT NULL DEFAULT NULL');
      break;
  }
  return $ret;
}

/**
 * Add additional validate and submit processing columns.
 */
function webform_update_8() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      $ret[] = update_sql('ALTER TABLE {webform} ADD additional_validate text DEFAULT NULL');
      $ret[] = update_sql('ALTER TABLE {webform} ADD additional_submit text DEFAULT NULL');
      break;
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql('ALTER TABLE {webform} ADD additional_validate text DEFAULT NULL AFTER email_subject');
      $ret[] = update_sql('ALTER TABLE {webform} ADD additional_submit text DEFAULT NULL AFTER additional_validate');
      break;
  }
  return $ret;
}

/**
 * Remove webform version variable, now obsolete with schema and version numbers.
 * Split columns for email_from into email_from_address and email_from_name
 */
function webform_update_9() {
  variable_del('webform_version');
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_change_column($ret, 'webform', 'email_from', 'email_from_address', 'varchar(255)', array(
        'not null' => FALSE,
        'default' => 'NULL',
      ));
      $ret[] = update_sql('ALTER TABLE {webform} ADD email_from_name varchar(255) NULL DEFAULT NULL');
      break;
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql('ALTER TABLE {webform} CHANGE email_from email_from_address varchar(255) NULL DEFAULT NULL');
      $ret[] = update_sql('ALTER TABLE {webform} ADD email_from_name varchar(255) NULL DEFAULT NULL AFTER email');
      break;
  }
  return $ret;
}

/**
 * Add the form_key column to the webform_component table.
 */
function webform_update_10() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      $ret[] = update_sql('ALTER TABLE {webform_component} ADD form_key varchar(128) NULL DEFAULT NULL');
      break;
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql('ALTER TABLE {webform_component} ADD form_key varchar(128) NULL DEFAULT NULL AFTER pid');
      break;
  }
  return $ret;
}

/**
 * Add unique indexes on Submission IDs for faster joins.
 */
function webform_update_11() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {webform_submissions} ADD INDEX sid (sid)");
      $ret[] = update_sql("ALTER TABLE {webform_submitted_data} ADD INDEX sid (sid)");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE INDEX {webform_submissions}_sid_idx ON {webform_submissions}(sid)");
      $ret[] = update_sql("CREATE INDEX {webform_submitted_data}_sid_idx ON {webform_submitted_data}(sid)");
      break;
  }
  return $ret;
}

/**
 * Change 'user' column to 'uid' in webform_submissions table.
 */
function webform_update_12() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD uid int(10) NOT NULL DEFAULT 0 AFTER sid');
      $ret[] = update_sql('UPDATE {webform_submissions} ws set uid = (SELECT uid FROM {users} u WHERE u.name = ws.user)');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} DROP user');
      break;
    case 'pgsql':
      $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD uid integer NOT NULL DEFAULT 0');
      $ret[] = update_sql('UPDATE {webform_submissions} ws set uid = (SELECT uid FROM {users} u WHERE u.name = ws.user)');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} DROP user');
      break;
  }
  return $ret;
}

/**
 * Update to the 2.x version of webform.
 */
function webform_update_13() {
  $ret = array();

  // Set the webform weight to -1. This is needed to have webform's hook_menu()
  // take precedence over node_menu().
  $ret[] = update_sql("UPDATE {system} SET weight = -1 WHERE type = 'module' and name = 'webform'");

  // Ensure crufty submission data that was not removed when webform nodes
  // were deleted is cleared out before doing key changes.
  $ret[] = update_sql("DELETE FROM {webform} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
  $ret[] = update_sql("DELETE FROM {webform_component} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
  $ret[] = update_sql("DELETE FROM {webform_submissions} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");
  $ret[] = update_sql("DELETE FROM {webform_submitted_data} WHERE nid NOT IN (SELECT nid FROM {node} WHERE type = 'webform')");

  // Convert timestamp-based cids to small integers starting at 1 for each node.
  $result = db_query("SELECT nid, cid FROM {webform_component} ORDER BY nid ASC, cid ASC");
  $nid = 0;
  while ($component = db_fetch_array($result)) {
    if ($component['nid'] != $nid) {
      $nid = $component['nid'];
      $cid = 1;
    }
    $ret[] = update_sql("UPDATE {webform_component} SET cid = " . $cid . " WHERE nid = " . $nid . " AND cid = " . $component['cid']);
    $ret[] = update_sql("UPDATE {webform_component} SET pid = " . $cid . " WHERE nid = " . $nid . " AND pid = " . $component['cid']);
    $ret[] = update_sql("UPDATE {webform_submitted_data} SET cid = " . $cid . " WHERE nid = " . $nid . " AND cid = " . $component['cid']);
    $cid++;
  }

  // Convert the cid and pid columns to smallints for efficiency.
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {webform_component} CHANGE cid cid smallint unsigned NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {webform_component} CHANGE pid pid smallint unsigned NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {webform_submitted_data} CHANGE cid cid smallint unsigned NOT NULL default '0'");
      break;
    case 'pgsql':
      db_change_column($ret, 'webform_component', 'cid', 'cid', 'smallint', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_change_column($ret, 'webform_component', 'pid', 'pid', 'smallint', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_change_column($ret, 'webform_submitted_data', 'cid', 'cid', 'smallint', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      break;
  }
  return $ret;
}

/**
 * Variable name changes.
 */
function webform_update_14() {
  $ret = array();
  variable_set('webform_default_from_address', variable_get('webform_default_from_email', variable_get('site_mail', ini_get('sendmail_from'))));
  variable_del('webform_default_from_email');
  if ('Form submission from: ' == variable_get('webform_default_subject', 'Form submission from: ')) {
    variable_set('webform_default_subject', 'Form submission from: %title');
  }
  return $ret;
}

/**
 * Convert 'CC' option in extra column to simply 'email'.
 * Set email value to '%useremail' instead of 'user email'.
 * Change the 'disabled' option from an attributes option to an individual option.
 */
function webform_update_15() {
  $ret = array();
  $result = db_query("SELECT nid, cid, extra, value FROM {webform_component} WHERE type = 'email'");
  while ($row = db_fetch_array($result)) {
    $extra = unserialize($row['extra']);
    if ($extra['carboncopy']) {
      $extra['email'] = 1;
      unset($extra['carboncopy']);
    }
    $value = $row['value'] == 'user email' ? '%useremail' : '';
    db_query("UPDATE {webform_component} SET extra = '%s', value = '%s' WHERE nid = %d and cid = %d", serialize($extra), $value, $row['nid'], $row['cid']);
  }
  $result = db_query("SELECT nid, cid, extra FROM {webform_component} WHERE type IN ('email', 'textfield', 'textarea')");
  while ($row = db_fetch_array($result)) {
    $extra = unserialize($row['extra']);
    if ($extra['attributes']['disabled']) {
      $extra['disabled'] = 1;
      unset($extra['attributes']['disabled']);
      db_query("UPDATE {webform_component} SET extra = '%s' WHERE nid = %d and cid = %d", serialize($extra), $row['nid'], $row['cid']);
    }
  }
  return $ret;
}

/**
 * Add the submit button text and teaser columns. Remove redirect_post.
 */
function webform_update_16() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql('ALTER TABLE {webform} DROP redirect_post');
      $ret[] = update_sql('ALTER TABLE {webform} ADD teaser tinyint NOT NULL DEFAULT 0 AFTER confirmation');
      $ret[] = update_sql('ALTER TABLE {webform} ADD submit_text varchar(255) NULL DEFAULT NULL AFTER teaser');
      break;
    case 'pgsql':
      $ret[] = update_sql('ALTER TABLE {webform} DROP redirect_post');
      $ret[] = update_sql('ALTER TABLE {webform} ADD teaser smallint NOT NULL DEFAULT 0');
      $ret[] = update_sql('ALTER TABLE {webform} ADD submit_text varchar(255) NULL DEFAULT NULL');
      break;
  }
  return $ret;
}

/**
 * Set the submit interval to a real "unlimited" value instead of 5 years.
 */
function webform_update_17() {
  $ret = array();
  $ret[] = update_sql('UPDATE {webform} SET submit_interval = -1 WHERE submit_interval = 157784630');
  return $ret;
}

/**
 * Convert E-mail from name, address, and subject to integer values.
 */
function webform_update_18() {
  $ret = array();
  $result = db_query('SELECT * FROM {webform}');
  while ($webform = db_fetch_object($result)) {
    foreach (array(
      'email_from_name',
      'email_from_address',
      'email_subject',
    ) as $key) {
      if ($webform->{$key} == 'Automatic' || $webform->{$key} == 'Default') {
        $ret[] = update_sql('UPDATE {webform} SET ' . $key . " = 'default' WHERE nid = " . $webform->nid);
      }
      elseif (!is_numeric($webform->{$key})) {
        $cid = db_result(db_query("SELECT cid FROM {webform_component} WHERE name = '%s' AND nid = %d", $webform->{$key}, $webform->nid));
        if ($cid) {
          $ret[] = update_sql('UPDATE {webform} SET ' . $key . " = '" . $cid . "' WHERE nid = " . $webform->nid);
        }
      }
    }
  }
  return $ret;
}

/**
 * Upgrade hook to remove the captcha component.
 */
function webform_update_19() {
  $ret = array();
  variable_del('webform_enable_captcha');

  // Check for the new version of captcha module.
  if ($GLOBALS['db_type'] == 'pgsql') {
    $captcha_exists = db_result(db_query("SELECT table_name FROM {information_schema.tables} WHERE table_schema = 'public' AND table_name LIKE 'captcha_points'"));
  }
  else {
    $captcha_exists = db_result(db_query("SHOW TABLES LIKE 'captcha_points'"));
  }
  if (module_exists('image_captcha')) {
    $captcha_module = 'image_captcha';
    $captcha_type = 'Image';
  }
  else {
    $captcha_module = 'captcha';
    $captcha_type = 'Math';
  }
  $result = db_query("SELECT nid, cid FROM {webform_component} WHERE type = 'captcha'");
  while ($component = db_fetch_object($result)) {
    $ret[] = update_sql('DELETE FROM {webform_component} WHERE cid = ' . $component->cid . ' AND nid = ' . $component->nid);
    if ($captcha_exists) {
      $added = db_result(db_query("SELECT form_id FROM {captcha_points} WHERE form_id = 'webform_client_form_" . $component->nid . "'"));
      if (!$added) {
        $ret[] = update_sql("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('webform_client_form_" . $component->nid . "', '" . $captcha_module . "', '" . $captcha_type . "')");
      }
    }
  }
  return $ret;
}

/**
 * Set new primary keys for the submissions table.
 */
function webform_update_20() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':

      // Update the webform_submissions table with sid primary key instead of nid, sid.
      $ret[] = update_sql('ALTER TABLE {webform_submissions} DROP INDEX sid');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} DROP PRIMARY KEY');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD UNIQUE INDEX sid_nid (sid, nid)');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD PRIMARY KEY (sid)');

      // Update webform_submitted_data table removing nid from the primary key.
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} DROP PRIMARY KEY');
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} DROP INDEX sid');

      // While we've got these keys removed, decrease the size of the 'no' column.
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} CHANGE no no tinyint NOT NULL DEFAULT 0');
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} ADD PRIMARY KEY (sid, cid, no)');
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} ADD INDEX nid (nid)');
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} ADD INDEX sid_nid (sid, nid)');
      break;
    case 'pgsql':
      $ret[] = update_sql('ALTER TABLE {webform_submissions} DROP CONSTRAINT {webform_submissions}_pkey');
      $ret[] = update_sql('DROP INDEX {webform_submissions}_sid_idx');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD PRIMARY KEY (sid)');
      $ret[] = update_sql('ALTER TABLE {webform_submissions} ADD CONSTRAINT {webform_submissions}_sid_nid_key UNIQUE (sid, nid)');
      $ret[] = update_sql('DROP INDEX {webform_submitted_data}_sid_idx');
      db_change_column($ret, 'webform_submitted_data', 'no', 'no', 'smallint', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      $ret[] = update_sql('ALTER TABLE {webform_submitted_data} ADD PRIMARY KEY (sid, cid, no)');
      $ret[] = update_sql('CREATE INDEX {webform_submitted_data}_nid_idx ON {webform_submitted_data} (nid)');
      $ret[] = update_sql('CREATE INDEX {webform_submitted_data}_sid_nid_idx ON {webform_submitted_data} (sid, nid)');
      $ret[] = update_sql('ALTER TABLE {webform_component} ADD PRIMARY KEY (nid, cid)');
      break;
  }
  return $ret;
}

/**
 * Increase the size of the component instance name.
 */
function webform_update_5200() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {webform_component} CHANGE name name varchar(255) DEFAULT NULL");
      break;
    case 'pgsql':
      db_change_column($ret, 'webform_component', 'name', 'name', 'varchar(255)', array(
        'not null' => TRUE,
        'default' => "NULL",
      ));
      break;
  }
  return $ret;
}

/**
 * Add a column for email to the webform_component table.
 */
function webform_update_5201() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {webform_component} ADD email int(1) UNSIGNED NOT NULL DEFAULT '0'");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {webform_component} ADD email int NOT NULL DEFAULT '0'");
      break;
  }
  $ret[] = update_sql("UPDATE {webform_component} SET email = 1");
  return $ret;
}

/**
 * Per-webform submission access control based on roles.
 */
function webform_update_5202() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("CREATE TABLE {webform_roles} (\n        nid int(10) unsigned NOT NULL default '0',\n        rid int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY (nid, rid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {webform_roles} (\n        nid integer NOT NULL default '0',\n        rid integer NOT NULL default '0',\n        PRIMARY KEY (nid, rid)\n        )");
      break;
  }
  $result = db_query("SELECT nid FROM {node} WHERE type = 'webform'");
  while ($node = db_fetch_object($result)) {
    db_query("INSERT INTO {webform_roles} (nid, rid) VALUES (%d, 1)", $node->nid);
    db_query("INSERT INTO {webform_roles} (nid, rid) VALUES (%d, 2)", $node->nid);
  }
  return $ret;
}

/**
 * Cleanup filtering values used by the file component.
 *
 * Previously, file extensions were saved by category, exactly as the FormAPI
 * returned to the submit handler. All extensions are now stored in a single
 * array, including only valid extensions.
 */
function webform_update_5203() {
  $ret = array();
  $result = db_query("SELECT nid, cid, extra FROM {webform_component} WHERE type = 'file'");
  while ($component = db_fetch_object($result)) {
    $extra = unserialize($component->extra);
    $extensions = array();

    // Sanity check, set some defaults if no filtering is in place.
    if (!isset($extra['filtering']['types'])) {
      $extra['filtering']['types'] = array(
        'webimages' => drupal_map_assoc(array(
          'png',
          'gif',
          'jpg',
        )),
      );
    }

    // Defined types.
    foreach ($extra['filtering']['types'] as $category => $category_extensions) {
      foreach ((array) $category_extensions as $extension) {
        if (!is_numeric($extension)) {
          $extensions[] = $extension;
        }
      }
    }

    // Additional types.
    $additional_extensions = explode(',', $extra['filtering']['addextensions']);
    foreach ($additional_extensions as $extension) {
      $clean_extension = drupal_strtolower(trim($extension));
      if (!empty($clean_extension) && !in_array($clean_extension, $extensions)) {
        $extensions[] = $clean_extension;
      }
    }
    $extra['filtering']['types'] = $extensions;
    db_query("UPDATE {webform_component} SET extra = '%s' WHERE nid = %d AND cid = %d", serialize($extra), $component->nid, $component->cid);
  }
  return $ret;
}

/**
 * Recursively delete all files and folders in the specified filepath, then
 * delete the containing folder.
 *
 * Note that this only deletes visible files with write permission
 *
 * @param string $path
 *   A filepath relative to file_directory_path
 */
function _webform_recursive_delete($path) {
  if ($path) {
    $listing = $path . '/*';
    foreach (glob($listing) as $file) {
      if (is_file($file) === TRUE) {
        @unlink($file);
      }
      elseif (is_dir($file) === TRUE) {
        _webform_recursive_delete($file);
      }
    }
    @rmdir($path);
  }
}

Functions

Namesort descending Description
webform_install Implementation of hook_install().
webform_uninstall Implementation of hook_uninstall().
webform_update_1 Schema changes include component id's (cid) keys in the webform_component and webform_submitted_data tables.
webform_update_10 Add the form_key column to the webform_component table.
webform_update_11 Add unique indexes on Submission IDs for faster joins.
webform_update_12 Change 'user' column to 'uid' in webform_submissions table.
webform_update_13 Update to the 2.x version of webform.
webform_update_14 Variable name changes.
webform_update_15 Convert 'CC' option in extra column to simply 'email'. Set email value to '%useremail' instead of 'user email'. Change the 'disabled' option from an attributes option to an individual option.
webform_update_16 Add the submit button text and teaser columns. Remove redirect_post.
webform_update_17 Set the submit interval to a real "unlimited" value instead of 5 years.
webform_update_18 Convert E-mail from name, address, and subject to integer values.
webform_update_19 Upgrade hook to remove the captcha component.
webform_update_2 Schema changes 2: Added redirect_post column in webform table.
webform_update_20 Set new primary keys for the submissions table.
webform_update_3 Schema change 3: Update to UTF8
webform_update_4 Schema change 4: Remove the webform_role_node table, node access can be handled by other modules made for this purpose. Add additional columns to webform_submissions for recording of repeated submissions (IP Address, Browser, etc). Add additional…
webform_update_5 Update MySQL sequence name to be cross-database compatible.
webform_update_5200 Increase the size of the component instance name.
webform_update_5201 Add a column for email to the webform_component table.
webform_update_5202 Per-webform submission access control based on roles.
webform_update_5203 Cleanup filtering values used by the file component.
webform_update_6 Add a parent ID to all components, allowing nested fieldsets.
webform_update_7 Allow much larger default values for components.
webform_update_8 Add additional validate and submit processing columns.
webform_update_9 Remove webform version variable, now obsolete with schema and version numbers. Split columns for email_from into email_from_address and email_from_name
_webform_recursive_delete Recursively delete all files and folders in the specified filepath, then delete the containing folder.