Same name and namespace in other branches
  1. 8.9.x core/modules/simpletest/simpletest.module \simpletest_clean_database()

Removed prefixed tables from the database that are left over from crashed tests.

2 calls to simpletest_clean_database()
simpletest_clean_environment in modules/simpletest/simpletest.module
Remove all temporary database tables and directories.
simpletest_uninstall in modules/simpletest/simpletest.install
Implements hook_uninstall().

File

modules/simpletest/simpletest.module, line 565
Provides testing functionality.

Code

function simpletest_clean_database() {
  $tables = db_find_tables_d8(Database::getConnection()
    ->prefixTables('{simpletest}') . '%');
  $schema = drupal_get_schema_unprocessed('simpletest');
  $count = 0;
  foreach (array_diff_key($tables, $schema) as $table) {

    // Strip the prefix and skip tables without digits following "simpletest",
    // e.g. {simpletest_test_id}.
    if (preg_match('/simpletest\\d+.*/', $table, $matches)) {
      db_drop_table($matches[0]);
      $count++;
    }
  }
  if ($count > 0) {
    drupal_set_message(format_plural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.'));
  }
  else {
    drupal_set_message(t('No leftover tables to remove.'));
  }
}