You are here

function spam_install in Spam 5

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

Implementation of hook_install()

File

./spam.install, line 6

Code

function spam_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {spam_tracker} (\n        sid int(11) unsigned NOT NULL auto_increment,\n        source varchar(64) NOT NULL default '', # node, comment, trackback, etc...\n        id int(11) unsigned NOT NULL default '0',\n        probability int(2) unsigned default '0',\n        hostname varchar(128) NOT NULL default '', # source IP\n        hash char(32) NOT NULL default '',\n        timestamp int(11) unsigned default '0',\n        PRIMARY KEY sid (sid),\n        KEY id (id),\n        KEY probability (probability),\n        KEY source (source),\n        KEY hostname (hostname),\n        KEY hash (hash)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {spam_tokens} (\n        tid int(10) unsigned NOT NULL auto_increment,\n        token varchar(255) NOT NULL default '',\n        spam int(10) unsigned default '0',\n        notspam int(10) unsigned default '0',\n        probability int(10) unsigned default '0',\n        last int(11) unsigned default '0',\n        PRIMARY KEY tid (tid),\n        UNIQUE KEY token (token),\n        KEY spam (spam),\n        KEY notspam (notspam),\n        KEY probability (probability),\n        KEY last (last)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {spam_custom} (\n        scid int(10) unsigned NOT NULL auto_increment,\n        filter varchar(255) NOT NULL default '',\n        style int(2) unsigned default '0', # text, regex, URL\n        effect int(2) unsigned default '0',\n        action tinyint(2) unsigned default '0',\n        matches int(11) unsigned default '0',\n        last int(11) unsigned default '0',\n        PRIMARY KEY scid (scid),\n        KEY filter (filter),\n        KEY matches (matches),\n        KEY last (last)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {spam_reported} (\n        rid int(11) unsigned NOT NULL auto_increment,\n        source varchar(64) NOT NULL default '', # node, comment, trackback, etc...\n        id int(11) unsigned NOT NULL default '0',\n        uid int(10) unsigned NOT NULL default '0',\n        hostname varchar(128) NOT NULL default '', # source IP\n        feedback text NULL default '',\n        timestamp int(11) unsigned default '0',\n        PRIMARY KEY rid (rid),\n        KEY source (source),\n        KEY id (id),\n        KEY uid (uid)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {spam_log} (\n        sid int(11) unsigned NOT NULL auto_increment,\n        source varchar(64) NOT NULL default '', # node, comment, trackback, etc...\n        id int(11) unsigned NOT NULL default '0',\n        uid int(10) unsigned NOT NULL default '0',\n        hostname varchar(128) NOT NULL default '', # source IP\n        entry varchar(255) NOT NULL default '',\n        timestamp int(11) unsigned default '0',\n        PRIMARY KEY sid (sid),\n        KEY source (source),\n        KEY id (id),\n        KEY timestamp (timestamp)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
      db_query("INSERT INTO {spam_custom} VALUES (1, '/(adipex|cialis|phentermine|viagra)/i', 1, 1, 2, 0, 0)");
      db_query("INSERT INTO {spam_custom} VALUES (2, '/casino games|poker online|texas hold\\''em|texas holdem/i', 1, 0, 2, 0, 0)");
      db_query("INSERT INTO {spam_custom} VALUES (3, '/(american|casino|free|grand|online|party)(|-)?(blackjack|casino|gambling|poker)/i', 1, 0, 2, 0, 0)");
      db_query("INSERT INTO {spam_custom} VALUES (4, 'diet pill', 0, 0, 2, 0, 0)");
    case 'pgsql':
      db_query("CREATE TABLE {spam_tracker} (\n        sid serial PRIMARY KEY,\n        source varchar(64) NOT NULL default '',\n        id integer NOT NULL default 0,\n        probability smallint default 0,\n        hostname varchar(128) NOT NULL default '',\n        hash char(32) NOT NULL default '',\n        timestamp integer default 0\n      );");
      db_query("CREATE INDEX {spam_tracker}_id|_key ON {spam_tracker} (id);");
      db_query("CREATE INDEX {spam_tracker}_probability_key| ON {spam_tracker} (probability);");
      db_query("CREATE INDEX {spam_tracker}_source_key| ON {spam_tracker} (source);");
      db_query("CREATE INDEX {spam_tracker}_hostname_key} ON {spam_tracker} (hostname);");
      db_query("CREATE INDEX {spam_tracker}_hash_key} ON {spam_tracker} (hash);");
      db_query("CREATE TABLE {spam_tokens} (\n        tid serial PRIMARY KEY,\n        token varchar(255) NOT NULL default '',\n        spam integer DEFAULT 0 CONSTRAINT {spam_tokens_spam_unsigned} CHECK (spam >= 0),\n        notspam integer DEFAULT 0 CONSTRAINT {spam_tokens_notspam_unsigned} CHECK (notspam >= 0),\n        probability integer DEFAULT 1 CONSTRAINT {spam_tokens_probability_positive} CHECK (probability > 0),\n        last integer DEFAULT 0\n      );");
      db_query("CREATE UNIQUE INDEX (spam_tokens_token_key) ON {spam_tokens} (token);");
      db_query("CREATE INDEX (spam_tokens_spam_key) ON {spam_tokens} (spam);");
      db_query("CREATE INDEX (spam_tokens_notspam_key) ON {spam_tokens} (notspam);");
      db_query("CREATE INDEX (spam_tokens_probability_key} ON {spam_tokens} (probability);");
      db_query("CREATE INDEX spam_tokens_last_key ON {spam_tokens} (last);");
      db_query("CREATE TABLE {spam_custom} (\n        scid serial PRIMARY KEY,\n        filter varchar(255) NOT NULL default '',\n        style smallint default 0, -- text, regex, URL\n        effect smallint default 0, \n        action smallint default 0,\n        matches integer default 0,\n        last integer default 0\n      );");
      db_query("CREATE INDEX {spam_custom_filter_key} ON {spam_custom} (filter);");
      db_query("CREATE INDEX {spam_custom_matches_key} ON {spam_custom} (matches);");
      db_query("CREATE INDEX {spam_custom_last_key} ON {spam_custom} (last);");
      db_query("INSERT INTO {spam_custom} VALUES (1, '/(adipex|cialis|phentermine|viagra)/i', 1, 1, 2, 0, 0);");
      db_query("INSERT INTO {spam_custom} VALUES (2, '/casino games|poker online|texas hold''em|texas holdem/i', 1, 0, 2, 0, 0);");
      db_query("INSERT INTO {spam_custom} VALUES (3, '/(american|casino|free|grand|online|party)( |-)?(blackjack|casino|gambling|poker)/i', 1, 0, 2, 0, 0);");
      db_query("INSERT INTO {spam_custom} VALUES (4, 'diet pill', 0, 0, 2, 0, 0);");
      db_query("CREATE TABLE {spam_reported} (\n        rid serial PRIMARY KEY,\n        source varchar(64) NOT NULL default '',\n        id integer NOT NULL default 0,\n        uid integer NOT NULL default 0,\n        hostname varchar(128) NOT NULL default '',\n        feedback text NULL default '',\n        timestamp integer default 0\n      );");
      db_query("CREATE TABLE {spam_log} (\n        sid serial PRIMARY KEY,\n        source varchar(64) NOT NULL default '',\n        id integer NOT NULL default 0,\n        uid integer NOT NULL default 0,\n        hostname varchar(128) NOT NULL default '',\n        entry varchar(255) NOT NULL default '',\n        timestamp integer default 0\n      );");
      db_query("CREATE INDEX {spam_log_source_key} ON {spam_log} (source);");
      db_query("CREATE INDEX {spam_log_id_key} ON {spam_log} (id);");
      db_query("CREATE INDEX {spam_log_timestamp_key} ON {spam_log} (timestamp);");
  }
  drupal_set_message(t('All tables required by the spam module have been created.'));
}