]> git.mjollnir.org Git - moodle.git/commitdiff
Now blocks deletion looks both for tables without and with the
authorstronk7 <stronk7>
Mon, 2 Oct 2006 23:06:36 +0000 (23:06 +0000)
committerstronk7 <stronk7>
Mon, 2 Oct 2006 23:06:36 +0000 (23:06 +0000)
"block_" part in table names.
This is an interim situation until "block_" will be required. See:
http://docs.moodle.org/en/Development:Coding#Database_structures
http://tracker.moodle.org/browse/MDL-6786

Also, it's the FIRST use of XMLDB DDL functions inside Moodle! B-)

admin/blocks.php

index f31ae37cb21403fd1b0c8372893120ce13f027a7..368299a8298e6f744b69cd2b5bd955887cccce88 100644 (file)
@@ -6,6 +6,8 @@
     require_once($CFG->libdir.'/adminlib.php');
     require_once($CFG->libdir.'/blocklib.php');
     require_once($CFG->libdir.'/tablelib.php');
+    require_once($CFG->libdir.'/ddllib.php');
+
     $adminroot = admin_get_root();
     admin_externalpage_setup('manageblocks', $adminroot);
 
             }
 
             // Then the tables themselves
-
             if ($tables = $db->Metatables()) {
                 $prefix = $CFG->prefix.$block->name;
+                $prefix2 = $CFG->prefix.'block_'.$block->name;
                 foreach ($tables as $table) {
-                    if (strpos($table, $prefix) === 0) {
-                        if (!execute_sql("DROP TABLE $table", false)) {
+                    if (strpos($table, $prefix) === 0 || strpos($table, $prefix2) === 0) {
+                    /// If the match has been due to the 1st condition, debug to developers
+                        if (strpos($table, $prefix) === 0) {
+                            debugging('This block has some wrongly named tables. See Moodle Docs coding guidelines (and MDL-6786)', DEBUG_DEVELOPER);
+                        }
+                    /// Strip prefix from $table
+                        $table = preg_replace("/^{$CFG->prefix}/", '', $table);
+                        $xmldb_table = new XMLDBTable($table);
+                        if (!drop_table($xmldb_table, true, false)) {
                             notify("ERROR: while trying to drop table $table");
                         }
                     }