badbehavior.install in Bad Behavior 6.2
Same filename and directory in other branches
Install, update and uninstall functions for the Bad Behavior module.
File
badbehavior.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Bad Behavior module.
*/
/**
* Implements hook_schema().
*/
function badbehavior_schema() {
$schema['bad_behavior_log'] = array(
'description' => 'Stores hit logs for the Bad Behavior module.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'ip' => array(
'type' => 'text',
'not null' => TRUE,
),
'date' => array(
'type' => 'datetime',
'not null' => TRUE,
'default' => '1970-01-01 00:00:00',
),
'request_method' => array(
'type' => 'text',
'not null' => TRUE,
),
'request_uri' => array(
'type' => 'text',
'not null' => TRUE,
),
'server_protocol' => array(
'type' => 'text',
'not null' => TRUE,
),
'http_headers' => array(
'type' => 'text',
'not null' => TRUE,
),
'user_agent' => array(
'type' => 'text',
'not null' => TRUE,
),
'request_entity' => array(
'type' => 'text',
'not null' => TRUE,
),
'key' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
'indexes' => array(
'ip' => array(
array(
'ip',
15,
),
),
'user_agent' => array(
array(
'user_agent',
10,
),
),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function badbehavior_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
if (badbehavior_load_includes()) {
if (empty($base_url)) {
$base_url = $GLOBALS['base_url'];
}
if (BB2_VERSION == '2.2.15') {
$requirements['badbehavior'] = array(
'value' => BB2_VERSION,
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['badbehavior'] = array(
'value' => BB2_VERSION,
'severity' => REQUIREMENT_WARNING,
'description' => t('Bad Behavior files are installed, but are not the recommended version (2.2.15). See the <code>!readme</code> for exact installation details.', array(
'!readme' => l(t('README.txt'), $base_url . drupal_get_path('module', 'badbehavior') . '/README.txt'),
)),
);
}
}
else {
$requirements['badbehavior'] = array(
'value' => t('Missing BadBehavior library'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Required Bad Behavior files are not found. See the <code>!readme</code> for installation details.', array(
'!readme' => l(t('README.txt'), $base_url . drupal_get_path('module', 'badbehavior') . '/README.txt'),
)),
);
}
$requirements['badbehavior']['title'] = t('Bad Behavior');
}
return $requirements;
}
/**
* Implements hook_install().
*/
function badbehavior_install() {
drupal_install_schema('badbehavior');
// Set module weight for the badbehavior module
$thestatus = array();
$thestatus[] = db_query("UPDATE {system} SET weight = -999 WHERE type = 'module' AND name = 'badbehavior'");
// If there is one FALSE value in the status array, there was an error.
if (array_search(FALSE, $thestatus) !== FALSE) {
drupal_set_message(t('Setting the module weight of Bad Behavior failed.'), 'error');
}
}
/**
* Implements hook_uninstall().
*/
function badbehavior_uninstall() {
drupal_uninstall_schema('badbehavior');
variable_del('badbehavior_mail');
variable_del('badbehavior_email');
variable_del('badbehavior_logging');
variable_del('badbehavior_log_timeformat');
variable_del('badbehavior_strict');
variable_del('badbehavior_strict_mode_enable');
variable_del('badbehavior_offsite_forms');
variable_del('badbehavior_httpbl_age');
variable_del('badbehavior_httpbl_key');
variable_del('badbehavior_httpbl_quicklink');
variable_del('badbehavior_httpbl_quicklinktext');
variable_del('badbehavior_httpbl_threat');
variable_del('badbehavior_reverse_proxy');
variable_del('badbehavior_reverse_proxy_header');
variable_del('badbehavior_verbose_logging_enable');
variable_del('badbehavior_db_installed');
cache_clear_all('variables', 'cache');
}
/**
* Rename variables.
*
* Implements hook_update_N().
*/
function badbehavior_update_6100() {
$mail = variable_get('badbehavior_email', variable_get('site_mail', ini_get('sendmail_from')));
variable_set('badbehavior_mail', $mail);
variable_del('badbehavior_email');
$verbose = variable_get('badbehavior_verbose_logging_enable', 0);
variable_set('badbehavior_logging', $verbose ? 'verbose' : 1);
variable_del('badbehavior_verbose_logging_enable');
$strict = variable_get('badbehavior_strict_mode_enable', 0);
variable_set('badbehavior_strict', $strict);
variable_del('badbehavior_strict_mode_enable');
return array();
}
/**
* Reset module weight for earliest possible loading position.
*
* Implements hook_update_N().
*/
function badbehavior_update_6200() {
$retfun = array();
$retfun[] = update_sql("UPDATE {system} SET weight = -999 WHERE type = 'module' AND name = 'badbehavior'");
return $retfun;
}
Functions
Name![]() |
Description |
---|---|
badbehavior_install | Implements hook_install(). |
badbehavior_requirements | Implements hook_requirements(). |
badbehavior_schema | Implements hook_schema(). |
badbehavior_uninstall | Implements hook_uninstall(). |
badbehavior_update_6100 | Rename variables. |
badbehavior_update_6200 | Reset module weight for earliest possible loading position. |