mongodb_watchdog.install in MongoDB 6
File
mongodb_watchdog/mongodb_watchdog.install
View source
<?php
require_once dirname(__FILE__) . '/../mongodb.module';
function mongodb_watchdog_install() {
mongodb_watchdog_ensure_indexes();
}
function mongodb_watchdog_enable() {
mongodb_watchdog_ensure_indexes();
}
function mongodb_watchdog_uninstall() {
$watchdog_name = variable_get('mongodb_watchdog', 'watchdog');
$watchdog = mongodb_collection($watchdog_name);
$watchdog
->drop();
$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');
}
function mongodb_watchdog_ensure_indexes() {
$collection = mongodb_collection(variable_get('mongodb_watchdog', 'watchdog'));
$index = array(
'line' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
$index = array(
'timestamp' => -1,
);
$collection
->ensureIndex($index);
$index = array(
'type' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
$index = array(
'severity' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
$index = array(
'type' => 1,
'severity' => 1,
'timestamp' => -1,
);
$collection
->ensureIndex($index);
}
function mongodb_watchdog_update_6000() {
$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');
}