Permalink
Browse files

MDL-31527 XMLDB Editor - make sure default tables are created with co…

…rrect plugin prefix
  • Loading branch information...
1 parent b6aa60c commit 3b8d8e16414c874df9b56ceebbda64f4b3fc9ae5 @davosmith davosmith committed with stronk7 Feb 7, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 admin/xmldb/actions/create_xml_file/create_xml_file.class.php
@@ -66,6 +66,7 @@ function invoke() {
/// 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 @@ function invoke() {
$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 @@ function invoke() {
/// 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;
+ }
}

0 comments on commit 3b8d8e1

Please sign in to comment.