You are here

function simpletest_clean_database in Zircon Profile 8.0

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

Removes prefixed tables from the database from crashed tests.

1 call to simpletest_clean_database()
simpletest_clean_environment in core/modules/simpletest/simpletest.module
Removes all temporary database tables and directories.

File

core/modules/simpletest/simpletest.module, line 590
Provides testing functionality.

Code

function simpletest_clean_database() {
  $tables = db_find_tables(Database::getConnection()
    ->prefixTables('{simpletest}') . '%');
  $schema = drupal_get_module_schema('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(\Drupal::translation()
      ->formatPlural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.'));
  }
  else {
    drupal_set_message(t('No leftover tables to remove.'));
  }
}