mirror of
https://github.com/moodle/moodle.git
synced 2025-03-15 05:00:06 +01:00
MDL-12066 - Links in the HTML block are not recoded on backup and restore.
This is messy because the links are hidden in the configdata column, which is serialized and base64encoded. So we have to untangle that, then ask the block whether there are any bits of $config that need to be fixed, then re-encode it before backup up. And reverse that on restore. It needs to remain base64 encoded in the backup file, so that the file format is backwards compatible. I disucssed this with Eloy before doing it. Merged from MOODLE_19_STABLE.
This commit is contained in:
parent
9cb69c1910
commit
43457dc87c
@ -957,8 +957,16 @@
|
||||
if(empty($blocks[$instance->blockid]->name)) {
|
||||
continue;
|
||||
}
|
||||
//Begin Block
|
||||
|
||||
//Give the block a chance to process any links in configdata.
|
||||
if (!isset($blocks[$instance->blockid]->blockobject)) {
|
||||
$blocks[$instance->blockid]->blockobject = block_instance($blocks[$instance->blockid]->name);
|
||||
}
|
||||
$config = unserialize(base64_decode($instance->configdata));
|
||||
$blocks[$instance->blockid]->blockobject->backup_encode_absolute_links_in_config($config);
|
||||
$instance->configdata = base64_encode(serialize($config));
|
||||
|
||||
//Begin Block
|
||||
fwrite ($bf,start_tag('BLOCK',3,true));
|
||||
fwrite ($bf,full_tag('ID', 4, false,$instance->id));
|
||||
fwrite ($bf,full_tag('NAME',4,false,$blocks[$instance->blockid]->name));
|
||||
|
@ -90,8 +90,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: process all html text also in blocks too
|
||||
|
||||
// Process all html text also in blocks too
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo '<li>' . get_string ('from') . ' ' . get_string('blocks');
|
||||
}
|
||||
if (!empty($restore->blockinstanceids)) {
|
||||
$blocks = blocks_get_record();
|
||||
$instances = get_records_list('block_instance', 'id', implode(',', $restore->blockinstanceids), '', 'id,blockid,configdata');
|
||||
foreach ($instances as $instance) {
|
||||
if (!isset($blocks[$instance->blockid]->blockobject)) {
|
||||
$blocks[$instance->blockid]->blockobject = block_instance($blocks[$instance->blockid]->name);
|
||||
}
|
||||
$config = unserialize(base64_decode($instance->configdata));
|
||||
if ($blocks[$instance->blockid]->blockobject->restore_decode_absolute_links_in_config($config)) {
|
||||
echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
$instance->configdata = base64_encode(serialize($config));
|
||||
$status = $status && update_record('block_instance', $instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo '</li>';
|
||||
}
|
||||
|
||||
// Restore links in questions.
|
||||
require_once("$CFG->dirroot/question/restorelib.php");
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
@ -759,6 +780,11 @@
|
||||
function restore_create_block_instances($restore,$xml_file) {
|
||||
|
||||
$status = true;
|
||||
|
||||
// Tracks which blocks we create during the restore.
|
||||
// This is used in restore_decode_content_links.
|
||||
$restore->blockinstanceids = array();
|
||||
|
||||
//Check it exists
|
||||
if (!file_exists($xml_file)) {
|
||||
$status = false;
|
||||
@ -851,6 +877,7 @@
|
||||
if (!empty($instance->id)) { // this will only be set if we come from 1.7 and above backups
|
||||
backup_putid ($restore->backup_unique_code,"block_instance",$instance->id,$newid);
|
||||
}
|
||||
$restore->blockinstanceids[] = $newid;
|
||||
} else {
|
||||
$status = false;
|
||||
break;
|
||||
|
@ -35,5 +35,16 @@ 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);
|
||||
}
|
||||
|
||||
function restore_decode_absolute_links_in_config(&$config) {
|
||||
debugging("In block_html::restore_decode_absolute_links_in_config"); // DONOTCOMMIT
|
||||
$oldtext = $config->text;
|
||||
$config->text = restore_decode_absolute_links($oldtext);
|
||||
return $config->text != $oldtext;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -125,6 +125,28 @@ class block_base {
|
||||
function after_restore($restore) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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. For example, for the HTML block
|
||||
* we need to do $config->text = backup_encode_absolute_links($config->text);.
|
||||
*
|
||||
* @param object $config the config field for an insance of this class.
|
||||
*/
|
||||
function backup_encode_absolute_links_in_config(&$config) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo the effect of backup_encode_absolute_links_in_config. For exmaple, in the
|
||||
* HTML block we need to do $config->text = restore_decode_absolute_links($config->text);
|
||||
*
|
||||
* @param object $config the config field for an insance of this class.
|
||||
* @return boolean return true if something has changed, so the database can be updated,
|
||||
* false if not, for efficiency reasons.
|
||||
*/
|
||||
function restore_decode_absolute_links_in_config(&$config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the block name, as present in the class name,
|
||||
* the database, the block directory, etc etc.
|
||||
|
Loading…
x
Reference in New Issue
Block a user