/** * Delete all plugin tables * @name string name of plugin, used as table prefix * @file string path to install.xml file * @feedback boolean */ function drop_plugin_tables($name, $file, $feedback = true) { global $CFG, $DB; // first try normal delete if (file_exists($file) and $DB->get_manager()->delete_tables_from_xmldb_file($file)) { return true; } // then try to find all tables that start with name and are not in any xml file $used_tables = get_used_table_names(); $tables = $DB->get_tables(); /// Iterate over, fixing id fields as necessary foreach ($tables as $table) { if (in_array($table, $used_tables)) { continue; } if (strpos($table, $name) !== 0) { continue; } // found orphan table --> delete it if ($DB->get_manager()->table_exists($table)) { $xmldb_table = new xmldb_table($table); $DB->get_manager()->drop_table($xmldb_table); } } return true; }
/** * Delete all plugin tables * @name string name of plugin, used as table prefix * @file string path to install.xml file * @feedback boolean */ function drop_plugin_tables($name, $file, $feedback = true) { global $CFG, $db; // first try normal delete if (delete_tables_from_xmldb_file($file, $feedback)) { return true; } // then try to find all tables that start with name and are not in any xml file $used_tables = get_used_table_names(); $tables = $db->MetaTables(); /// Iterate over, fixing id fields as necessary foreach ($tables as $table) { if (strlen($CFG->prefix)) { if (strpos($table, $CFG->prefix) !== 0) { continue; } $table = substr($table, strlen($CFG->prefix)); } $table = strtolower($table); if (strpos($table, $name) !== 0) { continue; } if (in_array($table, $used_tables)) { continue; } // found orphan table --> delete it $table = new XMLDBTable($table); if (table_exists($table)) { drop_table($table, true, $feedback); } } return true; }