AT-4848: Added a condition to handle a false positive.
[atutor.git] / docs / mods / _core / imscp / ims_import.php
index 6201322..103163e 100644 (file)
@@ -97,16 +97,16 @@ function checkResources($import_path){
        $data = rscandir($import_path);
        //check if every file is presented in the manifest
        foreach($data as $filepath){
-       debug(preg_match('/(.*)\.xml/', substr($filepath, strlen($import_path))));
+//     debug(preg_match('/(.*)\.xml/', substr($filepath, strlen($import_path))));
                //validate xml via its xsd/dtds
                if (preg_match('/(.*)\.xml/', substr($filepath, strlen($import_path)))){
                        libxml_use_internal_errors(true);
                        $dom = new DOMDocument();
                        $dom->load(realpath($filepath));
-                       debug(realpath($filepath), 'filepath');
+//                     debug(realpath($filepath), 'filepath');
                        if (!$dom->schemaValidate('main.xsd')){
                                $errors = libxml_get_errors();
-                               debug($errors);exit;
+//                             debug($errors);exit;
                                foreach ($errors as $error) {
                                        //suppress warnings
                                        if ($error->level==LIBXML_ERR_WARNING){
@@ -1222,7 +1222,11 @@ foreach ($items as $item_id => $content_info)
                $all_package_base_path = implode('/', $all_package_base_path);
        }
 
-       if ($common_path != '' && substr($content_info['new_path'], strlen($common_path))) {
+    // The following condition checks if there is a common path, if so, remove it from the content base_href.
+    // This prevents the path to grow longer.
+       if ($common_path != '' 
+               && ($content_info['new_path'] === $common_path
+               || substr($content_info['new_path'], strlen($common_path)))) {
                $content_info['new_path'] = $package_base_name . substr($content_info['new_path'], strlen($common_path));
        } else {
                $content_info['new_path'] = $package_base_name . '/' . $content_info['new_path'];