You are here

function spamicide_install in Spamicide 5

Same name and namespace in other branches
  1. 8 spamicide.install \spamicide_install()
  2. 6 spamicide.install \spamicide_install()
  3. 7 spamicide.install \spamicide_install()

Implementation of hook_install(). Create the tables required for the spamicide module

File

./spamicide.install, line 67
This module provides yet another tool to eliminate spam.

Code

function spamicide_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {spamicide} (\n        form_id varchar(128) NOT NULL,\n        form_field varchar(64) NOT NULL default 'feed_me',\n        enabled tinyint NOT NULL default 0,\n        removable tinyint NOT NULL default 1,\n        PRIMARY KEY (form_id)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $success = TRUE;
      break;
    case 'pgsql':
      db_query("CREATE TABLE {spamicide} (\n        form_id varchar(128) NOT NULL,\n        form_field varchar(64) NOT NULL default 'feed_me',\n        enabled smallint NOT NULL default 0,\n        removable smallint NOT NULL default 1,\n        PRIMARY KEY (form_id)\n        );");
      $success = TRUE;
      break;
    default:
      drupal_set_message(t('Unsupported database.'), 'error');
      $success = FALSE;
  }
  if ($success) {

    // insert some defaults
    $form_ids = array(
      'comment_form',
      'contact_mail_user',
      'contact_mail_page',
      'user_register',
      'user_pass',
      'user_login',
      'user_login_block',
    );
    foreach ($form_ids as $form_id) {
      db_query("INSERT INTO {spamicide} (form_id, enabled, removable) VALUES ('%s', 1, 0)", $form_id);
    }
    drupal_set_message(t('The installation of the spamicide table and some default entries was successful.'), 'status');
    drupal_set_message(t('You can now <a href="!spamicide_admin">configure the Spamicide module</a> for your site.', array(
      '!spamicide_admin' => url('admin/settings/spamicide'),
    )), 'status');
  }
  else {
    drupal_set_message(t('The installation of the SPAMICIDE module failed.'), 'error');
  }
}