From 1cdadf514074166a9877daab28fcf20c393fe1db Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Tue, 7 Feb 2012 19:47:17 +0000 Subject: [PATCH] MDL-31527 XMLDB Editor - make sure default tables are created with correct plugin prefix --- .../create_xml_file/create_xml_file.class.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/admin/tool/xmldb/actions/create_xml_file/create_xml_file.class.php b/admin/tool/xmldb/actions/create_xml_file/create_xml_file.class.php index 205700f2c80..1cf39694d67 100644 --- a/admin/tool/xmldb/actions/create_xml_file/create_xml_file.class.php +++ b/admin/tool/xmldb/actions/create_xml_file/create_xml_file.class.php @@ -68,6 +68,7 @@ class create_xml_file extends XMLDBAction { // Get the dir containing the file $dirpath = required_param('dir', PARAM_PATH); + $plugintype = $this->get_plugin_type($dirpath); $dirpath = $CFG->dirroot . $dirpath; $file = $dirpath . '/install.xml'; @@ -77,6 +78,9 @@ class create_xml_file extends XMLDBAction { $xmlcomment = 'XMLDB file for Moodle ' . dirname($xmlpath); $xmltable = strtolower(basename(dirname($xmlpath))); + if ($plugintype && $plugintype != 'mod') { + $xmltable = $plugintype.'_'.$xmltable; + } // Initial contents $c = '' . "\n"; @@ -106,5 +110,23 @@ class create_xml_file extends XMLDBAction { // Return ok if arrived here return $result; } + + /** + * From a given path, work out what type of plugin + * this belongs to + * @param string $dirpath Path to the db file for this plugin + * @return string the type of the plugin or null if not found + */ + function get_plugin_type($dirpath) { + global $CFG; + $dirpath = $CFG->dirroot.$dirpath; + $plugintypes = get_plugin_types(); + foreach ($plugintypes as $plugintype => $pluginbasedir) { + if (substr($dirpath, 0, strlen($pluginbasedir)) == $pluginbasedir) { + return $plugintype; + } + } + return null; + } } -- 2.43.0