You are here

function apdqc_modules_uninstalled in Asynchronous Prefetch Database Query Cache 7

Implements hook_modules_uninstalled().

File

./apdqc.module, line 456
Asynchronous Prefetch Database Query Cache module.

Code

function apdqc_modules_uninstalled($modules) {

  // Check for orphaned cache*__truncated_table's.
  $table_names = array_keys(db_query('SHOW TABLE STATUS')
    ->fetchAllAssoc('Name'));
  foreach ($table_names as $key => $table_name) {
    if (strpos($table_name, 'cache') !== 0) {

      // Remove if not a cache table.
      unset($table_names[$key]);
      continue;
    }
    if (strpos(strrev($table_name), strrev('__truncated_table')) !== 0) {

      // Skip if table name doesn't end in __truncated_table.
      continue;
    }
    $base_table = substr($table_name, 0, strpos($table_name, '__truncated_table'));
    if (in_array($base_table, $table_names)) {

      // Remove if __truncated_table has a base a cache table.
      unset($table_names[$key]);
      continue;
    }

    // Kill the orphaned *__truncated_table from the DB.
    if (db_table_exists($table_name)) {
      db_drop_table($table_name);
    }
  }
}