You are here

honeypot.install in Honeypot 6

Same filename and directory in other branches
  1. 8 honeypot.install
  2. 7 honeypot.install
  3. 2.0.x honeypot.install

Install, update and uninstall functions for the Honeypot module.

File

honeypot.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Honeypot module.
 */

/**
 * Implementation of hook_install().
 */
function honeypot_install() {
  $t = get_t();

  // Create tables.
  drupal_install_schema('honeypot');
  drupal_set_message($t("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
    '!link' => l($t('configure Honeypot'), 'admin/settings/honeypot'),
  )));
}

/**
 * Implementation of hook_uninstall().
 */
function honeypot_uninstall() {
  db_query("DELETE from {variable} WHERE name LIKE 'honeypot_%'");
  $cache_tables = array(
    'variables',
    'cache_bootstrap',
  );
  foreach ($cache_tables as $table) {
    if (db_table_exists($table)) {
      cache_clear_all($table, 'cache');
    }
  }

  // Remove tables.
  drupal_uninstall_schema('honeypot');
}

/**
 * Implementation of hook_schema().
 */
function honeypot_schema() {
  $schema['honeypot_user'] = array(
    'description' => 'Table that stores failed attempts to submit a form.',
    'fields' => array(
      'uid' => array(
        'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'timestamp' => array(
        'description' => 'Date/time when the form submission failed, as Unix timestamp.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'timestamp' => array(
        'timestamp',
      ),
    ),
  );
  return $schema;
}

/**
 * Update Honeypot user registration form variable.
 */
function honeypot_update_6100() {

  // Get the existing value of the user registration form protection.
  $user_registration_form_value = variable_get('honeypot_form_user_register_form', 0);

  // Delete the old variable.
  variable_del('honeypot_form_user_register_form');

  // Create a new variable with the value from the old variable.
  variable_set('honeypot_form_user_register', $user_registration_form_value);

  // Must at least return an empty array to prevent errors.
  return array();
}

/**
 * Add {honeypot_users} database table.
 */
function honeypot_update_6200() {
  $ret = array();
  $table = array(
    'description' => 'Table that stores failed attempts to submit a form.',
    'fields' => array(
      'uid' => array(
        'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'timestamp' => array(
        'description' => 'Date/time when the form submission failed, as Unix timestamp.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'timestamp' => array(
        'timestamp',
      ),
    ),
  );
  db_create_table($ret, 'honeypot_user', $table);
  return $ret;
}

Functions

Namesort descending Description
honeypot_install Implementation of hook_install().
honeypot_schema Implementation of hook_schema().
honeypot_uninstall Implementation of hook_uninstall().
honeypot_update_6100 Update Honeypot user registration form variable.
honeypot_update_6200 Add {honeypot_users} database table.