mongodb_watchdog.install in MongoDB 7
Same filename and directory in other branches
MongoDB watchdog install file.
File
mongodb_watchdog/mongodb_watchdog.installView source
<?php
/**
* @file
* MongoDB watchdog install file.
*/
/**
* Implements hook_install().
*/
function mongodb_watchdog_install() {
mongodb_watchdog_ensure_indexes();
}
/**
* Implements hook_enable().
*/
function mongodb_watchdog_enable() {
mongodb_watchdog_ensure_indexes();
}
/**
* Implements hook_uninstall().
*
* Drop /all/ the watchdog collections.
*/
function mongodb_watchdog_uninstall() {
// This can happen if mongodb.module has already been disabled prior to
// uninstalling mongodb_watchdog.
if (!module_exists('mongodb')) {
drupal_load('module', 'mongodb');
}
// Drop the base watchdog collection.
$watchdog_name = variable_get('mongodb_watchdog', 'watchdog');
$watchdog = mongodb_collection($watchdog_name);
$watchdog
->drop();
// Then drop all watchdog event collections in all known database aliases.
$aliases = variable_get('mongodb_connections', array());
$aliases['default'] = TRUE;
$count = 0;
$regex = '/\\.watchdog_event_[[:xdigit:]]{32}$/';
foreach (array_keys($aliases) as $alias) {
$db = mongodb($alias);
foreach ($db
->listCollections() as $collection) {
if (preg_match($regex, $collection)) {
$collection
->drop();
$count++;
}
}
}
if ($count) {
drupal_set_message(format_plural($count, 'Dropped 1 watchdog collection', 'Dropped @count watchdog collections'));
}
variable_del('mongodb_watchdog');
variable_del('mongodb_watchdog_items');
}
/**
* Create an index for the watchdog table.
*
* This index is on <line, timestamp> instead of <function, line, timestamp>,
* because we write to this collection alot, and the smaller index on two
* numbers should be much faster to create than one with a string included.
*/
function mongodb_watchdog_ensure_indexes() {
$collection = mongodb_collection(variable_get('mongodb_watchdog', 'watchdog'));
// Index for adding/updating increments.
$index = array(
'line' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
// Index for admin page without filters.
$index = array(
'timestamp' => -1,
);
$collection
->ensureIndex($index);
// Index for admin page filtering by type.
$index = array(
'type' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
// Index for admin page filtering by severity.
$index = array(
'severity' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
// Index for admin page filtering by type and severity.
$index = array(
'type' => 1,
'severity' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
}
/**
* Changes a variable name that defines a collection to store events.
*/
function mongodb_watchdog_update_7000() {
$collection_name = variable_get('mongodb_collectionname', 'watchdog');
if ($collection_name !== 'watchdog') {
variable_set('mongodb_watchdog', $collection_name);
}
variable_del('mongodb_collectionname');
variable_del('mongodb_watchdog_collectionname');
}
Functions
Name | Description |
---|---|
mongodb_watchdog_enable | Implements hook_enable(). |
mongodb_watchdog_ensure_indexes | Create an index for the watchdog table. |
mongodb_watchdog_install | Implements hook_install(). |
mongodb_watchdog_uninstall | Implements hook_uninstall(). |
mongodb_watchdog_update_7000 | Changes a variable name that defines a collection to store events. |