Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding basic block instance conversion

  • Loading branch information...
commit 8e2c53665ec0e87414d48adfb654caf3e0a1e4d5 1 parent 5aee1af
@mrmark mrmark authored mudrd8mz committed
View
103 backup/converter/moodle1/stepslib.php
@@ -459,4 +459,107 @@ public function execute_after_convert() {
$this->close_xml_writer();
}
}
+}
+
+/**
+ * Write out a block's block.xml file
+ */
+class moodle1_block_structure_step extends moodle1_structure_step {
+ /**
+ * The block's instance ID
+ *
+ * @var int
+ */
+ protected $instanceid;
+
+ /**
+ * The block's name
+ *
+ * @var string
+ */
+ protected $blockname;
+
+ /**
+ * 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(
+ new convert_path_element('block', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'),
+ );
+ }
+
+ /**
+ * 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 "course/blocks/{$this->blockname}_{$this->instanceid}/block.xml";
+ }
+
+ public function get_new() {
+ return array(
+ 'showinsubcontexts' => 0,
+ 'subpagepattern' => NULL,
+ 'block_positions' => NULL,
+ );
+ }
+
+ public function get_renamed() {
+ return array(
+ 'name' => 'blockname',
+ 'pageid' => 'parentcontextid',
+ 'pagetype' => 'pagetypepattern',
+ 'position' => 'defaultregion',
+ 'weight' => 'defaultweight',
+ );
+ }
+
+ public function get_deprecated() {
+ return array(
+ 'id',
+ 'visible',
+ 'roles_overrides',
+ 'roles_assignments',
+ );
+ }
+
+ public function mutate_datum($name, $datum) {
+ if ($name == 'pagetypepattern') {
+ if ($datum == 'course-view') {
+ $datum = 'course-view-*';
+ }
+
+ } else if ($name == 'defaultregion') {
+ if ($datum == 'r') {
+ $datum = BLOCK_POS_RIGHT;
+ } else {
+ $datum = BLOCK_POS_LEFT;
+ }
+ }
+ return $datum;
+ }
+
+ public function convert_block($data) {
+ $this->instanceid = $data['ID'];
+ $this->blockname = $data['NAME'];
+
+ $contextid = convert_helper::get_contextid($this->instanceid, "block_$this->name", $this->get_convertid());
+
+ // Map PAGEID to context ID
+ if ($data['PAGETYPE'] == 'course-view') {
+ $data['PAGEID'] = convert_helper::get_contextid($data['PAGEID'], 'course', $this->get_convertid());
+ } else if (strpos($data['PAGETYPE'], 'mod-') === 0) { // EG: mod-quiz-view
+ $parts = explode('-', $data['PAGETYPE']);
+ $data['PAGEID'] = convert_helper::get_contextid($data['PAGEID'], $parts[1], $this->get_convertid());
+ }
+
+ $this->open_xml_writer();
+ $this->xmlwriter->begin_tag('block', array('id' => $this->instanceid, 'contextid' => $contextid));
+ $this->convert_data($data);
+ $this->xmlwriter->end_tag('block');
+ $this->close_xml_writer();
+ }
}
View
1  backup/converter/moodle1/taskslib.php
@@ -37,6 +37,7 @@ public function build() {
$this->add_step(new moodle1_course_structure_step('course_info'));
$this->add_step(new moodle1_section_structure_step('course_section'));
+ $this->add_step(new moodle1_block_structure_step('course_blocks'));
// At the end, mark it as built
$this->built = true;
Please sign in to comment.
Something went wrong with that request. Please try again.