MDL-31527 XMLDB Editor - make sure default tables are created with correct plugin prefix

This commit is contained in:
Davo Smith
2012-02-14 12:12:31 +01:00
committed by Eloy Lafuente (stronk7)
parent b6aa60c810
commit 3b8d8e1641
@@ -66,6 +66,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';
@@ -75,6 +76,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 = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
@@ -104,5 +108,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;
}
}