MDL-8270 full block backup/restore - based on patches by Mark Nielsen and code in HEAD by Tim Hunt

This commit is contained in:
skodak
2008-03-23 15:50:08 +00:00
parent 90165e2d01
commit a18258a969
4 changed files with 307 additions and 79 deletions
+43 -6
View File
@@ -36,14 +36,51 @@ class block_html extends block_base {
return $this->content;
}
function backup_encode_absolute_links_in_config(&$config) {
$config->text = backup_encode_absolute_links($config->text);
/**
* Will be called before an instance of this block is backed up, so that any links in
* any links in any HTML fields on config can be encoded.
* @return string
*/
function get_backup_encoded_config() {
$data = clone($this->config);
$data->text = backup_encode_absolute_links($data->text);
return base64_encode(serialize($data));
}
function restore_decode_absolute_links_in_config(&$config) {
$oldtext = $config->text;
$config->text = restore_decode_absolute_links($oldtext);
return $config->text != $oldtext;
/**
* This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
* function in order to decode contents of this block from the backup
* format to destination site/course in order to mantain inter-activities
* working in the backup/restore process.
*
* This is called from {@link restore_decode_content_links()} function in the restore process.
*
* NOTE: There is no block instance when this method is called.
*
* @param object $restore Standard restore object
* @return boolean
**/
function decode_content_links_caller($restore) {
global $CFG;
if ($restored_blocks = get_records_select("backup_ids","table_name = 'block_instance' AND backup_code = $restore->backup_unique_code AND new_id > 0", "", "new_id")) {
$restored_blocks = implode(',', array_keys($restored_blocks));
$sql = "SELECT bi.*
FROM {$CFG->prefix}block_instance bi
JOIN {$CFG->prefix}block b ON b.id = bi.blockid
WHERE b.name = 'html' AND bi.id IN ($restored_blocks)";
if ($instances = get_records_sql($sql)) {
foreach ($instances as $instance) {
$blockobject = block_instance('html', $instance);
$blockobject->config->text = restore_decode_absolute_links($blockobject->config->text);
$blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore);
$blockobject->instance_config_commit($blockobject->pinned);
}
}
}
return true;
}
}
?>