Skip to content

Commit

Permalink
filters: MDL-7336 refactor in backup/restore ready for local filter s…
Browse files Browse the repository at this point in the history
…ettings.
  • Loading branch information
tjhunt committed Apr 13, 2009
1 parent 6b037e0 commit 7b8dcbc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
38 changes: 22 additions & 16 deletions backup/backuplib.php
Expand Up @@ -715,12 +715,11 @@ function backup_course_start ($bf,$preferences) {
fwrite ($bf,full_tag("ENROLENDDATE",3,false,$course->enrolenddate));
fwrite ($bf,full_tag("ENROLPERIOD",3,false,$course->enrolperiod));
fwrite ($bf,full_tag("ENABLECOMPLETION",3,false,$course->enablecompletion));

/// write local course overrides here?
write_role_overrides_xml($bf, $context, 3);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 3);
//Print header end

// Write role assigns, overrides, etc.
write_per_context_data($bf, $preferences, $context, 3);

// Print header end
fwrite ($bf,end_tag("HEADER",2,true));
} else {
$status = false;
Expand Down Expand Up @@ -1073,10 +1072,11 @@ function backup_course_blocks ($bf,$preferences) {
$status = $blockobj->instance_backup($bf, $preferences);
fwrite ($bf,end_tag('INSTANCEDATA',4,true));
}

// Write role assigns, overrides, etc.
$context = get_context_instance(CONTEXT_BLOCK, $instance->id);
write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 4);
write_per_context_data($bf, $preferences, $context, 4);

//End Block
fwrite ($bf,end_tag('BLOCK',3,true));
}
Expand Down Expand Up @@ -1233,10 +1233,9 @@ function backup_course_modules ($bf,$preferences,$section) {
fwrite ($bf,full_tag("AVAILABLEUNTIL",6,false,$course_module->availableuntil));
fwrite ($bf,full_tag("SHOWAVAILABILITY",6,false,$course_module->showavailability));

// get all the role_capabilities overrides in this mod
write_role_overrides_xml($bf, $context, 6);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 6);
// Write role assigns, overrides, etc.
write_per_context_data($bf, $preferences, $context, 6);

// write completion data if enabled and user data enabled
require_once($CFG->libdir.'/completionlib.php');
$completion=new completion_info($course);
Expand Down Expand Up @@ -1460,11 +1459,10 @@ function backup_user_info ($bf,$preferences) {
fwrite ($bf,end_tag("USER_PREFERENCES",4,true));
}

// Write role assigns, overrides, etc.
$context = get_context_instance(CONTEXT_USER, $user->old_id);
write_per_context_data($bf, $preferences, $context, 4);

write_role_overrides_xml($bf, $context, 4);
/// write role_assign code here
write_role_assignments_xml($bf, $preferences, $context, 4);
//End User tag
fwrite ($bf,end_tag("USER",3,true));
//Do some output
Expand Down Expand Up @@ -2817,6 +2815,14 @@ function backup_fetch_roles($preferences) {
return $roles;
}

/**
* Writes out all of the data that should appear for every context.
*/
function write_per_context_data($bf, $preferences, $context, $startlevel) {
write_role_overrides_xml($bf, $context, $startlevel);
write_role_assignments_xml($bf, $preferences, $context, $startlevel);
}

/**
* function to print xml for overrides
*/
Expand Down
6 changes: 3 additions & 3 deletions backup/restorelib.php
Expand Up @@ -8682,7 +8682,7 @@ function restore_execute(&$restore,$info,$course_header,&$errorstr) {
// try to restore roles even when restore is going to fail - teachers might have
// at least some role assigned - this is not correct though
$status = restore_create_roles($restore, $xml_file) && $status;
$status = restore_roles_settings($restore, $xml_file) && $status;
$status = restore_roles_and_filter_settings($restore, $xml_file) && $status;

//Now if all is OK, update:
// - course modinfo field
Expand All @@ -8696,7 +8696,7 @@ function restore_execute(&$restore,$info,$course_header,&$errorstr) {
$course = $DB->get_record("course", array("id"=>$restore->course_id));
fix_course_sortorder();
// Check if the user has course update capability in the newly restored course
// there is no need to load his capabilities again, because restore_roles_settings
// there is no need to load his capabilities again, because restore_roles_and_filter_settings
// would have loaded it anyway, if there is any assignments.
// fix for MDL-6831
$newcontext = get_context_instance(CONTEXT_COURSE, $restore->course_id);
Expand Down Expand Up @@ -8992,7 +8992,7 @@ function restore_create_roles($restore, $xmlfile) {
* in course/user/block/mod level, it passed through
* the xml file again
*/
function restore_roles_settings($restore, $xmlfile) {
function restore_roles_and_filter_settings($restore, $xmlfile) {
// data pulls from course, mod, user, and blocks

/*******************************************************
Expand Down

0 comments on commit 7b8dcbc

Please sign in to comment.