Permalink
Browse files

MDL-37967 Improve XML question import format handling of duplicated f…

…iles
  • Loading branch information...
1 parent 09de5eb commit ddc03b10d5c76336f31f5bba4198e852fcbf31b0 Jean-Michel Vedrine committed Feb 14, 2013
Showing with 8 additions and 1 deletion.
  1. +8 −1 question/format/xml/format.php
View
9 question/format/xml/format.php
@@ -170,16 +170,23 @@ public function import_files_as_draft($xml) {
}
$fs = get_file_storage();
$itemid = file_get_unused_draft_itemid();
+ $filenames = array();
foreach ($xml as $file) {
+ $filename = $file['@']['name'];
+ if (in_array($filename, $filenames)) {
+ debugging('Duplicate file in XML: ' . $filename, DEBUG_DEVELOPER);
+ continue;
+ }
$filerecord = array(
'contextid' => context_user::instance($USER->id)->id,
'component' => 'user',
'filearea' => 'draft',
'itemid' => $itemid,
'filepath' => '/',
- 'filename' => $file['@']['name'],
+ 'filename' => $filename,
);
$fs->create_file_from_string($filerecord, base64_decode($file['#']));
+ $filenames[] = $filename;
}
return $itemid;
}

0 comments on commit ddc03b1

Please sign in to comment.