Index: lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/backup/lib.php,v retrieving revision 1.89.2.16 diff -u -r1.89.2.16 lib.php --- lib.php 10 May 2009 23:16:06 -0000 1.89.2.16 +++ lib.php 20 May 2009 18:23:38 -0000 @@ -1,6 +1,13 @@ dirroot.'/lib/uploadlib.php'); Index: restore_check.html =================================================================== RCS file: /cvsroot/moodle/moodle/backup/restore_check.html,v retrieving revision 1.48.2.15 diff -u -r1.48.2.15 restore_check.html --- restore_check.html 19 May 2009 18:45:16 -0000 1.48.2.15 +++ restore_check.html 20 May 2009 18:23:38 -0000 @@ -216,44 +216,19 @@ // Calculate if the user can create courses $cancreatecourses = user_can_create_courses(); - //Depending the selected restoreto: - // A) If user has 'moodle/site:restore' in more than one course and cannot create courses and he isn't restoring from SITEID: - // 0-Existing course, deleting: Select the destination course and launch the check again, then - // put $restore->course_id and $restore->deleting (true), create the restore object. - // 1-Existing course, adding: Select the destination course and launch the check again, then - // put $restore->course_id and $restore->deleting (false), create the restore object. - // B) Else, if user has 'moodle/site:restore' in only 1 course or cannot create courses or he is restoring from within SITEID: - // 0-Current course, deleting: Put $restore->course_id and $restore->deleting (true), create the restore object - // 1-Current course, adding: Put $restore->course_id and $restore->deleting (false), create the restore object - // C) If the user is a creator: - // 0-Existing course, deleting: Select the destination course and launch the check again, then - // put $restore->course_id and $restore->deleting (true), create the restore object. - // 1-Existing course, adding: Select the destination course and launch the check again, then - // put $restore->course_id and $restore->deleting (false), create the restore object. - // 2-New course: Create the restore object and launch the execute. - // NOTE: SITEID is prevented as a source for restoring because it's public area and we must encourage admins - // to avoid using it as a "repository" for courses storage. - - // A) If user has 'moodle/site:restore' in more than one course and cannot create courses and he isn't restoring from SITEID - if (count($mycourses) > 1 && !$cancreatecourses && $id != SITEID) { - /// Nothing to do, process continues and C) will show the list of courses - - // B) Else, if user has 'moodle/site:restore' is only 1 course or cannot create courses or he is restoring from within SITEID - } else if (count($mycourses) == 1 || !$cancreatecourses || $id == SITEID) { + if (empty($restore->course_id) && ($restore->restoreto == RESTORETO_CURRENT_DELETING || $restore->restoreto == RESTORETO_CURRENT_ADDING)) { $restore->course_id = $id; /// Force restore to current course, disabling pick course from list } - // C) Arrived here, we have preprocessed all the changes needed by A) and B). Continue with the process - //Set restore->deleting as needed - if ($restore->restoreto == 0) { + if ($restore->restoreto == RESTORETO_CURRENT_DELETING || $restore->restoreto == RESTORETO_EXISTING_DELETING) { $restore->deleting = true; } else { $restore->deleting = false; } //Now, select the course if needed - if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) && count($mycourses) > 1) { + if (empty($restore->course_id) && ($restore->restoreto == RESTORETO_EXISTING_DELETING || $restore->restoreto == RESTORETO_EXISTING_ADDING)) { if ($courses = $mycourses) { print_heading(get_string("choosecourse")); @@ -275,11 +250,11 @@ print_continue("$CFG->wwwroot/$CFG->admin/index.php"); } //Checks everything and execute restore - } else if ((($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id != 0)) or ($restore->restoreto == 2)) { + } else if (($restore->restoreto != RESTORETO_NEW_COURSE and $restore->course_id != 0) or ($restore->restoreto == RESTORETO_NEW_COURSE)) { //Final access control check - if ($restore->course_id == 0 and !$cancreatecourses) { + if (empty($restore->course_id) and !$cancreatecourses) { error("You need to be a creator or admin to restore into new course!"); - } else if ($restore->course_id != 0 and !has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $restore->course_id))) { + } else if (!empty($restore->course_id) and !has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $restore->course_id))) { error("You need to be an edit teacher or admin to restore into selected course!"); } $show_continue_button = true; @@ -287,9 +262,9 @@ //Check and warn if we are restoring over frontpage (SITEID) course. MDL-19163 if ($restore->course_id == SITEID) { - if ($restore->restoreto == 0) { + if ($restore->restoreto == RESTORETO_CURRENT_DELETING) { $messages[] = get_string ('restoretositedeleting'); - } else if ($restore->restoreto == 1) { + } else if ($restore->restoreto == RESTORETO_CURRENT_ADDING) { $messages[] = get_string ('restoretositeadding'); } } Index: restore_form.html =================================================================== RCS file: /cvsroot/moodle/moodle/backup/restore_form.html,v retrieving revision 1.60.2.17 diff -u -r1.60.2.17 restore_form.html --- restore_form.html 2 Jan 2009 16:53:30 -0000 1.60.2.17 +++ restore_form.html 20 May 2009 18:23:38 -0000 @@ -112,9 +112,9 @@ $cancreatecourses = user_can_create_courses(); if (!isset($restore_restoreto)) { if (!$cancreatecourses) { - $restore_restoreto = 1; + $restore_restoreto = RESTORETO_CURRENT_ADDING; } else { - $restore_restoreto = 2; + $restore_restoreto = RESTORETO_NEW_COURSE; } } @@ -194,20 +194,8 @@ echo ""; echo ""; - // permission should have been checked already - /** - * if user has manageactivities in any course and we are not restoring from within SITEID - * existingcoursedeleting - * existingcourseadding - * else we show - * currentcoursedeleting - * currentcourse - * if user has course:create in any category, we show - * newcourse - */ - // Non-cached - get accessinfo if (isset($USER->access)) { $accessinfo = $USER->access; @@ -217,21 +205,21 @@ $mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true); - // if the user can manage 2 or more courses and we are not restoring from within SITEID, - // we show options for existing courses - - if (count($mycourses) > 1 && $id != SITEID) { - $restore_restoreto_options[0] = get_string("existingcoursedeleting"); - $restore_restoreto_options[1] = get_string("existingcourseadding"); - // else if the user can write to current course - } else if (has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))){ - $restore_restoreto_options[0] = get_string("currentcoursedeleting"); - $restore_restoreto_options[1] = get_string("currentcourseadding"); + // if the user can restore to current course, grant the "current" options + if (has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))){ + $restore_restoreto_options[RESTORETO_CURRENT_DELETING] = get_string("currentcoursedeleting"); + $restore_restoreto_options[RESTORETO_CURRENT_ADDING] = get_string("currentcourseadding"); } - // if user can create any course at all, give the option + // if user can create any course, grant the "new course" option if ($cancreatecourses) { - $restore_restoreto_options[2] = get_string("newcourse"); + $restore_restoreto_options[RESTORETO_NEW_COURSE] = get_string("newcourse"); + } + + // if the user can restore to 2 or more courses (or to just 1 but different from current), grant the "existing" options + if (count($mycourses) > 1 || (count($mycourses) == 1 && $mycourses[0]->id != $id)) { + $restore_restoreto_options[RESTORETO_EXISTING_DELETING] = get_string("existingcoursedeleting"); + $restore_restoreto_options[RESTORETO_EXISTING_ADDING] = get_string("existingcourseadding"); } /// Acummulator for hidden options and proper XHTML output Index: restorelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/backup/restorelib.php,v retrieving revision 1.283.2.74 diff -u -r1.283.2.74 restorelib.php --- restorelib.php 10 May 2009 14:38:34 -0000 1.283.2.74 +++ restorelib.php 20 May 2009 18:23:46 -0000 @@ -1107,7 +1107,7 @@ $section->sequence = ""; //Now calculate the section's newid $newid = 0; - if ($restore->restoreto == 2) { + if ($restore->restoreto == RESTORETO_NEW_COURSE) { //Save it to db (only if restoring to new course) $newid = insert_record("course_sections",$section); } else { @@ -7889,7 +7889,7 @@ //If we've selected to restore into new course //create it (course) //Saving conversion id variables into backup_tables - if ($restore->restoreto == 2) { + if ($restore->restoreto == RESTORETO_NEW_COURSE) { if (!defined('RESTORE_SILENTLY')) { echo '
  • '.get_string('creatingnewcourse') . '
  • '; } @@ -7949,7 +7949,7 @@ if ($status) { //Now , this situation is equivalent to the "restore to new course" one (we //have a course record and nothing more), so define it as "to new course" - $restore->restoreto = 2; + $restore->restoreto = RESTORETO_NEW_COURSE; } else { if (!defined('RESTORE_SILENTLY')) { notify("An error occurred while deleting some of the course contents."); @@ -8103,7 +8103,7 @@ //we have to do this after groups and groupings are restored, because we need the new groupings id if ($status) { //Into new course - if ($restore->restoreto == 2) { + if ($restore->restoreto == RESTORETO_NEW_COURSE) { if (!defined('RESTORE_SILENTLY')) { echo "
  • ".get_string("creatingsections"); } @@ -8119,7 +8119,7 @@ echo '
  • '; } //Into existing course - } else if ($restore->restoreto == 0 or $restore->restoreto == 1) { + } else if ($restore->restoreto != RESTORETO_NEW_COURSE) { if (!defined('RESTORE_SILENTLY')) { echo "
  • ".get_string("checkingsections"); } @@ -8149,7 +8149,7 @@ //Now create metacourse info if ($status and $restore->metacourse) { //Only to new courses! - if ($restore->restoreto == 2) { + if ($restore->restoreto == RESTORETO_NEW_COURSE) { if (!defined('RESTORE_SILENTLY')) { echo "
  • ".get_string("creatingmetacoursedata"); } @@ -8361,9 +8361,11 @@ } //Bring back the course blocks -- do it AFTER the modules!!! - if($status) { + if ($status) { //If we are deleting and bringing into a course or making a new course, same situation - if($restore->restoreto == 0 || $restore->restoreto == 2) { + if ($restore->restoreto == RESTORETO_CURRENT_DELETING || + $restore->restoreto == RESTORETO_EXISTING_DELETING || + $restore->restoreto == RESTORETO_NEW_COURSE) { if (!defined('RESTORE_SILENTLY')) { echo '
  • '.get_string('creatingblocks'); } @@ -8382,9 +8384,11 @@ } } - if($status) { + if ($status) { //If we are deleting and bringing into a course or making a new course, same situation - if($restore->restoreto == 0 || $restore->restoreto == 2) { + if ($restore->restoreto == RESTORETO_CURRENT_DELETING || + $restore->restoreto == RESTORETO_EXISTING_DELETING || + $restore->restoreto == RESTORETO_NEW_COURSE) { if (!defined('RESTORE_SILENTLY')) { echo '
  • '.get_string('courseformatdata'); } @@ -8847,7 +8851,7 @@ foreach ($courseoverrides as $oldroleid => $courseoverride) { // if not importing into exiting course, or creating new role, we are ok // local course overrides to be respected (i.e. restored course overrides ignored) - if ($restore->restoreto != 1 || empty($restore->rolesmapping[$oldroleid])) { + if (($restore->restoreto != RESTORETO_CURRENT_ADDING && $restore->restoreto != RESTORETO_EXISTING_ADDING) || empty($restore->rolesmapping[$oldroleid])) { restore_write_roleoverrides($restore, $courseoverride->overrides, "course", CONTEXT_COURSE, $course->course_id, $oldroleid); } } @@ -8887,7 +8891,7 @@ * role assignments/overrides * *************************************************/ - if ($restore->restoreto != 1) { // skip altogether if restoring to exisitng course by adding + if ($restore->restoreto != RESTORETO_CURRENT_ADDING && $restore->restoreto != RESTORETO_EXISTING_ADDING) { // skip altogether if restoring to exisitng course by adding if (!defined('RESTORE_SILENTLY')) { echo "
  • ".get_string("creatingblocksroles").'
  • '; } @@ -8909,6 +8913,7 @@ } } } + /************************************************ * Restoring assignments from userid level * * role assignments/overrides *