mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-42033' of git://github.com/jmvedrine/moodle
This commit is contained in:
commit
0a9f5b66c5
@ -387,7 +387,7 @@ class qformat_default {
|
||||
$question->modifiedby = $USER->id;
|
||||
$question->timemodified = time();
|
||||
$fileoptions = array(
|
||||
'subdirs' => false,
|
||||
'subdirs' => true,
|
||||
'maxfiles' => -1,
|
||||
'maxbytes' => 0,
|
||||
);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1473,4 +1473,51 @@ END;
|
||||
$this->assertEquals('/', $file->filepath);
|
||||
$this->assertEquals(6, $file->size);
|
||||
}
|
||||
|
||||
public function test_import_truefalse_wih_files() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$xml = '<question type="truefalse">
|
||||
<name>
|
||||
<text>truefalse</text>
|
||||
</name>
|
||||
<questiontext format="html">
|
||||
<text><![CDATA[<p><a href="@@PLUGINFILE@@/myfolder/moodle.txt">This text file</a> contains the word Moodle.</p>]]></text>
|
||||
<file name="moodle.txt" path="/myfolder/" encoding="base64">TW9vZGxl</file>
|
||||
</questiontext>
|
||||
<generalfeedback format="html">
|
||||
<text><![CDATA[<p>For further information, see the documentation about Moodle.</p>]]></text>
|
||||
</generalfeedback>
|
||||
<defaultgrade>1.0000000</defaultgrade>
|
||||
<penalty>1.0000000</penalty>
|
||||
<hidden>0</hidden>
|
||||
<answer fraction="100" format="moodle_auto_format">
|
||||
<text>true</text>
|
||||
<feedback format="html">
|
||||
<text></text>
|
||||
</feedback>
|
||||
</answer>
|
||||
<answer fraction="0" format="moodle_auto_format">
|
||||
<text>false</text>
|
||||
<feedback format="html">
|
||||
<text></text>
|
||||
</feedback>
|
||||
</answer>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
$importer = new qformat_xml();
|
||||
$q = $importer->import_truefalse($xmldata['question']);
|
||||
|
||||
$draftitemid = $q->questiontextitemid;
|
||||
$files = file_get_drafarea_files($draftitemid, '/myfolder/');
|
||||
|
||||
$this->assertEquals(1, count($files->list));
|
||||
|
||||
$file = $files->list[0];
|
||||
$this->assertEquals('moodle.txt', $file->filename);
|
||||
$this->assertEquals('/myfolder/', $file->filepath);
|
||||
$this->assertEquals(6, $file->size);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user