From: thompson697 Date: Wed, 13 Sep 2006 09:40:55 +0000 (+0000) Subject: Initial work on Roll Forwards - Restore from previous semester (ongoing MDL-5532) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c3b307b777ff3d84f9dd0107da3de9982105db8d;p=moodle.git Initial work on Roll Forwards - Restore from previous semester (ongoing MDL-5532) * Add fields to restore form to enable changes to Short Name, Full Name and Start Date * Start Date offset added to Restore process * Created Restorelog file in Course files area --- diff --git a/backup/restore_check.html b/backup/restore_check.html index fb1dba3637..3661d1dbb5 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -17,6 +17,16 @@ //Detect if we are coming from the restore form $fromform = optional_param ('fromform', 0, PARAM_INT); + if ($form1 = data_submitted()); { + $currentcourseshortname = $course_header->course_shortname; //"store_ShortName"; + $course_header->course_shortname = $form1->shortname; //"update_ShortName"; + $course_header->course_fullname = $form1->fullname; //"update_FullName"; + $form1->startdate = make_timestamp($form1->startyear, $form1->startmonth, $form1->startday); + $currentcoursestartdate = $course_header->course_startdate; + $coursestartdatedateoffset = $form1->startdate - $currentcoursestartdate; + $restore->course_startdateoffset = $coursestartdatedateoffset; //change to restore + } + //If restore session info exists, but we are coming from the form //it has prioriry if (isset($restore) and !empty($fromform)) { @@ -106,6 +116,10 @@ $restore->course_files=$restore_course_files; $restore->messages=$restore_messages; $restore->course_id=$course_id; +//add new vars to restore object + $restore->course_startdateoffset = $coursestartdatedateoffset; + $restore->course_shortname = $currentcourseshortname; + } else { //We have the object, so check if we have a new course_id //passed as parammeter diff --git a/backup/restore_form.html b/backup/restore_form.html index 7c5b0ae913..7c5e4af157 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -100,6 +100,18 @@ } } + if(!isset($form1->startdate)) { + $form1->startdate = $course_header->course_startdate; //$course_header->course_startdate; + } + + if (empty($form1->shortname)) { + $form1->shortname = $course_header->course_shortname; //'_shortname'; //$course_header->course_shortname; + } + + if (empty($form1->fullname)) { + $form1->fullname = $course_header->course_fullname; // '_fullname'; //$course_header->course_fullname; + } + if ($count == 0) { notice("No restorable modules are installed!"); } @@ -168,6 +180,30 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { } choose_from_menu($restore_restoreto_options, "restore_restoreto", $restore_restoreto, ""); echo ""; + if (iscreator()) { //display these fields conditionally + echo ""; + echo ""; + print_string("shortname"); + echo " :"; + echo "shortname\" alt=\" print_string(\"shortname\")\" />" ; + helpbutton("courseshortname", get_string("shortname")) ; + if (isset($err["shortname"])) formerr($err["shortname"]); + echo ""; + echo ""; + print_string("fullname"); + echo " :"; + echo "fullname\" alt=\" print_string(\"fullname\") \" />" ; + helpbutton("coursefullname", get_string("fullname")) ; + if (isset($err["fullname"])) formerr($err["fullname"]); + echo""; + echo " "; + echo " "; + print_string("startdate"); + echo ":"; + print_date_selector("startday", "startmonth", "startyear", $form1->startdate); + helpbutton("coursestartdate", get_string("startdate")); + echo ""; + } //Line echo "
"; //Now, check modules and info and show posibilities diff --git a/backup/restorelib.php b/backup/restorelib.php index f1f37afc58..7f4654f52e 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -543,6 +543,7 @@ $course->students = addslashes($course_header->course_students); $course->guest = addslashes($course_header->course_guest); $course->startdate = addslashes($course_header->course_startdate); + $course->startdate += $restore->course_startdateoffset; $course->enrolperiod = addslashes($course_header->course_enrolperiod); $course->numsections = addslashes($course_header->course_numsections); //$course->showrecent = addslashes($course_header->course_showrecent); INFO: This is out in 1.3 @@ -2154,6 +2155,11 @@ $admin = get_admin(); $adminid = $admin->id; + $dest_dir = $CFG->dataroot."/".$restore->course_id; + check_dir_exists($dest_dir,true); + $file = $dest_dir."/restorelog.html"; + $restorelog_file = fopen($file,"a"); + //Now, if we have anything in events, we have to restore that //events if ($events) { @@ -2182,8 +2188,13 @@ $eve->repeatid = backup_todb($info['EVENT']['#']['REPEATID']['0']['#']); $eve->modulename = ""; $eve->instance = 0; - $eve->eventtype = backup_todb($info['EVENT']['#']['EVENTTYPE']['0']['#']); + $eve->eventtype = backup_todb($info['EVENT']['#']['EVENTTYPE']['0']['#']); $eve->timestart = backup_todb($info['EVENT']['#']['TIMESTART']['0']['#']); + $date = usergetdate($eve->timestart); + fwrite ($restorelog_file,"The Event - ".$eve->name. " - TIMESTART was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year'].""); + $eve->timestart += $restore->course_startdateoffset; + $date = usergetdate($eve->timestart); + fwrite ($restorelog_file,"   the Event TIMESTART is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."
"); $eve->timeduration = backup_todb($info['EVENT']['#']['TIMEDURATION']['0']['#']); $eve->visible = backup_todb($info['EVENT']['#']['VISIBLE']['0']['#']); $eve->timemodified = backup_todb($info['EVENT']['#']['TIMEMODIFIED']['0']['#']); @@ -4906,6 +4917,11 @@ } $restore->course_id = $course_header->course_id; } + + if ($status = restore_open_html($restore,$course_header)){ + echo "
  • Creating the Restorelog.html in the course Files folder
  • "; + } + } else { $course = get_record("course","id",$restore->course_id); if ($course) { @@ -5372,6 +5388,10 @@ } } + if ($status = restore_close_html($restore)){ + echo "
  • Closing the Restorelog.html file.
  • "; + } + if (!defined('RESTORE_SILENTLY')) { //End the main ul echo ""; @@ -5383,5 +5403,62 @@ return $status; } + //Create, open and write header of the html log file + function restore_open_html($restore,$course_header) { + + global $CFG; + + $status = true; + + //Open file for writing + //First, we check the "course_id" folder exists and create it as necessary in CFG->dataroot + $dest_dir = $CFG->dataroot."/".$restore->course_id; + $status = check_dir_exists($dest_dir,true); + $file = $dest_dir."/restorelog.html"; + $restorelog_file = fopen($file,"a"); + //Write the header in the new logging file + fwrite ($restorelog_file," "); + fwrite ($restorelog_file,""); + fwrite ($restorelog_file,""); + fwrite ($restorelog_file,"".$course_header->course_shortname." Restored "); + fwrite ($restorelog_file,"

    The following changes were made during the Restoration of this Course.



    "); + fwrite ($restorelog_file,"The Course ShortName is now - ".$course_header->course_shortname." The FullName is now - ".$course_header->course_fullname."

    "); + $startdate = addslashes($course_header->course_startdate); + $date = usergetdate($startdate); + fwrite ($restorelog_file,"The Originating Courses Start Date was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year'].""); + $startdate += $restore->course_startdateoffset; + $date = usergetdate($startdate); + fwrite ($restorelog_file,"   This Courses Start Date is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."

    "); + + if ($status) { + return $restorelog_file; + } else { + return false; + } + } + //Create & close footer of the html log file + function restore_close_html($restore) { + + global $CFG; + + $status = true; + + //Open file for writing + //First, check that "course_id" folder exists + $dest_dir = $CFG->dataroot."/".$restore->course_id; + $status = check_dir_exists($dest_dir,true); + $file = $dest_dir."/restorelog.html"; + $restorelog_file = fopen($file,"a"); + //Write the footer to close the logging file + fwrite ($restorelog_file,"
    This file was written to directly by each modules restore process."); + fwrite ($restorelog_file,"

    Log complete."); + + if ($status) { + return $restorelog_file; + } else { + return false; + } + } ?>