Skip to content

Commit

Permalink
MDL-21432 backup - specialised blocks use the interlinks decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 27, 2010
1 parent bad08e7 commit dd0a750
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
47 changes: 45 additions & 2 deletions blocks/html/backup/moodle2/restore_html_block_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,51 @@ public function get_configdata_encoded_attributes() {
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public function get_configdata_encoded_attributes() {
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();
}
}

0 comments on commit dd0a750

Please sign in to comment.