]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21015 - prevent dead end under uncontrolled situations where cleanup doesn't...
authorEloy Lafuente <stronk7@moodle.org>
Tue, 1 Dec 2009 14:27:39 +0000 (14:27 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Tue, 1 Dec 2009 14:27:39 +0000 (14:27 +0000)
lib/simpletestlib.php

index b14513e9d1a518cc8a426b48e4ac9970e499aa75..29412f4a3e68cd7fa222ccdbb7278ec06506e4d5 100644 (file)
@@ -543,11 +543,15 @@ class UnitTestCaseUsingDatabase extends UnitTestCase {
      */
     protected function create_test_table($tablename, $installxmlfile) {
         global $CFG;
+        $dbman = $this->testdb->get_manager();
         if (isset($this->tables[$tablename])) {
             debugging('You are attempting to create test table ' . $tablename . ' again. It already exists. Please review your code immediately.', DEBUG_DEVELOPER);
             return;
         }
-        $dbman = $this->testdb->get_manager();
+        if ($dbman->table_exists($tablename)) {
+            debugging('This table ' . $tablename . ' already exists from a previous execution. If the error persists you will need to review your code to ensure it is being created only once.', DEBUG_DEVELOPER);
+            $dbman->drop_table(new xmldb_table($tablename));
+        }
         $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/' . $installxmlfile . '/db/install.xml', $tablename);
         $this->tables[$tablename] = 1;
     }