Improved course module info conversion

This commit is contained in:
David Mudrak
2011-05-13 02:41:47 +02:00
parent d5d02635d7
commit baa6f6a848
3 changed files with 95 additions and 64 deletions
+94 -57
View File
@@ -175,7 +175,7 @@ abstract class moodle1_xml_handler extends moodle1_handler {
}
/**
* Dumps the data into the XML file
* Writes the given XML tree data into the currently opened file
*
* @param string $element the name of the root element of the tree
* @param array $data the associative array of data to write
@@ -225,59 +225,6 @@ abstract class moodle1_xml_handler extends moodle1_handler {
}
/**
* Shared base class for activity modules and blocks handlers
*/
abstract class moodle1_plugin_handler extends moodle1_xml_handler {
/** @var string */
protected $plugintype;
/** @var string */
protected $pluginname;
/**
* @param moodle1_converter $converter the converter that requires us
* @param string plugintype
* @param string pluginname
*/
public function __construct(moodle1_converter $converter, $plugintype, $pluginname) {
parent::__construct($converter);
$this->plugintype = $plugintype;
$this->pluginname = $pluginname;
}
}
/**
* Base class for activity module handlers
*/
abstract class moodle1_mod_handler extends moodle1_plugin_handler {
/** @var int module id */
protected $moduleid;
/**
* Return the relative path to the XML file that
* this step writes out to. Example: course/course.xml
*
* @return string
*/
public function get_xml_filename() {
return "activities/{$this->pluginname}_{$this->moduleid}/module.xml";
}
}
/**
* Base class for activity module handlers
*/
abstract class moodle1_block_handler extends moodle1_plugin_handler {
}
/**
* Process the root element of the backup file
*/
@@ -464,10 +411,25 @@ class moodle1_course_outline_handler extends moodle1_xml_handler {
new convert_path(
'course_module', '/MOODLE_BACKUP/COURSE/SECTIONS/SECTION/MODS/MOD',
array(
'newfields' => array(
'completion' => 0,
'completiongradeitemnumber' => null,
'completionview' => 0,
'completionexpected' => 0,
'availablefrom' => 0,
'availableuntil' => 0,
'showavailability' => 0,
'availability_info' => array(),
'visibleold' => 1,
),
'dropfields' => array(
'instance',
'roles_overrides',
'roles_assignments',
),
'renamefields' => array(
'type' => 'modulename',
),
)
)
);
@@ -481,7 +443,8 @@ class moodle1_course_outline_handler extends moodle1_xml_handler {
* Populates the section sequence field (order of course modules) and stashes the
* course module info so that is can be dumped to activities/xxxx_x/module.xml later
*/
public function process_course_module($data) {
public function process_course_module($data, $raw) {
global $CFG;
// add the course module id into the section's sequence
if (is_null($this->currentsection['sequence'])) {
@@ -494,9 +457,28 @@ class moodle1_course_outline_handler extends moodle1_xml_handler {
$data['sectionid'] = $this->currentsection['id'];
$data['sectionnumber'] = $this->currentsection['number'];
// generate the module version - this is a bit tricky as this information
// is not present in 1.9 backups. we will use the currently installed version
// whenever we can but that might not be accurate for some modules.
// also there might be problem with modules that are not present at the target
// host...
$versionfile = $CFG->dirroot.'/mod/'.$data['modulename'].'/version.php';
if (file_exists($versionfile)) {
include($versionfile);
$data['version'] = $module->version;
} else {
$data['version'] = null;
}
// stash the course module info in stashes like 'cminfo_forum' with
// itemid set to the instance id
$this->converter->set_stash('cminfo_'.$data['type'], $data, $data['instance']);
// itemid set to the instance id. this is needed so that module handlers
// can later obtain information about the course module.
$this->converter->set_stash('cminfo_'.$data['modulename'], $data, $raw['INSTANCE']);
// write the module.xml file
$this->open_xml_writer('activities/'.$data['modulename'].'_'.$data['id'].'/module.xml');
$this->write_xml('module', $data, array('/module/version'));
$this->close_xml_writer();
}
/**
@@ -510,3 +492,58 @@ class moodle1_course_outline_handler extends moodle1_xml_handler {
unset($this->currentsection);
}
}
/**
* Shared base class for activity modules and blocks handlers
*/
abstract class moodle1_plugin_handler extends moodle1_xml_handler {
/** @var string */
protected $plugintype;
/** @var string */
protected $pluginname;
/**
* @param moodle1_converter $converter the converter that requires us
* @param string plugintype
* @param string pluginname
*/
public function __construct(moodle1_converter $converter, $plugintype, $pluginname) {
parent::__construct($converter);
$this->plugintype = $plugintype;
$this->pluginname = $pluginname;
}
}
/**
* Base class for activity module handlers
*/
abstract class moodle1_mod_handler extends moodle1_plugin_handler {
/**
* Returns course module id for the given instance id
*
* The mapping from instance id to course module id has been stashed by
* {@link moodle1_course_outline_handler::process_course_module()}
*
* @param int $instance the module instance id
* @return int
*/
protected function get_moduleid($instance) {
$stashed = $this->converter->get_stash('cminfo_'.$this->pluginname, $instance);
return $stashed['id'];
}
}
/**
* Base class for activity module handlers
*/
abstract class moodle1_block_handler extends moodle1_plugin_handler {
}
@@ -136,6 +136,6 @@ class moodle1_converter_test extends UnitTestCase {
public function test_convert_run_convert() {
$converter = convert_factory::converter('moodle1', $this->tempdir);
//$converter->convert();
$converter->convert();
}
}
-6
View File
@@ -47,7 +47,6 @@ class moodle1_mod_forum_handler extends moodle1_mod_handler {
public function get_paths() {
return array(
new convert_path('forum', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM'),
// new convert_path('foo', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM/FOO'), // Example of sub-path
);
}
@@ -55,10 +54,5 @@ class moodle1_mod_forum_handler extends moodle1_mod_handler {
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM data
*/
public function process_forum($data) {
print_object($data);
}
public function process_foo($data) {
print_object($data);
}
}