Skip to content
Browse files

MDL-34020: Further work on IMS package importing when using Blackboar…

…d packages
  • Loading branch information...
1 parent ea04def commit 56dc43f3d23e38bce394639f3ea21a8eee28aad9 @tlock tlock committed Jun 26, 2012
Showing with 45 additions and 5 deletions.
  1. +3 −3 mod/imscp/backup/moodle1/lib.php
  2. +42 −2 mod/imscp/locallib.php
View
6 mod/imscp/backup/moodle1/lib.php
@@ -83,7 +83,7 @@ public function process_legacy_resource(array $data, array $raw = null) {
$this->fileman->migrate_directory('moddata/resource/'.$data['id']);
// parse manifest
- $structure = $this->parse_structure($this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/imsmanifest.xml');
+ $structure = $this->parse_structure($this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/imsmanifest.xml', $imscp, $contextid);
$imscp['structure'] = is_array($structure) ? serialize($structure) : null;
// write imscp.xml
@@ -113,7 +113,7 @@ public function process_legacy_resource(array $data, array $raw = null) {
*
* @param string $manifestfilepath the full path to the manifest file to parse
*/
- protected function parse_structure($manifestfilepath) {
+ protected function parse_structure($manifestfilepath, $imscp, $context) {
global $CFG;
if (!file_exists($manifestfilepath)) {
@@ -127,6 +127,6 @@ protected function parse_structure($manifestfilepath) {
}
require_once($CFG->dirroot.'/mod/imscp/locallib.php');
- return imscp_parse_manifestfile($manifestfilecontents);
+ return imscp_parse_manifestfile($manifestfilecontents, $imscp, $context);
}
}
View
44 mod/imscp/locallib.php
@@ -95,15 +95,15 @@ function imscp_parse_structure($imscp, $context) {
return null;
}
- return imscp_parse_manifestfile($manifestfile->get_content());
+ return imscp_parse_manifestfile($manifestfile->get_content(), $imscp, $context);
}
/**
* Parse the contents of a IMS package's manifest file
* @param string $manifestfilecontents the contents of the manifest file
* @return array
*/
-function imscp_parse_manifestfile($manifestfilecontents) {
+function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) {
$doc = new DOMDocument();
if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) {
return null;
@@ -162,6 +162,9 @@ function imscp_parse_manifestfile($manifestfilecontents) {
foreach ($fileresources as $file) {
$href = $file->getAttribute('href');
}
+ if (pathinfo($href, PATHINFO_EXTENSION) == 'xml') {
+ $href = imscp_recursive_href($href, $imscp, $context);
+ }
if (empty($href)) {
continue;
}
@@ -189,6 +192,43 @@ function imscp_parse_manifestfile($manifestfilecontents) {
return $items;
}
+function imscp_recursive_href($manifestfilename, $imscp, $context) {
+ $fs = get_file_storage();
+
+ $dirname = dirname($manifestfilename);
+ $filename = basename($manifestfilename);
+
+ if ($dirname !== '/') {
+ $dirname = "/$dirname/";
+ }
+
+ if (!$manifestfile = $fs->get_file($context->id, 'mod_imscp', 'content', $imscp->revision, $dirname, $filename)) {
+ return null;
+ }
+ $doc = new DOMDocument();
+ if (!$doc->loadXML($manifestfile->get_content(), LIBXML_NONET)) {
+ return null;
+ }
+ $xmlresources = $doc->getElementsByTagName('resource');
+ foreach ($xmlresources as $res) {
+ if (!$href = $res->attributes->getNamedItem('href')) {
+ $fileresources = $res->getElementsByTagName('file');
+ foreach ($fileresources as $file) {
+ $href = $file->getAttribute('href');
+ if (pathinfo($href, PATHINFO_EXTENSION) == 'xml') {
+ $href = imscp_recursive_href($href, $imscp, $context);
+ }
+
+ if (pathinfo($href, PATHINFO_EXTENSION) == 'htm' || pathinfo($href, PATHINFO_EXTENSION) == 'html') {
+ return $href;
+ }
+ }
+ }
+ }
+
+ return $href;
+}
+
function imscp_recursive_item($xmlitem, $level, $resources) {
$identifierref = '';
if ($identifierref = $xmlitem->attributes->getNamedItem('identifierref')) {

0 comments on commit 56dc43f

Please sign in to comment.
Something went wrong with that request. Please try again.