Index: blocks/html/block_html.php
===================================================================
RCS file: /home/cvs_repositories/globalcvs/ou-moodle/blocks/html/block_html.php,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 block_html.php
--- blocks/html/block_html.php 21 Mar 2006 10:23:49 -0000 1.1.1.1
+++ blocks/html/block_html.php 14 Nov 2007 16:36:00 -0000
@@ -1,4 +1,4 @@
-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;
}
}
?>
Index: backup/restorelib.php
===================================================================
RCS file: /home/cvs_repositories/globalcvs/ou-moodle/backup/restorelib.php,v
retrieving revision 1.59
diff -u -r1.59 restorelib.php
--- backup/restorelib.php 9 Nov 2007 16:42:15 -0000 1.59
+++ backup/restorelib.php 14 Nov 2007 16:36:00 -0000
@@ -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 '
' . 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 'Updating config for block ', $instance->id, '.
';
+ $instance->configdata = base64_encode(serialize($config));
+ $status = $status && update_record('block_instance', $instance);
+ }
+ }
+ }
+ if (!defined('RESTORE_SILENTLY')) {
+ echo '';
+ }
+
// Restore links in questions.
require_once("$CFG->dirroot/question/restorelib.php");
if (!defined('RESTORE_SILENTLY')) {
@@ -625,7 +646,7 @@
$course->summary = backup_todb($course_header->course_summary);
$course->format = addslashes($course_header->course_format);
// ou-specific begins
- if($course->format=='study' || $course->formats=='weeks') {
+ if($course->format=='study' || $course->format=='weeks') {
$course->format='studycal';
}
// ou-specific ends
@@ -779,6 +800,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;
@@ -871,6 +897,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;
Index: backup/backuplib.php
===================================================================
RCS file: /home/cvs_repositories/globalcvs/ou-moodle/backup/backuplib.php,v
retrieving revision 1.35
diff -u -r1.35 backuplib.php
--- backup/backuplib.php 12 Nov 2007 09:26:54 -0000 1.35
+++ backup/backuplib.php 14 Nov 2007 16:36:00 -0000
@@ -962,8 +962,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));
Index: blocks/moodleblock.class.php
===================================================================
RCS file: /home/cvs_repositories/globalcvs/ou-moodle/blocks/moodleblock.class.php,v
retrieving revision 1.17
diff -u -r1.17 moodleblock.class.php
--- blocks/moodleblock.class.php 13 Nov 2007 14:08:57 -0000 1.17
+++ blocks/moodleblock.class.php 14 Nov 2007 16:36:00 -0000
@@ -126,6 +126,28 @@
}
/**
+ * 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.
*