From cc0bf616762e6f2da5b7c39c06aaf139785a46fc Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 2 Oct 2006 23:06:36 +0000 Subject: [PATCH] Now blocks deletion looks both for tables without and with the "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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/admin/blocks.php b/admin/blocks.php index f31ae37cb2..368299a829 100644 --- a/admin/blocks.php +++ b/admin/blocks.php @@ -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); @@ -99,12 +101,19 @@ } // 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"); } } -- 2.39.5