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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_chat_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
|
||||
*
|
||||
@@ -63,29 +69,50 @@ class moodle1_mod_chat_handler extends moodle1_mod_handler {
|
||||
* data available
|
||||
*/
|
||||
public function process_chat($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);
|
||||
global $CFG;
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
$this->open_xml_writer("activities/chat_{$moduleid}/chat.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
// get the course module id and context id
|
||||
$instanceid = $data['id'];
|
||||
$cminfo = $this->get_cminfo($instanceid);
|
||||
$this->moduleid = $cminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
|
||||
|
||||
// replay the upgrade step 2010050101
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
$data['introformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_chat');
|
||||
|
||||
// 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 chat.xml
|
||||
$this->open_xml_writer("activities/chat_{$this->moduleid}/chat.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'chat', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('chat', 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('messages');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/CHAT/MESSAGES
|
||||
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/CHAT/MESSAGES/MESSAGE
|
||||
* data available
|
||||
*/
|
||||
public function process_chat_messages($data) {
|
||||
public function process_chat_message($data) {
|
||||
//@todo process user data
|
||||
//$this->write_xml('message', $data, array('/message/id'));
|
||||
}
|
||||
@@ -95,8 +122,20 @@ class moodle1_mod_chat_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function on_chat_end() {
|
||||
// close chat.xml
|
||||
$this->xmlwriter->end_tag('messages');
|
||||
$this->xmlwriter->end_tag('chat');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/chat_{$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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_choice_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
|
||||
*
|
||||
@@ -73,21 +79,32 @@ class moodle1_mod_choice_handler extends moodle1_mod_handler {
|
||||
public function process_choice($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/choice_{$moduleid}/choice.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_choice');
|
||||
|
||||
// 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 choice.xml
|
||||
$this->open_xml_writer("activities/choice_{$this->moduleid}/choice.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'choice', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('choice', 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);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,5 +137,16 @@ class moodle1_mod_choice_handler extends moodle1_mod_handler {
|
||||
$this->xmlwriter->end_tag('choice');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/choice_{$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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_data_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
|
||||
*
|
||||
@@ -66,20 +72,38 @@ class moodle1_mod_data_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function process_data($data) {
|
||||
global $CFG;
|
||||
|
||||
// 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);
|
||||
|
||||
//upgrade data
|
||||
// replay the upgrade step 2007101512
|
||||
if (!array_key_exists('asearchtemplate', $data)) {
|
||||
$data['asearchtemplate'] = null;
|
||||
}
|
||||
|
||||
//Upgrade all the data->notification currently being NULL to 0
|
||||
// replay the upgrade step 2007101513
|
||||
if (is_null($data['notification'])) {
|
||||
$data['notification'] = 0;
|
||||
}
|
||||
|
||||
//@todo: user data - upgrade content to new file storage
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
$data['introformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_data');
|
||||
|
||||
// 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);
|
||||
|
||||
// @todo: user data - upgrade content to new file storage
|
||||
|
||||
// add 'export' tag to list and single template.
|
||||
$pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
|
||||
@@ -87,34 +111,24 @@ class moodle1_mod_data_handler extends moodle1_mod_handler {
|
||||
$data['listtemplate'] = preg_replace($pattern, $replacement, $data['listtemplate']);
|
||||
$data['singletemplate'] = preg_replace($pattern, $replacement, $data['singletemplate']);
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea' && $data['introformat'] == FORMAT_MOODLE ) {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
$data['introformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
//@todo: user data - move data comments to comments table
|
||||
//@todo: user data - move data ratings to ratings table
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
$this->open_xml_writer("activities/data_{$moduleid}/data.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
// start writing data.xml
|
||||
$this->open_xml_writer("activities/data_{$this->moduleid}/data.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'data', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('data', array('id' => $instanceid));
|
||||
|
||||
unset($data['id']); // we already write it as attribute, do not repeat it as child element
|
||||
$addfield = true;
|
||||
foreach ($data as $field => $value) {
|
||||
if ($field == 'asearchtemplate') {
|
||||
//add field asearchtemplate (if doesn't exist already)
|
||||
$addfield = false;
|
||||
if ($field <> 'id') {
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
}
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
}
|
||||
if ($addfield) {
|
||||
$this->xmlwriter->full_tag('asearchtemplate', null);
|
||||
}
|
||||
|
||||
$this->xmlwriter->begin_tag('fields');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,6 +139,7 @@ class moodle1_mod_data_handler extends moodle1_mod_handler {
|
||||
// process database fields
|
||||
$this->write_xml('field', $data, array('/field/id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA/RECORDS/RECORD
|
||||
* data available
|
||||
@@ -138,10 +153,21 @@ class moodle1_mod_data_handler extends moodle1_mod_handler {
|
||||
* This is executed when we reach the closing </MOD> tag of our 'data' path
|
||||
*/
|
||||
public function on_data_end() {
|
||||
|
||||
// finish writing data.xml
|
||||
$this->xmlwriter->end_tag('fields');
|
||||
$this->xmlwriter->end_tag('data');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/data_{$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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,16 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Choice conversion handler
|
||||
* Feedback module conversion handler
|
||||
*/
|
||||
class moodle1_mod_feedback_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
|
||||
*
|
||||
@@ -82,24 +88,34 @@ class moodle1_mod_feedback_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function process_feedback($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/feedback_{$moduleid}/feedback.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_feedback');
|
||||
|
||||
// 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 feedback.xml
|
||||
$this->open_xml_writer("activities/feedback_{$this->moduleid}/feedback.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'feedback', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('feedback', 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('items');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,9 +130,21 @@ class moodle1_mod_feedback_handler extends moodle1_mod_handler {
|
||||
* This is executed when we reach the closing </MOD> tag of our 'feedback' path
|
||||
*/
|
||||
public function on_feedback_end() {
|
||||
// finish writing feedback.xml
|
||||
$this->xmlwriter->end_tag('items');
|
||||
$this->xmlwriter->end_tag('feedback');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/feedback_{$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_forum_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
|
||||
*
|
||||
@@ -68,34 +74,55 @@ class moodle1_mod_forum_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function process_forum($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/forum_{$moduleid}/forum.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_forum');
|
||||
|
||||
// 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 forum.xml
|
||||
$this->open_xml_writer("activities/forum_{$this->moduleid}/forum.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'forum', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('forum', 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('discussions');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is executed when we reach the closing </MOD> tag of our 'forum' path
|
||||
*/
|
||||
public function on_forum_end() {
|
||||
// finish writing forum.xml
|
||||
$this->xmlwriter->end_tag('discussions');
|
||||
$this->xmlwriter->end_tag('forum');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
}
|
||||
|
||||
//conversion of discussion, posts etc will be implemented in a future version of Moodle
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/forum_{$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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class moodle1_mod_label_handler extends moodle1_mod_handler {
|
||||
'content' => 'intro'
|
||||
),
|
||||
'newfields' => array(
|
||||
'introformat' => 0
|
||||
'introformat' => FORMAT_HTML
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -72,25 +72,33 @@ class moodle1_mod_label_handler extends moodle1_mod_handler {
|
||||
$moduleid = $cminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
// get a fresh new file manager for this instance
|
||||
$fileman = $this->converter->get_file_manager($contextid, 'mod_label');
|
||||
|
||||
// convert course files embedded into the intro
|
||||
$fileman->filearea = 'intro';
|
||||
$fileman->itemid = 0;
|
||||
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $fileman);
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/label_{$moduleid}/inforef.xml");
|
||||
$this->xmlwriter->begin_tag('inforef');
|
||||
$this->xmlwriter->begin_tag('fileref');
|
||||
foreach ($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();
|
||||
|
||||
// write label.xml
|
||||
$this->open_xml_writer("activities/label_{$moduleid}/label.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
'modulename' => 'label', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('label', 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is executed when we reach the closing </MOD> tag of our 'label' path
|
||||
*/
|
||||
public function on_label_end() {
|
||||
// close label.xml
|
||||
$this->xmlwriter->end_tag('label');
|
||||
$this->write_xml('label', $data, array('/label/id'));
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_lesson_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
|
||||
*
|
||||
@@ -59,7 +65,6 @@ class moodle1_mod_lesson_handler extends moodle1_mod_handler {
|
||||
array(
|
||||
'newfields' => array(
|
||||
'contentsformat' => FORMAT_MOODLE,
|
||||
'responseformat' => 0,
|
||||
),
|
||||
)
|
||||
),
|
||||
@@ -68,6 +73,7 @@ class moodle1_mod_lesson_handler extends moodle1_mod_handler {
|
||||
array(
|
||||
'newfields' => array(
|
||||
'answerformat' => 0,
|
||||
'responseformat' => 0,
|
||||
),
|
||||
'renamefields' => array(
|
||||
'answertext' => 'answer_text',
|
||||
@@ -82,25 +88,43 @@ class moodle1_mod_lesson_handler extends moodle1_mod_handler {
|
||||
* data available
|
||||
*/
|
||||
public function process_lesson($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);
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
$this->open_xml_writer("activities/lesson_{$moduleid}/lesson.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
// get the course module id and context id
|
||||
$instanceid = $data['id'];
|
||||
$cminfo = $this->get_cminfo($instanceid);
|
||||
$this->moduleid = $cminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
|
||||
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_lesson');
|
||||
|
||||
// migrate referenced local media files
|
||||
if (!empty($data['mediafile']) and strpos($data['mediafile'], '://') === false) {
|
||||
$this->fileman->filearea = 'mediafile';
|
||||
$this->fileman->itemid = 0;
|
||||
try {
|
||||
$this->fileman->migrate_file('course_files/'.$data['mediafile']);
|
||||
} catch (moodle1_convert_exception $e) {
|
||||
// the file probably does not exist
|
||||
// todo add to log
|
||||
}
|
||||
}
|
||||
|
||||
// start writing lesson.xml
|
||||
$this->open_xml_writer("activities/lesson_{$this->moduleid}/lesson.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'lesson', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('lesson', 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('pages');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,9 +132,19 @@ class moodle1_mod_lesson_handler extends moodle1_mod_handler {
|
||||
* data available
|
||||
*/
|
||||
public function process_lesson_page($data) {
|
||||
global $CFG;
|
||||
|
||||
// replay the upgrade step 2009120801
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$data['contents'] = text_to_html($data['contents'], false, false, true);
|
||||
$data['contentsformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
$this->xmlwriter->begin_tag('page', array('id' => $data['pageid']));
|
||||
foreach ($data as $field => $value) {
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
if ($field <> 'id') {
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->xmlwriter->begin_tag('answers');
|
||||
@@ -121,6 +155,18 @@ class moodle1_mod_lesson_handler extends moodle1_mod_handler {
|
||||
* data available
|
||||
*/
|
||||
public function process_lesson_answer($data) {
|
||||
|
||||
// replay the upgrade step 2010072003
|
||||
$flags = intval($data['flags']);
|
||||
if ($flags & 1) {
|
||||
$data['answer_text'] = text_to_html($data['answer_text'], false, false, true);
|
||||
$data['answerformat'] = FORMAT_HTML;
|
||||
}
|
||||
if ($flags & 2) {
|
||||
$data['response'] = text_to_html($data['response'], false, false, true);
|
||||
$data['responseformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
$this->write_xml('answer', $data, array('/answer/id'));
|
||||
}
|
||||
|
||||
@@ -136,9 +182,21 @@ class moodle1_mod_lesson_handler extends moodle1_mod_handler {
|
||||
* This is executed when we reach the closing </MOD> tag of our 'lesson' path
|
||||
*/
|
||||
public function on_lesson_end() {
|
||||
// finish writing lesson.xml
|
||||
$this->xmlwriter->end_tag('pages');
|
||||
$this->xmlwriter->end_tag('lesson');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/lesson_{$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_quiz_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
|
||||
*
|
||||
@@ -76,33 +82,51 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
|
||||
* data available
|
||||
*/
|
||||
public function process_quiz($data) {
|
||||
global $CFG;
|
||||
|
||||
//quiz: SET sumgrades=0 WHERE sumgrades IS NULL
|
||||
// replay the upgrade step 2008081501
|
||||
if (is_null($data['sumgrades'])) {
|
||||
$data['sumgrades'] = 0;
|
||||
//@todo for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL
|
||||
//@todo for user data: quiz_grades.grade should be not be null , convert to default 0
|
||||
}
|
||||
|
||||
/// Convert 1.9 quiz.timelimit from minutes to seconds.
|
||||
// replay the upgrade step 2009042000
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
$data['introformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// replay the upgrade step 2009031001
|
||||
$data['timelimit'] *= 60;
|
||||
|
||||
// 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/quiz_{$moduleid}/quiz.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_quiz');
|
||||
|
||||
// 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 quiz.xml
|
||||
$this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'quiz', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('quiz', 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);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function on_quiz_question_instances_start() {
|
||||
@@ -114,9 +138,6 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
|
||||
}
|
||||
|
||||
public function process_quiz_question_instance($data) {
|
||||
// quiz_question_instances.grade should be decimal(12,7) not null default 0
|
||||
// $data['grade'] and other precisions will be changed when inserted into db.
|
||||
|
||||
$this->write_xml('question_instance', $data, array('/question_instance/id'));
|
||||
}
|
||||
|
||||
@@ -129,11 +150,10 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
|
||||
}
|
||||
|
||||
public function process_quiz_feedback($data) {
|
||||
//quiz_feedback.mingrade not null! defaults 0
|
||||
// replay the upgrade step 2010122302
|
||||
if (is_null($data['mingrade'])) {
|
||||
$data['mingrade'] = 0;
|
||||
}
|
||||
//quiz_feedback.maxgrade not null! defaults 0
|
||||
if (is_null($data['maxgrade'])) {
|
||||
$data['maxgrade'] = 0;
|
||||
}
|
||||
@@ -145,11 +165,24 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
|
||||
* This is executed when we reach the closing </MOD> tag of our 'quiz' path
|
||||
*/
|
||||
public function on_quiz_end() {
|
||||
// create 1 new <overrides> element (no data from 1.9)
|
||||
|
||||
// append empty <overrides> subpath element
|
||||
$this->write_xml('overrides', array());
|
||||
|
||||
// finish writing quiz.xml
|
||||
$this->xmlwriter->end_tag('quiz');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/quiz_{$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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* Scorm conversion handler
|
||||
*/
|
||||
class moodle1_mod_scorm_handler extends moodle1_mod_handler {
|
||||
/** @var array in-memory cache for the course module information */
|
||||
protected $currentcminfo = null;
|
||||
/** @var moodle1_file_manager instance for the current scorm */
|
||||
|
||||
/** @var moodle1_file_manager */
|
||||
protected $fileman = null;
|
||||
|
||||
/** @var int cmid */
|
||||
protected $moduleid = null;
|
||||
|
||||
/**
|
||||
* Declare the paths in moodle.xml we are able to convert
|
||||
*
|
||||
@@ -65,7 +67,6 @@ class moodle1_mod_scorm_handler extends moodle1_mod_handler {
|
||||
'timeopen' => '0',
|
||||
'timeclose' => '0',
|
||||
'introformat' => '0',
|
||||
'launch' => null,
|
||||
),
|
||||
'renamefields' => array(
|
||||
'summary' => 'intro'
|
||||
@@ -82,18 +83,27 @@ class moodle1_mod_scorm_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function process_scorm($data) {
|
||||
global $CFG;
|
||||
|
||||
// get the course module id and context id
|
||||
$instanceid = $data['id'];
|
||||
$this->currentcminfo = $this->get_cminfo($instanceid);
|
||||
$moduleid = $this->currentcminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
|
||||
$instanceid = $data['id'];
|
||||
$currentcminfo = $this->get_cminfo($instanceid);
|
||||
$this->moduleid = $currentcminfo['id'];
|
||||
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea' && $data['introformat'] == FORMAT_MOODLE ) {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
$data['introformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm');
|
||||
|
||||
// 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);
|
||||
|
||||
// check 1.9 version where backup was created
|
||||
$backupinfo = $this->converter->get_stash('backup_info');
|
||||
if ($backupinfo['moodle_version'] < 2007110503) {
|
||||
@@ -114,21 +124,26 @@ class moodle1_mod_scorm_handler extends moodle1_mod_handler {
|
||||
}
|
||||
}
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
$this->open_xml_writer("activities/scorm_{$moduleid}/scorm.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
// migrate scorm package file
|
||||
$this->fileman->filearea = 'package';
|
||||
$this->fileman->itemid = 0;
|
||||
$this->fileman->migrate_file('course_files/'.$data['reference']);
|
||||
|
||||
// start writing scorm.xml
|
||||
$this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'scorm', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('scorm', 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('scoes');
|
||||
|
||||
// prepare file manager for migrating scorm package file.
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm', 'package');
|
||||
$this->fileman->migrate_file('course_files/'.$data['reference']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,14 +158,14 @@ class moodle1_mod_scorm_handler extends moodle1_mod_handler {
|
||||
* This is executed when we reach the closing </MOD> tag of our 'scorm' path
|
||||
*/
|
||||
public function on_scorm_end() {
|
||||
//close scorm.xml
|
||||
// close scorm.xml
|
||||
$this->xmlwriter->end_tag('scoes');
|
||||
$this->xmlwriter->end_tag('scorm');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml for migrated scorm zip file.
|
||||
$this->open_xml_writer("activities/scorm_{$this->currentcminfo['id']}/inforef.xml");
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/scorm_{$this->moduleid}/inforef.xml");
|
||||
$this->xmlwriter->begin_tag('inforef');
|
||||
$this->xmlwriter->begin_tag('fileref');
|
||||
foreach ($this->fileman->get_fileids() as $fileid) {
|
||||
@@ -160,4 +175,4 @@ class moodle1_mod_scorm_handler extends moodle1_mod_handler {
|
||||
$this->xmlwriter->end_tag('inforef');
|
||||
$this->close_xml_writer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Provides support for the conversion of moodle1 backup to the moodle2 format
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage Survey
|
||||
* @subpackage survey
|
||||
* @copyright 2011 Rossiani Wijaya <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -31,6 +31,12 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class moodle1_mod_survey_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
|
||||
*
|
||||
@@ -62,31 +68,61 @@ class moodle1_mod_survey_handler extends moodle1_mod_handler {
|
||||
* data available
|
||||
*/
|
||||
public function process_survey($data) {
|
||||
global $CFG;
|
||||
|
||||
// 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/survey_{$moduleid}/survey.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
// replay upgrade step 2009042002
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$data['intro'] = text_to_html($data['intro'], false, false, true);
|
||||
$data['introformat'] = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_survey');
|
||||
|
||||
// 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);
|
||||
|
||||
// write survey.xml
|
||||
$this->open_xml_writer("activities/survey_{$this->moduleid}/survey.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'survey', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('survey', 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);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is executed when we reach the closing </MOD> tag of our 'survey' path
|
||||
*/
|
||||
public function on_survey_end() {
|
||||
// finish survey.xml
|
||||
$this->xmlwriter->end_tag('survey');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/survey_{$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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,11 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* Wiki conversion handler
|
||||
*/
|
||||
class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
/** @var string initial content for creating first page from optional 1.9 wiki file*/
|
||||
|
||||
/** @var string initial content for creating first page from the optional 1.9 wiki file */
|
||||
protected $initialcontent;
|
||||
|
||||
/** @var string */
|
||||
protected $initialcontentfilename;
|
||||
|
||||
/** @var bool initial content page already exists */
|
||||
@@ -41,6 +44,12 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
/** @var array a data element transfer buffer, can be used for transfer of data between xml path levels. */
|
||||
protected $databuf = array();
|
||||
|
||||
/** @var moodle1_file_manager */
|
||||
protected $fileman = null;
|
||||
|
||||
/** @var int cmid */
|
||||
protected $moduleid = null;
|
||||
|
||||
/**
|
||||
* Declare the paths in moodle.xml we are able to convert
|
||||
*
|
||||
@@ -146,33 +155,43 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
$data['name'] = 'Wiki';
|
||||
}
|
||||
// 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);
|
||||
|
||||
// get a fresh new file manager for this instance
|
||||
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_wiki');
|
||||
|
||||
// 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);
|
||||
|
||||
// we now have all information needed to start writing into the file
|
||||
$this->open_xml_writer("activities/wiki_{$moduleid}/wiki.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
|
||||
$this->open_xml_writer("activities/wiki_{$this->moduleid}/wiki.xml");
|
||||
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
|
||||
'modulename' => 'wiki', 'contextid' => $contextid));
|
||||
$this->xmlwriter->begin_tag('wiki', 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);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
//process ENTRIES
|
||||
public function on_wiki_entries_start() {
|
||||
$this->xmlwriter->begin_tag('subwikis');
|
||||
$this->needinitpage = false; //backup has entries, so the initial_content file has been stored as a page in 1.9.
|
||||
}
|
||||
|
||||
public function on_wiki_entries_end() {
|
||||
$this->xmlwriter->end_tag('subwikis');
|
||||
}
|
||||
|
||||
//process ENTRY
|
||||
public function process_wiki_entry($data) {
|
||||
$this->xmlwriter->begin_tag('subwiki', array('id' => $data['id']));
|
||||
unset($data['id']);
|
||||
@@ -184,19 +203,19 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
$this->xmlwriter->full_tag($field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function on_wiki_entry_end() {
|
||||
$this->xmlwriter->end_tag('subwiki');
|
||||
}
|
||||
|
||||
// process PAGES
|
||||
public function on_wiki_pages_start() {
|
||||
$this->xmlwriter->begin_tag('pages');
|
||||
}
|
||||
|
||||
public function on_wiki_pages_end() {
|
||||
$this->xmlwriter->end_tag('pages');
|
||||
}
|
||||
|
||||
// process PAGE
|
||||
public function process_wiki_entry_page($data) {
|
||||
// assimilate data to create later in extra virtual path page/versions/version/
|
||||
$this->databuf['id'] = $this->converter->get_nextid();
|
||||
@@ -207,14 +226,14 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
$this->databuf['timecreated'] = $data['timecreated']; //do not unset, is reused
|
||||
$this->databuf['userid'] = $data['userid']; //do not unset, is reused
|
||||
|
||||
//process page data (user data and also the one that is from <initialcontent>
|
||||
// process page data (user data and also the one that is from <initialcontent>
|
||||
$this->xmlwriter->begin_tag('page', array('id' => $data['id']));
|
||||
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);
|
||||
}
|
||||
|
||||
//process page content as a version.
|
||||
// process page content as a version.
|
||||
$this->xmlwriter->begin_tag('versions');
|
||||
$this->write_xml('version', $this->databuf, array('/version/id')); //version id from get_nextid()
|
||||
$this->xmlwriter->end_tag('versions');
|
||||
@@ -228,7 +247,8 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
*/
|
||||
public function on_wiki_end() {
|
||||
global $USER;
|
||||
//check if initial content needs to be created ( and if a page already there for it?)
|
||||
|
||||
//check if the initial content needs to be created (and if a page is already there for it)
|
||||
if ($this->initialcontentfilename && $this->needinitpage) {
|
||||
//contruct (synthetic - not for cooking) a full path for creating entries/entry/pages/page
|
||||
$data_entry = array(
|
||||
@@ -253,12 +273,12 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
);
|
||||
//create xml with constructed page data (from initial_content file).
|
||||
$this->on_wiki_entries_start();
|
||||
$this->process_wiki_entry($data_entry);
|
||||
$this->on_wiki_pages_start();
|
||||
$this->process_wiki_entry_page($data_page);
|
||||
$this->on_wiki_entry_page_end();
|
||||
$this->on_wiki_pages_end();
|
||||
$this->on_wiki_entry_end();
|
||||
$this->process_wiki_entry($data_entry);
|
||||
$this->on_wiki_pages_start();
|
||||
$this->process_wiki_entry_page($data_page);
|
||||
$this->on_wiki_entry_page_end();
|
||||
$this->on_wiki_pages_end();
|
||||
$this->on_wiki_entry_end();
|
||||
$this->on_wiki_entries_end();
|
||||
}
|
||||
|
||||
@@ -266,5 +286,16 @@ class moodle1_mod_wiki_handler extends moodle1_mod_handler {
|
||||
$this->xmlwriter->end_tag('wiki');
|
||||
$this->xmlwriter->end_tag('activity');
|
||||
$this->close_xml_writer();
|
||||
|
||||
// write inforef.xml
|
||||
$this->open_xml_writer("activities/wiki_{$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