You are here

function mongodb_watchdog_uninstall in MongoDB 6

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. 7 mongodb_watchdog/mongodb_watchdog.install \mongodb_watchdog_uninstall()

Implements hook_uninstall().

Drop /all/ the watchdog collections.

File

mongodb_watchdog/mongodb_watchdog.install, line 29

Code

function mongodb_watchdog_uninstall() {

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