MDL-21432 backup - specialised blocks use the interlinks decoder
authorEloy Lafuente <stronk7@moodle.org>
Tue, 27 Jul 2010 23:47:12 +0000 (23:47 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Tue, 27 Jul 2010 23:47:12 +0000 (23:47 +0000)
blocks/html/backup/moodle2/restore_html_block_task.class.php
blocks/rss_client/backup/moodle2/restore_rss_client_block_task.class.php

index e30db89..dab463f 100644 (file)
@@ -44,8 +44,51 @@ class restore_html_block_task extends restore_block_task {
         return array('text'); // We need to encode some attrs in configdata
     }
 
-    static public function decode_content_links($content) {
-        return $content; // No special encoding of links
+    static public function define_decode_contents() {
+
+        $contents = array();
+
+        $contents[] = new restore_html_block_decode_content('block_instances', 'configdata', 'block_instance');
+
+        return $contents;
+    }
+
+    static public function define_decode_rules() {
+        return array();
     }
 }
 
+/**
+ * Specialised restore_decode_content provider that unserializes the configdata
+ * field, to serve the configdata->text content to the restore_decode_processor
+ * packaging it back to its serialized form after process
+ */
+class restore_html_block_decode_content extends restore_decode_content {
+
+    protected $configdata; // Temp storage for unserialized configdata
+
+    protected function get_iterator() {
+        global $DB;
+
+        // Build the SQL dynamically here
+        $fieldslist = 't.' . implode(', t.', $this->fields);
+        $sql = "SELECT t.id, $fieldslist
+                  FROM {" . $this->tablename . "} t
+                  JOIN {backup_ids_temp} b ON b.newitemid = t.id
+                 WHERE b.backupid = ?
+                   AND b.itemname = ?
+                   AND t.blockname = 'html'";
+        $params = array($this->restoreid, $this->mapping);
+        return ($DB->get_recordset_sql($sql, $params));
+    }
+
+    protected function preprocess_field($field) {
+        $this->configdata = unserialize(base64_decode($field));
+        return isset($this->configdata->text) ? $this->configdata->text : '';
+    }
+
+    protected function postprocess_field($field) {
+        $this->configdata->text = $field;
+        return base64_encode(serialize($this->configdata));
+    }
+}
index 9d72d6d..e3e29ff 100644 (file)
@@ -48,8 +48,12 @@ class restore_rss_client_block_task extends restore_block_task {
         return array(); // No special handling of configdata
     }
 
-    static public function decode_content_links($content) {
-        return $content; // No special encoding of links
+    static public function define_decode_contents() {
+        return array();
+    }
+
+    static public function define_decode_rules() {
+        return array();
     }
 }