MDL-32880: Add moodle1 backup converter for rss_client block.
authorPaul Nicholls <paul.nicholls@canterbury.ac.nz>
Wed, 7 Nov 2012 01:06:03 +0000 (14:06 +1300)
committerPaul Nicholls <paul.nicholls@canterbury.ac.nz>
Thu, 22 Nov 2012 20:01:59 +0000 (09:01 +1300)
Creates a shell rss_client.xml file, which contains no feeds.  This makes it behave the same as restoring a Moodle 1.9 backup into a different 1.9 site - the block is created, its title is as per the original course, but it has no feeds selected (and none are added to the site's feed list).

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

diff --git a/blocks/rss_client/backup/moodle1/lib.php b/blocks/rss_client/backup/moodle1/lib.php
new file mode 100644 (file)
index 0000000..95da634
--- /dev/null
@@ -0,0 +1,34 @@
+<?php\r
+\r
+/**\r
+ * Provides support for the conversion of moodle1 backup to the moodle2 format\r
+ *\r
+ * @package    block_rss_client\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 rss_client\r
+ */\r
+class moodle1_block_rss_client_handler extends moodle1_block_handler {\r
+    public function process_block(array $data) {\r
+        parent::process_block($data);\r
+        $instanceid = $data['id'];\r
+        $contextid = $this->converter->get_contextid(CONTEXT_BLOCK, $data['id']);\r
+\r
+        // Moodle 1.9 backups do not include sufficient data to restore feeds, so we need an empty shell rss_client.xml\r
+        // for the restore process to find\r
+        $this->open_xml_writer("course/blocks/{$data['name']}_{$instanceid}/rss_client.xml");\r
+        $this->xmlwriter->begin_tag('block', array('id' => $instanceid, 'contextid' => $contextid, 'blockname' => 'rss_client'));\r
+        $this->xmlwriter->begin_tag('rss_client', array('id' => $instanceid));\r
+        $this->xmlwriter->full_tag('feeds', '');\r
+        $this->xmlwriter->end_tag('rss_client');\r
+        $this->xmlwriter->end_tag('block');\r
+        $this->close_xml_writer();\r
+\r
+        return $data;\r
+    }\r
+}
\ No newline at end of file