You are here

function webform_install in Webform 5

Same name and namespace in other branches
  1. 5.2 webform.install \webform_install()
  2. 6.3 webform.install \webform_install()
  3. 6.2 webform.install \webform_install()
  4. 7.4 webform.install \webform_install()
  5. 7.3 webform.install \webform_install()

File

./webform.install, line 3

Code

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        redirect_post int(1) unsigned not null default '0',\n        submit_limit int(2)  not null default '-1',\n        submit_interval int(10) not null default '157784630',\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 int(10) unsigned NOT NULL default '0',\n        pid int(10) unsigned NOT NULL default '0',\n        form_key varchar(128) default NULL,\n        name varchar(128) default NULL,\n        type varchar(16) default NULL,\n        value text default NULL,\n        extra text,\n        mandatory int(2) unsigned default NULL,\n        weight int(2) default NULL,\n        PRIMARY KEY  (nid,cid)\n        ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
      $success = $success && db_query("CREATE TABLE if not exists {webform_submissions} (\n        nid int(10) unsigned NOT NULL default '0',\n        sid 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  (nid,sid),\n        KEY sid (sid)\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 int(10) unsigned NOT NULL default '0',\n        no int(10) unsigned NOT NULL default '0',\n        data longtext,\n        PRIMARY KEY  (nid,sid,cid,no),\n        KEY sid (sid)\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        redirect_post smallint NOT NULL default '0',\n        submit_limit smallint NOT NULL default '-1',\n        submit_interval integer NOT NULL default '157784630',\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 integer NOT NULL default '0',\n        pid integer NOT NULL default '0',\n        form_key varchar(128) default NULL,\n        name varchar(128) 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        weight smallint NOT NULL default '0',\n        PRIMARY KEY (nid,cid)\n        )");
      $success = $success && db_query("CREATE TABLE {webform_submissions} (\n        nid integer NOT NULL default '0',\n        sid serial UNIQUE,\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 (nid,sid)\n        )");
      $success = $success && db_query("CREATE INDEX {webform_submissions}_sid_idx ON {webform_submissions}(sid)");
      $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 integer NOT NULL default '0',\n        no integer NOT NULL default '0',\n        data text NOT NULL default '',\n        PRIMARY KEY (nid,sid,cid,no)\n        )");
      $success = $success && db_query("CREATE INDEX {webform_submitted_data}_sid_idx ON {webform_submitted_data}(sid)");
      break;
  }
  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');
  }
}