From: skodak Date: Sun, 23 Mar 2008 15:54:41 +0000 (+0000) Subject: MDL-8270 full block backup/restore - based on patches by Mark Nielsen and code in... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e43281ae78f205e57ac3057a1a4470ee22670eee;p=moodle.git MDL-8270 full block backup/restore - based on patches by Mark Nielsen and code in HEAD by Tim Hunt; merged from MOODLE_19_STABLE --- diff --git a/backup/restorelib.php b/backup/restorelib.php index 3bc2f864dd..221b6c8d5a 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -104,7 +104,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); if (!defined('RESTORE_SILENTLY')) { echo "
  • ".get_string ("from")." ".get_string("modulenameplural",$name); } - $status = $function_name($restore); + $status = $function_name($restore) && $status; if (!defined('RESTORE_SILENTLY')) { echo '
  • '; } @@ -114,22 +114,16 @@ define('RESTORE_GROUPS_GROUPINGS', 3); // Process all html text also in blocks too if (!defined('RESTORE_SILENTLY')) { - echo '
  • ' . get_string ('from') . ' ' . get_string('blocks'); + 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)) { - $instance->configdata = base64_encode(serialize($config)); - $status = $status && update_record('block_instance', $instance); - } + + if ($blocks = get_records('block', 'visible', 1)) { + foreach ($blocks as $block) { + $blockobject = block_instance($block->name); + $blockobject->decode_content_links_caller($restore); } } + if (!defined('RESTORE_SILENTLY')) { echo '
  • '; } @@ -139,7 +133,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); if (!defined('RESTORE_SILENTLY')) { echo '
  • ' . 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')) { echo '
  • '; } @@ -161,6 +155,24 @@ define('RESTORE_GROUPS_GROUPINGS', 3); $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; } @@ -762,7 +774,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); // 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); 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 $blockrecords = get_records_select('block', '', '', 'name, id'); $temp_blocks_l = array(); @@ -809,11 +821,6 @@ define('RESTORE_GROUPS_GROUPINGS', 3); function restore_create_block_instances($restore,$xml_file) { global $CFG; $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 if (!file_exists($xml_file)) { @@ -839,8 +846,8 @@ define('RESTORE_GROUPS_GROUPINGS', 3); if($instance->pagetype == PAGE_COURSE_VIEW) { // This one's easy... $instance->pageid = $restore->course_id; - } - else { + + } else if (!empty($CFG->showblocksonmodpages)) { $parts = explode('-', $instance->pagetype); if($parts[0] == 'mod') { if(!$restore->mods[$parts[1]]->restore) { @@ -858,6 +865,10 @@ define('RESTORE_GROUPS_GROUPINGS', 3); // Not invented here ;-) continue; } + + } else { + // do not restore activity blocks if disabled + continue; } if(!isset($pageinstances[$instance->pagetype])) { @@ -870,7 +881,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); $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 foreach($pageinstances as $thistypeinstances) { @@ -917,15 +928,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3); } if ($instance->id = insert_record('block_instance', $instance)) { - // Save the new ID for later+ - $CFG->restore_blockinstanceids[] = $instance->id; // Create block instance if (!$blockobj = block_instance($instance->name, $instance)) { $status = false; break; } // Run the block restore if needed - if ($blockobj->backuprestore_enabled()) { + if ($blockobj->backuprestore_instancedata_used()) { // Get restore information $data = backup_getid($restore->backup_unique_code,'block_instance',$oldid); $data->new_id = $instance->id; // For completeness @@ -938,7 +947,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); if ($oldid) { backup_putid ($restore->backup_unique_code,"block_instance",$oldid,$instance->id); } - $restore->blockinstanceids[] = $instance->id; + } else { $status = false; break; @@ -4314,8 +4323,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); //Check if we are into BLOCKS zone //if ($this->tree[3] == "BLOCKS") //Debug // echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName.">
    \n"; //Debug - - + //If we are under a BLOCK tag under a BLOCKS zone, accumule it if (isset($this->tree[4]) and isset($this->tree[3])) { // if ($this->tree[4] == "BLOCK" and $this->tree[3] == "BLOCKS") { @@ -5116,13 +5124,13 @@ define('RESTORE_GROUPS_GROUPINGS', 3); //if (trim($this->content)) //Debug // echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."
    \n"; //Debug //echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName.">
    \n"; //Debug - + // Collect everything into $this->temp if (!isset($this->temp)) { $this->temp = ""; } $this->temp .= htmlspecialchars(trim($this->content)).""; - + //Dependig of different combinations, do different things if ($this->level == 4) { switch ($tagName) { @@ -5130,7 +5138,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); //We've finalized a block, get it $this->info->instances[] = $this->info->tempinstance; unset($this->info->tempinstance); - + //Also, xmlize INSTANCEDATA and save to db //Prepend XML standard header to info gathered $xml_data = "\n".$this->temp; @@ -5160,7 +5168,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3); } //Reset temp unset($this->temp); - + break; default: die($tagName);