From 013b90ed924ab4884c7638e4198b175ed89c3db1 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Thu, 5 Oct 2006 04:05:07 +0000 Subject: [PATCH] a few fixes, for MDL-6836, MDL-6835, and MDL-6765 --- backup/backuplib.php | 7 ++++-- backup/restore_form.html | 3 ++- backup/restorelib.php | 52 +++++++++++++--------------------------- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/backup/backuplib.php b/backup/backuplib.php index 2ad2d577cb..5633189b24 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -55,8 +55,11 @@ //Is needed user (exists in needed_users) if (isset($needed_users[$backupable_user->id])) { $backupable_user->info .= "needed"; - } - + } else if (isset($course_users[$backupable_user->id])) { + $backupable_user->info .= "needed"; + } // Yu: also needed because they can view course + // might need another variable + //Now create the backup_id record $backupids_rec->backup_code = $backup_unique_code; $backupids_rec->table_name = "user"; diff --git a/backup/restore_form.html b/backup/restore_form.html index 20393f0b0d..cc58306581 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -470,7 +470,8 @@ if ($info->backup_moodle_version < 2006092801) { } else { // 1.7 and above backup $roles = restore_read_xml_roles($xml_file); - if (is_array($roles)) { // possible to have course with no roles + + if (!empty($roles->roles)) { // possible to have course with no roles foreach ($roles->roles as $roleid=>$role) { echo (''); diff --git a/backup/restorelib.php b/backup/restorelib.php index 32e7f7b5a0..988e40ed1e 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -898,17 +898,21 @@ if (!empty($sect->mods)) { //For each mod inside section foreach ($sect->mods as $keym => $mod) { + // Yu: This part is called repeatedly for every instance, + // so it is necessary to set the granular flag and check isset() + // when the first instance of this type of mod is processed. + if (!isset($restore->mods[$mod->type]->granular) && is_array($restore->mods[$mod->type]->instances)) { + // This defines whether we want to restore specific + // instances of the modules (granular restore), or + // whether we don't care and just want to restore + // all module instances (non-granular). + $restore->mods[$mod->type]->granular = true; + } else { + $restore->mods[$mod->type]->granular = false; + } + //Check if we've to restore this module (and instance) - if ($restore->mods[$mod->type]->restore) { - - if (is_array($restore->mods[$mod->type]->instances)) { - // This defines whether we want to restore specific - // instances of the modules (granular restore), or - // whether we don't care and just want to restore - // all module instances (non-granular). - $restore->mods[$mod->type]->granular = true; - } - + if ($restore->mods[$mod->type]->restore) { if (empty($restore->mods[$mod->type]->granular) // we don't care about per instance || (array_key_exists($mod->instance,$restore->mods[$mod->type]->instances) && !empty($restore->mods[$mod->type]->instances[$mod->instance]->restore))) { @@ -3507,30 +3511,7 @@ $this->level--; $this->content = ""; - } - - - - - - - - - - - - - - - - - - - - - - - + } //This is the endTag handler we use where we are reading the course_header zone (todo="COURSE_HEADER") function endElementCourseHeader($parser, $tagName) { @@ -6107,7 +6088,7 @@ if (!empty($course->roleassignments)) { $courseassignments = $course->roleassignments; - foreach ($courseassignments as $oldroleid => $courseassignment) { + foreach ($courseassignments as $oldroleid => $courseassignment) { restore_write_roleassignments($restore, $courseassignment->assignments, "course", CONTEXT_COURSE, $course->course_id, $oldroleid); } } @@ -6234,7 +6215,6 @@ $newcontext = get_context_instance($contextlevel, $oldinstance->new_id); $assignment->contextid = $newcontext->id; // new context id // might already have same assignment - role_assign($assignment->roleid, $assignment->userid, 0, $assignment->contextid, $assignment->timestart, $assignment->timeend, $assignment->hidden, $assignment->enrol); } -- 2.39.5