Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding plugin abstract class and adding a step to activities to gener…

…ate their module.xml
  • Loading branch information...
commit 5aee1af3f1ebe377a55252348f245493e6c961e1 1 parent 7c9d292
@mrmark mrmark authored mudrd8mz committed
View
87 backup/converter/moodle1/stepslib.php
@@ -351,7 +351,8 @@ public function convert_mod($data) {
$this->sequence[] = $data['ID'];
$info = new stdClass;
- $info->section = $this->id;
+ $info->sectionid = $this->id;
+ $info->sectionnumber = $this->data['NUMBER'];
foreach ($data as $name => $value) {
$name = strtolower($name);
$info->$name = $value;
@@ -374,4 +375,88 @@ public function execute_after_convert() {
$this->write_section_xml();
}
}
+}
+
+/**
+ * Writes out an activity's module.xml file
+ */
+class moodle1_module_structure_step extends moodle1_structure_step {
+ /**
+ * Module name
+ *
+ * @var string
+ */
+ protected $type;
+
+ /**
+ * The current Module ID
+ *
+ * @var int
+ */
+ protected $moduleid;
+
+ /**
+ * @param string $type The module name
+ */
+ public function __construct($name, $type, convert_task $task = null) {
+ $this->type = $type;
+ parent::__construct($name, $task);
+ }
+
+ /**
+ * Function that will return the structure to be processed by this convert_step.
+ * Must return one array of @convert_path_element elements
+ */
+ protected function define_structure() {
+ return array(); // @todo Hack?
+ }
+
+ /**
+ * 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->type}_{$this->moduleid}/module.xml";
+ }
+
+ public function get_new() {
+ return array(
+ 'visibleold' => 1,
+ 'completion' => 0,
+ 'completiongradeitemnumber' => NULL,
+ 'completionview' => 0,
+ 'completionexpected' => 0,
+ 'availablefrom' => 0,
+ 'availableuntil' => 0,
+ 'showavailability' => 1,
+ 'availability_info' => NULL,
+ );
+ }
+
+ public function get_renamed() {
+ return array(
+ 'type' => 'modulename',
+ );
+ }
+
+ public function get_deprecated() {
+ return array('id', 'instance');
+ }
+
+ public function execute_after_convert() {
+ global $DB;
+
+ $records = $DB->get_records('backup_ids_temp', array('backupid' => $this->get_convertid(), 'itemname' => $this->type));
+ foreach ($records as $record) {
+ $this->moduleid = $record->parentitemid;
+
+ $this->open_xml_writer();
+ $this->xmlwriter->begin_tag('module', array('id' => $this->moduleid, 'version' => '?')); // @todo What to do for version?
+ $this->convert_data((array) unserialize(base64_decode($record->info)));
+ $this->xmlwriter->end_tag('module');
+ $this->close_xml_writer();
+ }
+ }
}
View
35 backup/converter/moodle1/taskslib.php
@@ -43,11 +43,36 @@ public function build() {
}
}
-// @todo finnish this class...
-abstract class moodle1_activity_task extends convert_task {
- // @todo Implement methods that will for example write out the activities/type_cmid/module.xml
+abstract class moodle1_plugin_task extends convert_task {
+ /**
+ * Plugin specific steps
+ */
+ abstract protected function define_my_steps();
+}
+
+abstract class moodle1_activity_task extends moodle1_plugin_task {
+ /**
+ * Function responsible for building the steps of any task
+ * (must set the $built property to true)
+ */
+ public function build() {
+ $this->define_my_steps();
+
+ // @todo Risky?
+ list($plugin, $name) = explode('_', $this->name);
+
+ $this->add_step(new moodle1_module_structure_step("{$this->name}_module", $name));
+ $this->built = true;
+ }
}
-// @todo finnish this class...
-abstract class moodle1_block_task extends convert_task {
+abstract class moodle1_block_task extends moodle1_plugin_task {
+ /**
+ * Function responsible for building the steps of any task
+ * (must set the $built property to true)
+ */
+ public function build() {
+ $this->define_my_steps();
+ $this->built = true;
+ }
}
View
3  mod/forum/backup/moodle1/convert_forum_activity_task.class.php
@@ -10,8 +10,7 @@ class moodle1_forum_activity_task extends moodle1_activity_task {
* Function responsible for building the steps of any task
* (must set the $built property to true)
*/
- public function build() {
+ public function define_my_steps() {
$this->add_step(new moodle1_forum_activity_structure_step('forum'));
- $this->built = true;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.