simpletest_clean_database

Versions
7
simpletest_clean_database()

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

Code

modules/simpletest/simpletest.module, line 421

<?php
function simpletest_clean_database() {
  $tables = db_find_tables(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.'));
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.