MDL-17835 backup & restore - encode/decode content links from/to course formats info.
Credit goes to Mark Nielsen. Thanks! ; merged from 19_STABLE
This commit is contained in:
+20
-1
@@ -2314,7 +2314,7 @@
|
||||
//It does this conversions:
|
||||
// - $CFG->wwwroot/file.php/courseid ------------------> $@FILEPHP@$ (slasharguments links)
|
||||
// - $CFG->wwwroot/file.php?file=/courseid ------------> $@FILEPHP@$ (non-slasharguments links)
|
||||
// - Every module xxxx_encode_content_links() is executed too
|
||||
// - Every module/block/course_format xxxx_encode_content_links() is executed too
|
||||
//
|
||||
function backup_encode_absolute_links($content) {
|
||||
global $CFG,$preferences, $DB;
|
||||
@@ -2372,6 +2372,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
// For the current course format call its encode_content_links method (if it exists)
|
||||
static $format_function_name;
|
||||
if (!isset($format_function_name)) {
|
||||
$format_function_name = false;
|
||||
if ($format = $DB->get_field('course','format', array('id'=>$mypreferences->backup_course))) {
|
||||
if (file_exists("$CFG->dirroot/course/format/$format/backuplib.php")) {
|
||||
include_once("$CFG->dirroot/course/format/$format/backuplib.php");
|
||||
$function_name = $format.'_encode_format_content_links';
|
||||
if (function_exists($function_name)) {
|
||||
$format_function_name = $function_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the above worked - then we have a function to call
|
||||
if ($format_function_name) {
|
||||
$result = $format_function_name($result, $mypreferences);
|
||||
}
|
||||
|
||||
// For each block, call its encode_content_links method.
|
||||
// This encodes forexample links to blocks/something/viewphp?id=666
|
||||
// that are stored in other activities.
|
||||
|
||||
+38
-2
@@ -81,7 +81,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
|
||||
}
|
||||
|
||||
//This function makes all the necessary calls to xxxx_decode_content_links_caller()
|
||||
//function in each module, passing them the desired contents to be decoded
|
||||
//function in each module/block/course format..., passing them the desired contents to be decoded
|
||||
//from backup format to destination site/course in order to mantain inter-activities
|
||||
//working in the backup/restore process
|
||||
function restore_decode_content_links($restore) {
|
||||
@@ -148,6 +148,23 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
|
||||
}
|
||||
}
|
||||
|
||||
// For the course format call its decode_content_links method (if it exists)
|
||||
$format = $DB->get_field('course','format', array('id'=>$restore->course_id));
|
||||
if (file_exists("$CFG->dirroot/course/format/$format/restorelib.php")) {
|
||||
include_once("$CFG->dirroot/course/format/$format/restorelib.php");
|
||||
$function_name = $format.'_decode_format_content_links_caller';
|
||||
|
||||
if (function_exists($function_name)) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo "<li>".get_string ("from")." ".get_string("format").' '.$format;
|
||||
}
|
||||
$status = $function_name($restore);
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo '</li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process all html text also in blocks too
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo '<li>'.get_string ('from').' '.get_string('blocks');
|
||||
@@ -186,7 +203,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
|
||||
//its task is to ask all modules (maybe other linkable objects) to restore
|
||||
//links to them.
|
||||
function restore_decode_content_links_worker($content,$restore) {
|
||||
global $DB;
|
||||
global $CFG, $DB;
|
||||
|
||||
foreach($restore->mods as $name => $info) {
|
||||
$function_name = $name."_decode_content_links";
|
||||
@@ -195,6 +212,25 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
|
||||
}
|
||||
}
|
||||
|
||||
// For the current format, call decode_format_content_links if it exists
|
||||
static $format_function_name;
|
||||
if (!isset($format_function_name)) {
|
||||
$format_function_name = false;
|
||||
if ($format = $DB->get_field('course','format', array('id'=>$restore->course_id))) {
|
||||
if (file_exists("$CFG->dirroot/course/format/$format/restorelib.php")) {
|
||||
include_once("$CFG->dirroot/course/format/$format/restorelib.php");
|
||||
$function_name = $format.'_decode_format_content_links';
|
||||
if (function_exists($function_name)) {
|
||||
$format_function_name = $function_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the above worked - then we have a function to call
|
||||
if ($format_function_name) {
|
||||
$content = $format_function_name($content, $restore);
|
||||
}
|
||||
|
||||
// For each block, call its encode_content_links method
|
||||
static $blockobjects = null;
|
||||
if (!isset($blockobjects)) {
|
||||
|
||||
Reference in New Issue
Block a user