Index: spam.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/spam/Attic/spam.install,v retrieving revision 1.1.2.1.2.9.2.6 diff -u -p -r1.1.2.1.2.9.2.6 spam.install --- spam.install 26 Nov 2007 22:48:26 -0000 1.1.2.1.2.9.2.6 +++ spam.install 19 Feb 2008 20:46:53 -0000 @@ -2,112 +2,298 @@ // $Id: spam.install,v 1.1.2.1.2.9.2.6 2007/11/26 22:48:26 jeremy Exp $ /** + * spam database schema * + * @TODO: descriptions + */ +function spam_schema() { + $schema['spam_filters_errors'] = array( + 'fields' => array( + 'bid' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'disp-width' => '11' + ), + 'content_type' => array( + 'type' => 'varchar', + 'length' => '128', + 'not null' => TRUE, + 'default' => '' + ), + 'content_id' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => 0, + 'disp-width' => '11' + ), + 'content_hash' => array( + 'type' => 'char', + 'length' => '32', + 'not null' => TRUE, + 'default' => '' + ), + 'content' => array( + 'type' => 'text', + 'not null' => TRUE + ), + 'hostname' => array( + 'type' => 'varchar', + 'length' => '15', + 'not null' => TRUE, + 'default' => '' + ), + 'timestamp' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => 0, + 'disp-width' => '11' + ), + ), + 'primary key' => array('bid'), + 'unique keys' => array( + 'content_hash' => array('content_hash'), + 'content_id' => array('content_id', 'content_type') + ), + 'indexes' => array( + 'content_hash_2' => array('content_hash'), + 'content_type' => array('content_type'), + 'hostname' => array('hostname'), + 'timestamp' => array('timestamp') + ), + ); + $schema['spam_filters'] = array( + 'description' => t('Provides global configurations for all enabled spam filters.'), + 'fields' => array( + 'fid' => array( + 'description' => t('The primary identifier for a spam filter.'), + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'disp-width' => '11' + ), + 'gid' => array( + 'description' => t('Foreign key for {spam_filters_groups}.'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '11' + ), + 'name' => array( + 'description' => t('The filter name.'), + 'type' => 'varchar', + 'length' => '128', + 'not null' => TRUE, + 'default' => '' + ), + 'module' => array( + 'description' => t('The module this filter belongs to.'), + 'type' => 'varchar', + 'length' => '128', + 'not null' => TRUE, + 'default' => '' + ), + 'status' => array( + 'description' => t('Allows a filter to be enabled or disabled.'), + 'type' => 'int', + 'unsigned' => TRUE, + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '3' + ), + 'weight' => array( + 'description' => t('Allows filters to be ordered.'), + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '4' + ), + 'gain' => array( + 'description' => t('Allows you to minimize or amplify the effect of a given filter.'), + 'type' => 'int', + 'unsigned' => TRUE, + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '3' + ) + ), + 'primary key' => array('fid'), + 'indexes' => array( + 'gid' => array('gid'), + 'module' => array('module'), + 'name' => array('name'), + 'status' => array('status'), + 'weight' => array('weight') + ), + ); + $schema['spam_filters_groups'] = array( + 'description' => t('Group of spam filters.'), + 'fields' => array( + 'gid' => array( + 'description' => t('The primary identifier for a group of spam filters.'), + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'disp-width' => '11' + ), + 'name' => array( + 'description' => t('Name of this group.'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE, + 'default' => '' + ), + 'weight' => array( + 'description' => t('Allows filter groups to be ordered.'), + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '4' + ) + ), + 'primary key' => array('gid'), + 'indexes' => array( + 'weight' => array('weight') + ), + ); + $schema['spam_filters_groups_data'] = array( + 'description' => t('Granular per-content-type configurations for enabled spam filters.'), + 'fields' => array( + 'gid' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'disp-width' => '11' + ), + 'content_type' => array( + 'type' => 'varchar', + 'length' => '64', // NOTE: other definitions use 128! + 'not null' => TRUE, + 'default' => '' + ) + ), + 'primary key' => array('gid', 'content_type'), + 'indexes' => array( + 'content_type' => array('content_type') + ), + ); + $schema['spam_tracker'] = array( + 'description' => t('Tracks all filtered site content, included both spam and non-spam.'), + 'fields' => array( + 'sid' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'disp-width' => '11' + ), + 'content_type' => array( + 'type' => 'varchar', + 'length' => '128', + 'not null' => TRUE, + 'default' => '' + ), + 'content_id' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => 0, + 'disp-width' => '11' + ), + 'score' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => 0, + 'disp-width' => '4' + ), + 'hostname' => array( + 'type' => 'varchar', + 'length' => '15', + 'not null' => TRUE, + 'default' => '' + ), + 'timestamp' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => 0, + 'disp-width' => '11' + ) + ), + 'primary key' => array('sid'), + 'unique keys' => array( + 'content_id' => array('content_id', 'content_type') + ), + 'indexes' => array( + 'content_type' => array('content_type'), + 'hostname' => array('hostname'), + 'score' => array('score'), + 'timestamp' => array('timestamp') + ), + ); + $schema['spam_log'] = array( + 'description' => t('Logging mechanism similar to watchdog, but provides additional information specific to spam tracking.'); + 'fields' => array( + 'lid' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'disp-width' => '11' + ), + 'sid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '11' + ), + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'disp-width' => '10' + ), + 'log' => array( + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE, + 'default' => '' + ), + 'timestamp' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + 'default' => 0, + 'disp-width' => '11' + ) + ), + 'primary key' => array('lid'), + 'indexes' => array( + 'sid' => array('sid'), + 'timestamp' => array('timestamp')), + ); + return $schema; +} +/** + * install spam data tables */ function spam_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - // TODO: PostgreSQL support -- patches welcome! - 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} ( - fid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - gid INT(11) UNSIGNED DEFAULT '0' NOT NULL, - name VARCHAR(128) NOT NULL DEFAULT '', - module VARCHAR(128) NOT NULL DEFAULT '', - status TINYINT UNSIGNED DEFAULT '0' NOT NULL, - weight TINYINT DEFAULT '0' NOT NULL, - gain TINYINT UNSIGNED DEFAULT '0' NOT NULL, - PRIMARY KEY (fid), - KEY (gid), - KEY (name), - KEY (module), - KEY (status), - KEY (weight) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE {spam_filters_groups} ( - gid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL DEFAULT '', - weight TINYINT DEFAULT '0' NOT NULL, - PRIMARY KEY (gid), - KEY (weight) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE {spam_filters_groups_data} ( - gid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - content_type VARCHAR(64) NOT NULL DEFAULT '', - PRIMARY KEY (gid,content_type), - KEY (content_type) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - /** - * Tracks all filtered site content, included both spam and non-spam. - */ - db_query("CREATE TABLE {spam_tracker} ( - sid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - content_type VARCHAR(128) NOT NULL DEFAULT '', - content_id INT(11) UNSIGNED DEFAULT '0', - score INT(4) UNSIGNED DEFAULT '0', - hostname VARCHAR(15) NOT NULL DEFAULT '', - timestamp INT(11) UNSIGNED DEFAULT '0', - PRIMARY KEY (sid), - UNIQUE KEY (content_id,content_type), - KEY (content_type), - KEY (score), - KEY (hostname), - KEY (timestamp) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - /** - * - */ - db_query("CREATE TABLE {spam_filters_errors} ( - bid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - content_type VARCHAR(128) NOT NULL DEFAULT '', - content_id INT(11) UNSIGNED DEFAULT '0', - content_hash CHAR(32) NOT NULL DEFAULT '', - content TEXT NOT NULL, - hostname VARCHAR(15) NOT NULL DEFAULT '', - timestamp INT(11) UNSIGNED DEFAULT '0', - PRIMARY KEY (bid), - UNIQUE KEY (content_id,content_type), - UNIQUE KEY (content_hash), - KEY (content_type), - KEY (content_hash), - KEY (hostname), - KEY (timestamp) - ) 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} ( - lid int(11) UNSIGNED NOT NULL AUTO_INCREMENT, - sid INT(11) UNSIGNED NOT NULL DEFAULT '0', - uid int(10) UNSIGNED NOT NULL DEFAULT '0', - log varchar(255) NOT NULL DEFAULT '', - timestamp int(11) UNSIGNED DEFAULT '0', - PRIMARY KEY lid (lid), - KEY sid (sid), - KEY timestamp (timestamp) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - - } + drupal_install_schema('spam'); drupal_set_message(t('All required spam tables have been created.')); } -/** +/** * Completely uninstall the spam module. */ function spam_uninstall() { - $tables = array('spam_filters', 'spam_tracker', 'spam_log', 'spam_filters_groups', 'spam_filters_groups_data'); - foreach ($tables as $table) { - db_query('DROP TABLE {'. $table .'}'); - } + drupal_uninstall_schema('spam'); drupal_set_message(t('All spam module configuration data and tables have been deleted.')); -} - -?> +} \ No newline at end of file