mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 18:36:42 +02:00
MDL-42033 Files in subdirs not exported correctly by question XML format
This commit is contained in:
parent
692d247a3a
commit
624ff5ba57
3 changed files with 58 additions and 9 deletions
|
@ -169,11 +169,13 @@ class qformat_xml extends qformat_default {
|
|||
}
|
||||
$fs = get_file_storage();
|
||||
$itemid = file_get_unused_draft_itemid();
|
||||
$filenames = array();
|
||||
$filepaths = array();
|
||||
foreach ($xml as $file) {
|
||||
$filename = $file['@']['name'];
|
||||
if (in_array($filename, $filenames)) {
|
||||
debugging('Duplicate file in XML: ' . $filename, DEBUG_DEVELOPER);
|
||||
$filename = $this->getpath($file, array('@', 'name'), '', true);
|
||||
$filepath = $this->getpath($file, array('@', 'path'), '/', true);
|
||||
$fullpath = $filepath . $filename;
|
||||
if (in_array($fullpath, $filepaths)) {
|
||||
debugging('Duplicate file in XML: ' . $fullpath, DEBUG_DEVELOPER);
|
||||
continue;
|
||||
}
|
||||
$filerecord = array(
|
||||
|
@ -181,11 +183,11 @@ class qformat_xml extends qformat_default {
|
|||
'component' => 'user',
|
||||
'filearea' => 'draft',
|
||||
'itemid' => $itemid,
|
||||
'filepath' => '/',
|
||||
'filepath' => $filepath,
|
||||
'filename' => $filename,
|
||||
);
|
||||
$fs->create_file_from_string($filerecord, base64_decode($file['#']));
|
||||
$filenames[] = $filename;
|
||||
$filepaths[] = $fullpath;
|
||||
}
|
||||
return $itemid;
|
||||
}
|
||||
|
@ -1092,9 +1094,9 @@ class qformat_xml extends qformat_default {
|
|||
if ($file->is_directory()) {
|
||||
continue;
|
||||
}
|
||||
$string .= '<file name="' . $file->get_filename() . '" encoding="base64">';
|
||||
$string .= '<file name="' . $file->get_filename() . '" path="' . $file->get_filepath() . '" encoding="base64">';
|
||||
$string .= base64_encode($file->get_content());
|
||||
$string .= '</file>';
|
||||
$string .= "</file>\n";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue