MDL-34020: Further work on IMS package importing when using Blackboard packages
This commit is contained in:
@@ -83,7 +83,7 @@ class moodle1_mod_imscp_handler extends moodle1_resource_successor_handler {
|
||||
$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 @@ class moodle1_mod_imscp_handler extends moodle1_resource_successor_handler {
|
||||
*
|
||||
* @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 @@ class moodle1_mod_imscp_handler extends moodle1_resource_successor_handler {
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/mod/imscp/locallib.php');
|
||||
return imscp_parse_manifestfile($manifestfilecontents);
|
||||
return imscp_parse_manifestfile($manifestfilecontents, $imscp, $context);
|
||||
}
|
||||
}
|
||||
|
||||
+42
-2
@@ -95,7 +95,7 @@ function imscp_parse_structure($imscp, $context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return imscp_parse_manifestfile($manifestfile->get_content());
|
||||
return imscp_parse_manifestfile($manifestfile->get_content(), $imscp, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +103,7 @@ function imscp_parse_structure($imscp, $context) {
|
||||
* @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')) {
|
||||
|
||||
Reference in New Issue
Block a user