You are here

function webform_install in Webform 5.2

Same name and namespace in other branches
  1. 5 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()

Implementation of hook_install().

File

./webform.install, line 6

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        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');
  }
}