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

This commit is contained in:
skodak 2008-03-23 15:54:41 +00:00
parent 67562ddb0c
commit e43281ae78

View file

@ -104,7 +104,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string ("from")." ".get_string("modulenameplural",$name); echo "<li>".get_string ("from")." ".get_string("modulenameplural",$name);
} }
$status = $function_name($restore); $status = $function_name($restore) && $status;
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '</li>'; echo '</li>';
} }
@ -116,20 +116,14 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<li>'.get_string ('from').' '.get_string('blocks'); echo '<li>'.get_string ('from').' '.get_string('blocks');
} }
if (!empty($restore->blockinstanceids)) {
$blocks = blocks_get_record(); if ($blocks = get_records('block', 'visible', 1)) {
$instances = get_records_list('block_instance', 'id', implode(',', $restore->blockinstanceids), '', 'id,blockid,configdata'); foreach ($blocks as $block) {
foreach ($instances as $instance) { $blockobject = block_instance($block->name);
if (!isset($blocks[$instance->blockid]->blockobject)) { $blockobject->decode_content_links_caller($restore);
$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)) {
$instance->configdata = base64_encode(serialize($config));
$status = $status && update_record('block_instance', $instance);
}
} }
} }
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '</li>'; echo '</li>';
} }
@ -139,7 +133,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '<li>' . get_string('from') . ' ' . get_string('questions', 'quiz'); echo '<li>' . get_string('from') . ' ' . get_string('questions', 'quiz');
} }
$status = question_decode_content_links_caller($restore); $status = question_decode_content_links_caller($restore) && $status;
if (!defined('RESTORE_SILENTLY')) { if (!defined('RESTORE_SILENTLY')) {
echo '</li>'; echo '</li>';
} }
@ -161,6 +155,24 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$content = $function_name($content,$restore); $content = $function_name($content,$restore);
} }
} }
// For each block, call its encode_content_links method
static $blockobjects = null;
if (!isset($blockobjects)) {
$blockobjects = array();
if ($blocks = get_records('block', 'visible', 1)) {
foreach ($blocks as $block) {
if ($blockobject = block_instance($block->name)) {
$blockobjects[] = $blockobject;
}
}
}
}
foreach ($blockobjects as $blockobject) {
$content = $blockobject->decode_content_links($content,$restore);
}
return $content; return $content;
} }
@ -762,7 +774,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// Looks like it's from Moodle < 1.3. Let's give the course default blocks... // Looks like it's from Moodle < 1.3. Let's give the course default blocks...
$newpage = page_create_object(PAGE_COURSE_VIEW, $restore->course_id); $newpage = page_create_object(PAGE_COURSE_VIEW, $restore->course_id);
blocks_repopulate_page($newpage); blocks_repopulate_page($newpage);
} else { } else if (!empty($CFG->showblocksonmodpages)) {
// We just have a blockinfo field, this is a legacy 1.4 or 1.3 backup // We just have a blockinfo field, this is a legacy 1.4 or 1.3 backup
$blockrecords = get_records_select('block', '', '', 'name, id'); $blockrecords = get_records_select('block', '', '', 'name, id');
$temp_blocks_l = array(); $temp_blocks_l = array();
@ -809,11 +821,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
function restore_create_block_instances($restore,$xml_file) { function restore_create_block_instances($restore,$xml_file) {
global $CFG; global $CFG;
$status = true; $status = true;
$CFG->restore_blockinstanceids = array();
// Tracks which blocks we create during the restore.
// This is used in restore_decode_content_links.
$restore->blockinstanceids = array();
//Check it exists //Check it exists
if (!file_exists($xml_file)) { if (!file_exists($xml_file)) {
@ -839,8 +846,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if($instance->pagetype == PAGE_COURSE_VIEW) { if($instance->pagetype == PAGE_COURSE_VIEW) {
// This one's easy... // This one's easy...
$instance->pageid = $restore->course_id; $instance->pageid = $restore->course_id;
}
else { } else if (!empty($CFG->showblocksonmodpages)) {
$parts = explode('-', $instance->pagetype); $parts = explode('-', $instance->pagetype);
if($parts[0] == 'mod') { if($parts[0] == 'mod') {
if(!$restore->mods[$parts[1]]->restore) { if(!$restore->mods[$parts[1]]->restore) {
@ -858,6 +865,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
// Not invented here ;-) // Not invented here ;-)
continue; continue;
} }
} else {
// do not restore activity blocks if disabled
continue;
} }
if(!isset($pageinstances[$instance->pagetype])) { if(!isset($pageinstances[$instance->pagetype])) {
@ -870,7 +881,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
$pageinstances[$instance->pagetype][$instance->pageid][] = $instance; $pageinstances[$instance->pagetype][$instance->pageid][] = $instance;
} }
$blocks = get_records_select('block', '', '', 'name, id, multiple'); $blocks = get_records_select('block', 'visible = 1', '', 'name, id, multiple');
// For each type of page we have restored // For each type of page we have restored
foreach($pageinstances as $thistypeinstances) { foreach($pageinstances as $thistypeinstances) {
@ -917,15 +928,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
} }
if ($instance->id = insert_record('block_instance', $instance)) { if ($instance->id = insert_record('block_instance', $instance)) {
// Save the new ID for later+
$CFG->restore_blockinstanceids[] = $instance->id;
// Create block instance // Create block instance
if (!$blockobj = block_instance($instance->name, $instance)) { if (!$blockobj = block_instance($instance->name, $instance)) {
$status = false; $status = false;
break; break;
} }
// Run the block restore if needed // Run the block restore if needed
if ($blockobj->backuprestore_enabled()) { if ($blockobj->backuprestore_instancedata_used()) {
// Get restore information // Get restore information
$data = backup_getid($restore->backup_unique_code,'block_instance',$oldid); $data = backup_getid($restore->backup_unique_code,'block_instance',$oldid);
$data->new_id = $instance->id; // For completeness $data->new_id = $instance->id; // For completeness
@ -938,7 +947,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
if ($oldid) { if ($oldid) {
backup_putid ($restore->backup_unique_code,"block_instance",$oldid,$instance->id); backup_putid ($restore->backup_unique_code,"block_instance",$oldid,$instance->id);
} }
$restore->blockinstanceids[] = $instance->id;
} else { } else {
$status = false; $status = false;
break; break;
@ -4315,7 +4324,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
//if ($this->tree[3] == "BLOCKS") //Debug //if ($this->tree[3] == "BLOCKS") //Debug
// echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br />\n"; //Debug // echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br />\n"; //Debug
//If we are under a BLOCK tag under a BLOCKS zone, accumule it //If we are under a BLOCK tag under a BLOCKS zone, accumule it
if (isset($this->tree[4]) and isset($this->tree[3])) { // if (isset($this->tree[4]) and isset($this->tree[3])) { //
if ($this->tree[4] == "BLOCK" and $this->tree[3] == "BLOCKS") { if ($this->tree[4] == "BLOCK" and $this->tree[3] == "BLOCKS") {