Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Creating stepslib.php and taskslib.php

  • Loading branch information...
commit be145927c5059c297d9d857b0813f63ae2a44b38 1 parent 56bd1ab
@mrmark mrmark authored mudrd8mz committed
View
158 backup/converter/moodle1/converter.class.php
@@ -1,5 +1,11 @@
<?php
/**
+ * All of the task and step classes specific to moodle1 conversion
+ */
+require_once($CFG->dirroot.'/backup/converter/moodle1/taskslib.php');
+require_once($CFG->dirroot.'/backup/converter/moodle1/stepslib.php');
+
+/**
* This will be the Moodle 1 to Moodle 2 Converter
*/
class moodle1_converter extends plan_converter {
@@ -45,155 +51,3 @@ public function destroy() {
}
-
-// @todo Where to store these classes?
-
-class moodle1_root_task extends convert_task {
- /**
- * Function responsible for building the steps of any task
- * (must set the $built property to true)
- */
- public function build() {
- $this->add_step(new convert_create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
-
- // At the end, mark it as built
- $this->built = true;
- }
-
-}
-
-class moodle1_final_task extends convert_task {
- /**
- * Function responsible for building the steps of any task
- * (must set the $built property to true)
- */
- public function build() {
- $this->add_step(new convert_drop_and_clean_temp_stuff('drop_and_clean_temp_stuff'));
-
- // At the end, mark it as built
- $this->built = true;
- }
-}
-
-class moodle1_course_task extends convert_task {
- /**
- * Create all the steps that will be part of this task
- */
- public function build() {
-
- $this->add_step(new moodle1_course_structure_step('course_info'));
-
- // At the end, mark it as built
- $this->built = true;
- }
-}
-
-class moodle1_course_structure_step extends convert_structure_step {
- protected $id;
- /**
- * @var xml_writer
- */
- protected $xmlwriter;
-
- protected $deprecated = array(
- 'roles_overrides',
- 'roles_assignments',
- 'cost',
- 'currancy',
- 'defaultrole',
- 'enrol',
- 'enrolenddate',
- 'enrollable',
- 'enrolperiod',
- 'enrolstartdate',
- 'expirynotify',
- 'expirythreshold',
- 'guest',
- 'notifystudents',
- 'password',
- 'student',
- 'students',
- 'teacher',
- 'teachers',
- 'metacourse',
- );
-
- /**
- * 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() {
- $paths = array();
- $paths[] = new convert_path_element('course', '/MOODLE_BACKUP/COURSE/HEADER');
- $paths[] = new convert_path_element('category', '/MOODLE_BACKUP/COURSE/HEADER/CATEGORY');
-
- return $paths;
- }
-
- public function open_writer() {
- if (!$this->xmlwriter instanceof xml_writer) {
- if (empty($this->id)) {
- throw new backup_exception('noidfound'); // @todo define string or dynamically make id
- }
- $directory = $this->get_converter()->get_convertdir().'/course';
- if (!check_dir_exists($directory)) {
- throw new backup_exception('failedtomakeconvertdir'); // @todo Define this string
- }
- $this->xmlwriter = new xml_writer(
- new file_xml_output($directory.'/course.xml')
- );
- $this->xmlwriter->start();
- $this->xmlwriter->begin_tag('course', array(
- 'id' => $this->id,
- 'contextid' => convert_helper::get_contextid($this->id, 'course')
- ));
- }
- }
-
- /**
- * This is actually called twice because category is defined
- * right after ID in the XML... any way around that? Only
- * idea is to patch Moodle 1.9
- *
- * @throws backup_exception
- * @param $data
- * @return void
- */
- public function convert_course($data) {
- // print_object($data); // DEBUG
- if (array_key_exists('ID', $data)) {
- $this->id = $data['ID'];
- unset($data['ID']);
- }
- if (empty($data)) {
- return;
- }
- $this->open_writer();
-
- foreach ($data as $name => $value) {
- $name = strtolower($name);
-
- if (in_array($name, $this->deprecated)) {
- continue;
- }
- $this->xmlwriter->full_tag($name, $value);
- }
- }
-
- public function convert_category($data) {
- // print_object($data); // DEBUG
- $this->open_writer();
- $this->xmlwriter->begin_tag('category', array('id' => $data['ID']));
- $this->xmlwriter->full_tag('name', $data['NAME']);
- $this->xmlwriter->end_tag('category');
- }
-
- public function execute_after_convert() {
- if ($this->xmlwriter instanceof xml_writer) {
- $this->xmlwriter->end_tag('course');
- $this->xmlwriter->stop();
- unset($this->xmlwriter);
- // var_dump(file_get_contents($this->get_converter()->get_convertdir().'/course/course.xml')); // DEBUG
- }
- }
-}
View
110 backup/converter/moodle1/stepslib.php
@@ -0,0 +1,110 @@
+<?php
+class moodle1_course_structure_step extends convert_structure_step {
+ protected $id;
+ /**
+ * @var xml_writer
+ */
+ protected $xmlwriter;
+
+ protected $deprecated = array(
+ 'roles_overrides',
+ 'roles_assignments',
+ 'cost',
+ 'currancy',
+ 'defaultrole',
+ 'enrol',
+ 'enrolenddate',
+ 'enrollable',
+ 'enrolperiod',
+ 'enrolstartdate',
+ 'expirynotify',
+ 'expirythreshold',
+ 'guest',
+ 'notifystudents',
+ 'password',
+ 'student',
+ 'students',
+ 'teacher',
+ 'teachers',
+ 'metacourse',
+ );
+
+ /**
+ * 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() {
+ $paths = array();
+ $paths[] = new convert_path_element('course', '/MOODLE_BACKUP/COURSE/HEADER');
+ $paths[] = new convert_path_element('category', '/MOODLE_BACKUP/COURSE/HEADER/CATEGORY');
+
+ return $paths;
+ }
+
+ public function open_writer() {
+ if (!$this->xmlwriter instanceof xml_writer) {
+ if (empty($this->id)) {
+ throw new backup_exception('noidfound'); // @todo define string or dynamically make id
+ }
+ $directory = $this->get_converter()->get_convertdir().'/course';
+ if (!check_dir_exists($directory)) {
+ throw new backup_exception('failedtomakeconvertdir'); // @todo Define this string
+ }
+ $this->xmlwriter = new xml_writer(
+ new file_xml_output($directory.'/course.xml')
+ );
+ $this->xmlwriter->start();
+ $this->xmlwriter->begin_tag('course', array(
+ 'id' => $this->id,
+ 'contextid' => convert_helper::get_contextid($this->id, 'course')
+ ));
+ }
+ }
+
+ /**
+ * This is actually called twice because category is defined
+ * right after ID in the XML... any way around that? Only
+ * idea is to patch Moodle 1.9
+ *
+ * @throws backup_exception
+ * @param $data
+ * @return void
+ */
+ public function convert_course($data) {
+ // print_object($data); // DEBUG
+ if (array_key_exists('ID', $data)) {
+ $this->id = $data['ID'];
+ unset($data['ID']);
+ }
+ if (empty($data)) {
+ return;
+ }
+ $this->open_writer();
+
+ foreach ($data as $name => $value) {
+ $name = strtolower($name);
+
+ if (in_array($name, $this->deprecated)) {
+ continue;
+ }
+ $this->xmlwriter->full_tag($name, $value);
+ }
+ }
+
+ public function convert_category($data) {
+ // print_object($data); // DEBUG
+ $this->open_writer();
+ $this->xmlwriter->begin_tag('category', array('id' => $data['ID']));
+ $this->xmlwriter->full_tag('name', $data['NAME']);
+ $this->xmlwriter->end_tag('category');
+ }
+
+ public function execute_after_convert() {
+ if ($this->xmlwriter instanceof xml_writer) {
+ $this->xmlwriter->end_tag('course');
+ $this->xmlwriter->stop();
+ unset($this->xmlwriter);
+ // var_dump(file_get_contents($this->get_converter()->get_convertdir().'/course/course.xml')); // DEBUG
+ }
+ }
+}
View
44 backup/converter/moodle1/taskslib.php
@@ -0,0 +1,44 @@
+<?php
+class moodle1_root_task extends convert_task {
+ /**
+ * Function responsible for building the steps of any task
+ * (must set the $built property to true)
+ */
+ public function build() {
+ $this->add_step(new convert_create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
+
+ // At the end, mark it as built
+ $this->built = true;
+ }
+
+}
+
+/**
+ * @todo Not used at the moment
+ */
+class moodle1_final_task extends convert_task {
+ /**
+ * Function responsible for building the steps of any task
+ * (must set the $built property to true)
+ */
+ public function build() {
+ $this->add_step(new convert_drop_and_clean_temp_stuff('drop_and_clean_temp_stuff'));
+
+ // At the end, mark it as built
+ $this->built = true;
+ }
+}
+
+class moodle1_course_task extends convert_task {
+ /**
+ * Create all the steps that will be part of this task
+ */
+ public function build() {
+
+ $this->add_step(new moodle1_course_structure_step('course_info'));
+
+ // At the end, mark it as built
+ $this->built = true;
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.