MDL-27718 Migrate files embedded in the activity intro fields
Contains various fixed spotted through the way, too.
This commit is contained in:
@@ -32,6 +32,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_assignment_handler extends moodle1_mod_handler {
|
||||
|
||||
/** @var moodle1_file_manager */
|
||||
protected $fileman = null;
|
||||
|
||||
/** @var int cmid */
|
||||
protected $moduleid = null;
|
||||
|
||||
/**
|
||||
* Declare the paths in moodle.xml we are able to convert
|
||||
*
|
||||
@@ -67,23 +73,34 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function process_assignment($data) {
|
||||
// get the course module id and context id
|
||||
$instanceid = $data['id'];
|
||||
$cminfo = $this->get_cminfo($instanceid);
|
||||
$moduleid = $cminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
|
||||
$instanceid = $data['id'];
|
||||
$cminfo = $this->get_cminfo($instanceid);
|
||||
$this->moduleid = $cminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
$this->open_xml_writer("activities/assignment_{$moduleid}/assignment.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_assignment');
|
||||
|
||||
// convert course files embedded into the intro
|
||||
$this->fileman->filearea = 'intro';
|
||||
$this->fileman->itemid = 0;
|
||||
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
|
||||
|
||||
// start writing assignment.xml
|
||||
$this->open_xml_writer("activities/assignment_{$this->moduleid}/assignment.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'assignment', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('assignment', array('id' => $instanceid));
|
||||
|
||||
unset($data['id']); // we already write it as attribute, do not repeat it as child element
|
||||
foreach ($data as $field => $value) {
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
if ($field <> 'id') {
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->xmlwriter->begin_tag('submissions');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,10 +116,21 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler {
|
||||
* This is executed when we reach the closing </MOD> tag of our 'assignment' path
|
||||
*/
|
||||
public function on_assignment_end() {
|
||||
|
||||
// finish writing assignment.xml
|
||||
$this->xmlwriter->end_tag('submissions');
|
||||
$this->xmlwriter->end_tag('assignment');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/assignment_{$this->moduleid}/inforef.xml");
|
||||
$this->xmlwriter->begin_tag('inforef');
|
||||
$this->xmlwriter->begin_tag('fileref');
|
||||
foreach ($this->fileman->get_fileids() as $fileid) {
|
||||
$this->write_xml('file', array('id' => $fileid));
|
||||
}
|
||||
$this->xmlwriter->end_tag('fileref');
|
||||
$this->xmlwriter->end_tag('inforef');
|
||||
$this->close_xml_writer();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user