MDL-61766 xmldb: Handle custom admin path
authorJun Pataleta <jun@moodle.com>
Tue, 27 Mar 2018 09:12:00 +0000 (17:12 +0800)
committerJun Pataleta <jun@moodle.com>
Thu, 29 Mar 2018 10:29:32 +0000 (18:29 +0800)
lib/xmldb/xmldb_structure.php

index 0f500a6..ad681ef 100644 (file)
@@ -234,7 +234,14 @@ class xmldb_structure extends xmldb_object {
         // Normalize paths to compare them.
         $filepath = realpath($this->name); // File path comes in name.
         $filename = basename($filepath);
-        $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $this->path . DIRECTORY_SEPARATOR . $filename);
+        $normalisedpath = $this->path;
+        if ($CFG->admin !== 'admin') {
+            $needle = 'admin/';
+            if (strpos($this->path, $needle) === 0) {
+                $normalisedpath = substr_replace($this->path, "$CFG->admin/", 0, strlen($needle));
+            }
+        }
+        $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $normalisedpath . DIRECTORY_SEPARATOR . $filename);
         if ($filepath !== $structurepath) {
             $relativepath = dirname(str_replace(realpath($CFG->dirroot) . DIRECTORY_SEPARATOR, '', $filepath));
             $this->errormsg = 'PATH attribute does not match file directory: ' . $relativepath;