You are here

function mongodb_watchdog_uninstall in MongoDB 7

Same name and namespace in other branches
  1. 8.2 modules/mongodb_watchdog/mongodb_watchdog.install \mongodb_watchdog_uninstall()
  2. 8 mongodb_watchdog/mongodb_watchdog.install \mongodb_watchdog_uninstall()
  3. 6 mongodb_watchdog/mongodb_watchdog.install \mongodb_watchdog_uninstall()

Implements hook_uninstall().

Drop /all/ the watchdog collections.

File

mongodb_watchdog/mongodb_watchdog.install, line 27
MongoDB watchdog install file.

Code

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');
}