MDL-32880: Add moodle1 backup converter for html block.
authorPaul Nicholls <paul.nicholls@canterbury.ac.nz>
Mon, 19 Nov 2012 22:59:51 +0000 (11:59 +1300)
committerPaul Nicholls <paul.nicholls@canterbury.ac.nz>
Thu, 22 Nov 2012 20:01:47 +0000 (09:01 +1300)
This converter processes the HTML block's content, migrating any referenced files.

blocks/html/backup/moodle1/lib.php [new file with mode: 0644]

diff --git a/blocks/html/backup/moodle1/lib.php b/blocks/html/backup/moodle1/lib.php
new file mode 100644 (file)
index 0000000..d4a491f
--- /dev/null
@@ -0,0 +1,46 @@
+<?php\r
+\r
+/**\r
+ * Provides support for the conversion of moodle1 backup to the moodle2 format\r
+ *\r
+ * @package    block_html\r
+ * @copyright  2012 Paul Nicholls\r
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r
+ */\r
+\r
+defined('MOODLE_INTERNAL') || die();\r
+\r
+/**\r
+ * Block conversion handler for html\r
+ */\r
+class moodle1_block_html_handler extends moodle1_block_handler {\r
+    private $fileman = null;\r
+    protected function convert_configdata(array $olddata) {\r
+        $instanceid = $olddata['id'];\r
+        $contextid  = $this->converter->get_contextid(CONTEXT_BLOCK, $olddata['id']);\r
+        $configdata = unserialize(base64_decode($olddata['configdata']));\r
+\r
+        // get a fresh new file manager for this instance\r
+        $this->fileman = $this->converter->get_file_manager($contextid, 'block_html');\r
+\r
+        // convert course files embedded in the block content\r
+        $this->fileman->filearea = 'content';\r
+        $this->fileman->itemid   = 0;\r
+        $configdata->text = moodle1_converter::migrate_referenced_files($configdata->text, $this->fileman);\r
+        $configdata->format = FORMAT_HTML;\r
+\r
+        return base64_encode(serialize($configdata));\r
+    }\r
+\r
+    protected function write_inforef_xml($newdata, $data) {\r
+        $this->open_xml_writer("course/blocks/{$data['name']}_{$data['id']}/inforef.xml");\r
+        $this->xmlwriter->begin_tag('inforef');\r
+        $this->xmlwriter->begin_tag('fileref');\r
+        foreach ($this->fileman->get_fileids() as $fileid) {\r
+            $this->write_xml('file', array('id' => $fileid));\r
+        }\r
+        $this->xmlwriter->end_tag('fileref');\r
+        $this->xmlwriter->end_tag('inforef');\r
+        $this->close_xml_writer();\r
+    }\r
+}
\ No newline at end of file