Commit 0cce36c6 authored by Marco Villegas's avatar Marco Villegas Committed by Marco Villegas
Browse files

Issue #695562: Remove local xapian database on uninstall.

parent 26d51033
Loading
Loading
Loading
Loading
+37 −0
Changes for xapian.install: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ function xapian_schema() {
 */
function xapian_uninstall() {
  drupal_uninstall_schema('xapian');
  _xapian_remove_db();

  variable_del('xapian_database_hostname');
  variable_del('xapian_database_path');
@@ -94,6 +95,42 @@ function xapian_requirements($phase) {
  );
}

/**
 * Remove xapian db if it's a local db.
 */
function _xapian_remove_db() {
  $database_type = variable_get('xapian_database_type', XAPIAN_LOCAL);
  $xapian_db = variable_get('xapian_database_path', file_directory_path() .'/xapian_database');
  $path = file_check_location($xapian_db);
  if ($database_type == XAPIAN_LOCAL) {
    _xapian_recursive_rmdir($path);
  }
}

/**
 * Helper to remove recursively a directory.
 */
function _xapian_recursive_rmdir($path) {
  if (file_exists($path) && is_dir($path)) {
    $iterator = new DirectoryIterator($path);
    foreach ($iterator as $fileinfo) {
      if (!$fileinfo->isDot()) {
        if ($fileinfo->isDir()) {
          _xapian_recursive_rmdir($fileinfo->getPathname());
        }
        else {
          if (!file_delete($fileinfo->getPathname())) {
            watchdog('xapian', "can not delete {$fileinfo->getPathname}");
          }
        }
      }
    }
    if (!rmdir($path)) {
      watchdog('xapian', "can not delete $path");
    }
  }
}

/**
 * Add 'indexed' column for tracking when content was last indexed.  This allows
 * us to isolate exactly which item fails on if we hit a redirect or run out of