spamicide.install in Spamicide 5
Same filename and directory in other branches
This module provides yet another tool to eliminate spam.
Author: Wes Roepken aka lipcpro (wes@lipcpro.com) Date: 04/13/2009
File
spamicide.installView source
<?php
/**
* @file
* This module provides yet another tool to eliminate spam.
*
* @ingroup spamicide
*
* Author: Wes Roepken aka lipcpro (wes@lipcpro.com)
* Date: 04/13/2009
*/
/**
* Implementation of hook_requirements().
*/
/*
function spamicide_requirements($phase) {
$requirements = array();
// Ensure translations don't break at install time.
$t = get_t();
if ($phase == 'runtime') {
$spamicide_directory = file_create_path() .'/spamicide';
if (!file_check_directory($spamicide_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
if (!is_dir($spamicide_directory)) {
$requirements['spamicide_directory'] = array(
'title' => $t('Spamicide Directory'),
'value' => $t('%p does not a directory or is not readable by the webserver.', array('%p' => $spamicide_directory)),
'severity' => REQUIREMENT_ERROR,
);
}
elseif (!is_writable($spamicide_directory)) {
$requirements['spamicide_directory'] = array(
'title' => $t('Spamicide Directory'),
'value' => $t('%p is not writeable by the webserver.', array('%p' => $spamicide_directory)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['spamicide_directory'] = array(
'title' => $t('Spamicide Directory'),
'value' => $t('An unknown error occured.'),
'description' => $t('An unknown error occured trying to verify %p is a directory and is writable.', array('%p' => $spamicide_directory)),
'severity' => REQUIREMENT_ERROR,
);
}
}
if (!is_writable(file_directory_temp())) {
$requirements['spamicide_directory'] = array(
'title' => $t('Spamicide Temp Directory'),
'value' => $t('%p is not writeable by the webserver.', array('%p' => file_directory_temp())),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
// */
/**
* Implementation of hook_install().
* Create the tables
* required for the spamicide module
*/
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');
}
}
function spamicide_uninstall() {
db_query("DROP TABLE {spamicide}");
db_query("DELETE FROM {variable} WHERE name LIKE 'spamicide_%'");
cache_clear_all('variables', 'cache');
}
Functions
Name | Description |
---|---|
spamicide_install | Implementation of hook_install(). Create the tables required for the spamicide module |
spamicide_uninstall |