You are here

function spam_install in Spam 5.3

Same name and namespace in other branches
  1. 5 spam.install \spam_install()
  2. 6 spam.install \spam_install()

File

./spam.install, line 6

Code

function spam_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
    default:

      /**
       * Provides global and granular per-content-type configurations for all
       * enabled spam filters.  The status allows a filter to be enabled or
       * disabled.  The weight allows filters to be ordered.  The gain allows
       * you to minimize or amplify the effect of a given filter.
       */
      db_query("CREATE TABLE {spam_filters} (\n        fid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        gid INT(11) UNSIGNED DEFAULT '0' NOT NULL,\n        name VARCHAR(128) NOT NULL DEFAULT '',\n        module VARCHAR(128) NOT NULL DEFAULT '',\n        status TINYINT UNSIGNED DEFAULT '0' NOT NULL,\n        weight TINYINT DEFAULT '0' NOT NULL,\n        gain TINYINT UNSIGNED DEFAULT '0' NOT NULL,\n        PRIMARY KEY fid (fid),\n        KEY gid (gid),\n        KEY name (name),\n        KEY module (module),\n        KEY status (status),\n        KEY weight (weight)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {spam_filters_groups} (\n        gid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        name VARCHAR(255) NOT NULL DEFAULT '',\n        weight TINYINT DEFAULT '0' NOT NULL,\n        PRIMARY KEY gid (gid),\n        KEY weight (weight)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {spam_filters_groups_data} (\n        gid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        content_type VARCHAR(64) NOT NULL DEFAULT '',\n        PRIMARY KEY gid_content_type (gid,content_type),\n        KEY content_type (content_type)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");

      /**
       * Tracks all filtered site content, included both spam and non-spam.
       */
      db_query("CREATE TABLE {spam_tracker} (\n        sid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        content_type VARCHAR(128) NOT NULL DEFAULT '',\n        content_id INT(11) UNSIGNED DEFAULT '0',\n        score INT(4) UNSIGNED DEFAULT '0',\n        hostname VARCHAR(15) NOT NULL DEFAULT '',\n        timestamp INT(11) UNSIGNED DEFAULT '0',\n        PRIMARY KEY sid (sid),\n        UNIQUE KEY content_id_content_type (content_id,content_type),\n        KEY content_type (content_type),\n        KEY score (score),\n        KEY hostname (hostname),\n        KEY timestamp (timestamp)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");

      /**
       *
       */
      db_query("CREATE TABLE {spam_filters_errors} (\n        bid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        uid INT(11) UNSIGNED NOT NULL DEFAULT '0',\n        content_type VARCHAR(128) NOT NULL DEFAULT '',\n        content_id INT(11) UNSIGNED DEFAULT '0',\n        content_hash CHAR(32) NOT NULL DEFAULT '',\n        content TEXT NOT NULL,\n        form TEXT NOT NULL,\n        feedback TEXT NOT NULL,\n        hostname VARCHAR(15) NOT NULL DEFAULT '',\n        timestamp INT(11) UNSIGNED DEFAULT '0',\n        PRIMARY KEY bid (bid),\n        KEY id_type (content_id,content_type),\n        UNIQUE KEY content_hash (content_hash),\n        KEY content_type (content_type),\n        KEY hostname (hostname),\n        KEY timestamp (timestamp)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");

      /**
       * Logging mechanism similar to watchdog, but provides additional
       * information specific to spam tracking.
       */
      db_query("CREATE TABLE {spam_log} (\n        lid int(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        trid int(11) UNSIGNED NOT NULL DEFAULT '0',\n        level int(2) UNSIGNED NOT NULL DEFAULT '0',\n        content_type VARCHAR(128) NULL DEFAULT '',\n        content_id INT(11) UNSIGNED DEFAULT '0',\n        uid int(10) UNSIGNED NOT NULL DEFAULT '0',\n        function varchar(255) NOT NULL DEFAULT '',\n        message varchar(255) NOT NULL DEFAULT '',\n        hostname VARCHAR(15) NOT NULL DEFAULT '',\n        timestamp int(11) UNSIGNED DEFAULT '0',\n        PRIMARY KEY lid (lid),\n        KEY trid (trid),\n        KEY content_type_content_id (content_type, content_id),\n        KEY message (message),\n        KEY uid (uid),\n        KEY hostname (hostname),\n        KEY timestamp (timestamp)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");

      /**
       * Spam statistics.
       */
      db_query("CREATE TABLE {spam_statistics} (\n        stid int(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n        name varchar(64) NOT NULL DEFAULT '',\n        count int(11) UNSIGNED NOT NULL DEFAULT '0',\n        timestamp int(11) UNSIGNED DEFAULT '0',\n        PRIMARY KEY stid (stid),\n        UNIQUE KEY name (name)\n      ) TYPE=MyISAM /* 40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':

      /**
       * tinyint (above) has usually been implemented as integer,
       * because of the following comment in pgsql docs:
       * "The type integer is the usual choice, as it offers the best
       * balance between range, storage size, and performance.
       * The smallint type is generally only used if disk space is at a premium.
       */
      db_query("CREATE TABLE {spam_filters} (\n\tfid serial PRIMARY KEY,\n\tgid integer NOT NULL default 0,\n\tname varchar(128) NOT NULL default '',\n\tmodule varchar(128) NOT NULL default '',\n\tstatus integer NOT NULL default 0,\n\tweight integer NOT NULL default 0,\n\tgain integer NOT NULL default 0\n      );");
      db_query("CREATE INDEX {spam_filters}_gid_key ON {spam_filters} (gid);");
      db_query("CREATE INDEX {spam_filters}_name_key ON {spam_filters} (name);");
      db_query("CREATE INDEX {spam_filters}_module_key ON {spam_filters} (module);");
      db_query("CREATE INDEX {spam_filters}_status_key ON {spam_filters} (status);");
      db_query("CREATE INDEX {spam_filters}_weight_key ON {spam_filters} (weight);");
      db_query("CREATE TABLE {spam_filters_groups} (\n        gid serial PRIMARY KEY,\n\tname varchar(255) NOT NULL default '',\n\tweight integer NOT NULL default 0\n      );");
      db_query("CREATE INDEX {spam_filters_groups}_weight_key ON {spam_filters_groups} (weight);");
      db_query("CREATE TABLE {spam_filters_groups_data} (\n\tgid serial,\n\tcontent_type varchar(64) NOT NULL default '',\n\tCONSTRAINT spam_filters_groups_data_pk PRIMARY KEY(gid,content_type)\n      );");
      db_query("CREATE INDEX {spam_filters_groups_data}_content_type_key ON {spam_filters_groups_data} (content_type);");

      /**
       * Tracks all filtered site content, included both spam and non-spam.
       */
      db_query("CREATE TABLE {spam_tracker} (\n\tsid serial PRIMARY KEY,\n\tcontent_type varchar(128) NOT NULL default '',\n\tcontent_id integer NOT NULL default 0,\n\tscore integer NOT NULL default 0,\n\thostname varchar(15) NOT NULL default '',\n\ttimestamp integer NOT NULL default 0,\n\tCONSTRAINT spam_tracker_u UNIQUE(content_id,content_type)\n      );");
      db_query("CREATE INDEX {spam_tracker}_u_key ON {spam_tracker} (content_id,content_type);");
      db_query("CREATE INDEX {spam_tracker}_content_type_key ON {spam_tracker} (content_type);");
      db_query("CREATE INDEX {spam_tracker}_score_key ON {spam_tracker} (score);");
      db_query("CREATE INDEX {spam_tracker}_hostname_key ON {spam_tracker} (hostname);");
      db_query("CREATE INDEX {spam_tracker}_timestamp_key ON {spam_tracker} (timestamp);");

      /**
       *
       */
      db_query("CREATE TABLE {spam_filters_errors} (\n\tbid serial PRIMARY KEY,\n\tcontent_type varchar(128) NOT NULL default '',\n\tcontent_id integer NOT NULL default 0,\n\tcontent_hash char(32) NOT NULL default '',\n        content text NOT NULL,\n        feedback text NOT NULL,\n\thostname varchar(15) NOT NULL default '',\n\ttimestamp integer NOT NULL default 0,\n\tCONSTRAINT spam_filters_errors_u1 UNIQUE(content_id,content_type),\n\tCONSTRAINT spam_filters_errors_u2 UNIQUE(content_hash)\n      );");
      db_query("CREATE INDEX {spam_filters_errors}_content_type_key ON {spam_filters_errors} (content_type);");
      db_query("CREATE INDEX {spam_filters_errors}_content_hash_key ON {spam_filters_errors} (content_hash);");
      db_query("CREATE INDEX {spam_filters_errors}_hostname_key ON {spam_filters_errors} (hostname);");
      db_query("CREATE INDEX {spam_filters_errors}_timestamp_key ON {spam_filters_errors} (timestamp);");

      /**
       * Logging mechanism similar to watchdog, but provides additional
       * information specific to spam tracking.
       */
      db_query("CREATE TABLE {spam_log} (\n\tlid serial PRIMARY KEY,\n        trid integer UNSIGNED NOT NULL DEFAULT '0',\n        level integer UNSIGNED NOT NULL DEFAULT '0',\n\tcontent_type varchar(128) NOT NULL default '',\n\tcontent_id integer NOT NULL default 0,\n\tfunction varchar(255) NOT NULL default '',\n\tuid integer NOT NULL default 0,\n\tmessage varchar(255) NOT NULL default '',\n\ttimestamp integer NOT NULL default 0\n      );");
      db_query("CREATE INDEX {spam_log}_sid_key ON {spam_log} (sid);");
      db_query("CREATE INDEX {spam_log}_trid_key ON {spam_log} (trid);");
      db_query("CREATE INDEX {spam_log}_timestamp_key ON {spam_log} (timestamp);");

      /**
       * Spam statistics.
       */
      db_query("CREATE TABLE {spam_statistics} (\n        stid serial PRIMARY KEY,\n        name varchar(64) NOT NULL DEFAULT '',\n        count integer UNSIGNED NOT NULL DEFAULT '0',\n        timestamp integer UNSIGNED DEFAULT '0',\n\tCONSTRAINT spam_statistics_u UNIQUE(name)\n      );");
      db_query("CREATE INDEX {spam_statistics}_u_key ON {spam_statistics} (name);");
      break;
  }
}