Permalink
Browse files

Apply modularity to the creation of the log file during restore to a …

…new course.

Remove the responsibility for loging the application of the course start date offset, from activity modules to the backup module.
Merged from stable branch
  • Loading branch information...
1 parent 352b8da commit cf0b1faded301b142413b9aa00423fbc1d5eaf41 thompson697 committed Oct 17, 2006
View
@@ -2205,10 +2205,7 @@ function restore_create_events($restore,$xml_file) {
//Get admin->id for later use
$admin = get_admin();
$adminid = $admin->id;
- //First, we check the course_id backup data folder exists
- $dest_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
- check_dir_exists($dest_dir,true);
- $restorelog_file = fopen("$dest_dir/restorelog.html","a");
+
//Now, if we have anything in events, we have to restore that
//events
if ($events) {
@@ -2227,6 +2224,11 @@ function restore_create_events($restore,$xml_file) {
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
+ //if necessary, write to restorelog and adjust date/time fields
+ if ($restore->course_startdateoffset) {
+ restore_log_date_changes('Events', $restore, $info['EVENT']['#'], array('TIMESTART'));
+ }
+
//Now build the EVENT record structure
$eve->name = backup_todb($info['EVENT']['#']['NAME']['0']['#']);
$eve->description = backup_todb($info['EVENT']['#']['DESCRIPTION']['0']['#']);
@@ -2239,11 +2241,6 @@ function restore_create_events($restore,$xml_file) {
$eve->instance = 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,"&nbsp;&nbsp;&nbsp;the Event TIMESTART is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$eve->timeduration = backup_todb($info['EVENT']['#']['TIMEDURATION']['0']['#']);
$eve->visible = backup_todb($info['EVENT']['#']['VISIBLE']['0']['#']);
$eve->timemodified = backup_todb($info['EVENT']['#']['TIMEMODIFIED']['0']['#']);
@@ -6259,5 +6256,65 @@ function restore_write_roleoverrides($restore, $overrides, $table, $contextlevel
insert_record('role_capabilities', $override);
}
}
- }
+ }
+ //write activity date changes to the html log file, and update date values in the the xml array
+ function restore_log_date_changes($recordtype, &$restore, &$xml, $TAGS, $NAMETAG='NAME') {
+
+ global $CFG;
+ $openlog = false;
+
+ // loop through time fields in $TAGS
+ foreach ($TAGS as $TAG) {
+
+ // check $TAG has a sensible value
+ if (!empty($xml[$TAG][0]['#']) && is_string($xml[$TAG][0]['#']) && is_numeric($xml[$TAG][0]['#'])) {
+
+ if ($openlog==false) {
+ $openlog = true; // only come through here once
+
+ // open file for writing
+ $course_dir = "$CFG->dataroot/$restore->course_id/backupdata";
+ check_dir_exists($course_dir, true);
+ $restorelog = fopen("$course_dir/restorelog.html", "a");
+
+ // start output for this record
+ $msg = new stdClass();
+ $msg->recordtype = $recordtype;
+ $msg->recordname = $xml[$NAMETAG][0]['#'];
+ fwrite ($restorelog, get_string("backupdaterecordtype", "moodle", $msg));
+ }
+
+ // write old date to $restorelog
+ $value = $xml[$TAG][0]['#'];
+ $date = usergetdate($value);
+
+ $msg = new stdClass();
+ $msg->TAG = $TAG;
+ $msg->weekday = $date['weekday'];
+ $msg->mday = $date['mday'];
+ $msg->month = $date['month'];
+ $msg->year = $date['year'];
+ fwrite ($restorelog, get_string("backupdateold", "moodle", $msg));
+
+ // write new date to $restorelog
+ $value += $restore->course_startdateoffset;
+ $date = usergetdate($value);
+
+ $msg = new stdClass();
+ $msg->TAG = $TAG;
+ $msg->weekday = $date['weekday'];
+ $msg->mday = $date['mday'];
+ $msg->month = $date['month'];
+ $msg->year = $date['year'];
+ fwrite ($restorelog, get_string("backupdatenew", "moodle", $msg));
+
+ // update $value in $xml tree for calling module
+ $xml[$TAG][0]['#'] = "$value";
+ }
+ }
+ // close the restore log, if it was opened
+ if ($openlog) {
+ fclose($restorelog);
+ }
+ }
?>
View
@@ -131,6 +131,9 @@
$string['backupcancelled'] = 'Backup Cancelled';
$string['backupcoursefileshelp'] = 'If enabled then course files will be included in automated backups';
$string['backupdate'] = 'Backup Date';
+$string['backupdatenew'] = ' &nbsp; $a->TAG is now $a->weekday, $a->mday $a->month $a->year<br>\n';
+$string['backupdateold'] = '$a->TAG was $a->weekday, $a->mday $a->month $a->year\n';
+$string['backupdaterecordtype'] = '<br>$a->recordtype - $a->recordname<br>\n';
$string['backupdetails'] = 'Backup Details';
$string['backupexecuteathelp'] = 'Choose what time automated backups should run at.';
$string['backupfailed'] = 'Some of your courses weren\'t saved!!';
@@ -1471,4 +1474,4 @@
$string['yourteacher'] = 'your $a';
$string['zippingbackup'] = 'Zipping backup';
-?>
+?>
@@ -32,12 +32,12 @@ function assignment_restore_mods($mod,$restore) {
$data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
if ($data) {
- //Now get completed xmlized object
- $info = $data->info;
- //First, check the course_id backup folder exists in CFG->dataroot
- $dest_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
- check_dir_exists($dest_dir,true);
- $restorelog_file = fopen("$dest_dir/restorelog.html","a");
+ //Now get completed xmlized object
+ $info = $data->info;
+ //if necessary, write to restorelog and adjust date/time fields
+ if ($restore->course_startdateoffset) {
+ restore_log_date_changes('Assignment', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
+ }
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
@@ -59,18 +59,7 @@ function assignment_restore_mods($mod,$restore) {
$assignment->assignmenttype = backup_todb($info['MOD']['#']['ASSIGNMENTTYPE']['0']['#']);
$assignment->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
$assignment->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']);
- $date = usergetdate($assignment->timedue);
- fwrite ($restorelog_file,"<br>The Assignment - ".$assignment->name." <br>");
- fwrite ($restorelog_file,"The TIMEDUE was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $assignment->timedue += $restore->course_startdateoffset;
- $date = usergetdate($assignment->timedue);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TIMEDUE is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$assignment->timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']);
- $date = usergetdate($assignment->timeavailable);
- fwrite ($restorelog_file,"The TIMEAVAILABLE was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $assignment->timeavailable += $restore->course_startdateoffset;
- $date = usergetdate($assignment->timeavailable);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TIMEAVAILABLE is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$assignment->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
$assignment->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
View
@@ -34,14 +34,14 @@ function chat_restore_mods($mod,$restore) {
if ($data) {
//Now get completed xmlized object
$info = $data->info;
- //First, check the course_id backup folder exists in CFG->dataroot
- $dest_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
- check_dir_exists($dest_dir,true);
- $restorelog_file = fopen("$dest_dir/restorelog.html","a");
+
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
-
+ // if necessary, write to restorelog and adjust date/time fields
+ if ($restore->course_startdateoffset) {
+ restore_log_date_changes('Chat', $restore, $info['MOD']['#'], array('CHATTIME'));
+ }
//Now, build the CHAT record structure
$chat->course = $restore->course_id;
$chat->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
@@ -50,12 +50,6 @@ function chat_restore_mods($mod,$restore) {
$chat->studentlogs = backup_todb($info['MOD']['#']['STUDENTLOGS']['0']['#']);
$chat->schedule = backup_todb($info['MOD']['#']['SCHEDULE']['0']['#']);
$chat->chattime = backup_todb($info['MOD']['#']['CHATTIME']['0']['#']);
- $date = usergetdate($chat->chattime);
- fwrite ($restorelog_file,"The Chat - ".$chat->name." <br>");
- fwrite ($restorelog_file,"The CHATTIME was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $chat->chattime += $restore->course_startdateoffset;
- $date = usergetdate($chat->chattime);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the CHATTIME is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br><br>");
$chat->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the chat
View
@@ -39,10 +39,10 @@ function choice_restore_mods($mod,$restore) {
if ($data) {
//Now get completed xmlized object
$info = $data->info;
- //First, check the course_id backup folder exists in CFG->dataroot
- $dest_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
- check_dir_exists($dest_dir,true);
- $restorelog_file = fopen("$dest_dir/restorelog.html","a");
+ // if necessary, write to restorelog and adjust date/time fields
+ if ($restore->course_startdateoffset) {
+ restore_log_date_changes('Choice', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
+ }
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
@@ -59,18 +59,7 @@ function choice_restore_mods($mod,$restore) {
$choice->showunanswered = backup_todb($info['MOD']['#']['SHOWUNANSWERED']['0']['#']);
$choice->limitanswers = backup_todb($info['MOD']['#']['LIMITANSWERS']['0']['#']);
$choice->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
- $date = usergetdate($choice->timeopen);
- fwrite ($restorelog_file,"<br>The Choice - ".$choice->name." <br>");
- fwrite ($restorelog_file,"The TIMEOPEN was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $choice->timeopen += $restore->course_startdateoffset;
- $date = usergetdate($choice->timeopen);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;The TIMEOPEN is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$choice->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
- $date = usergetdate($choice->timeclose);
- fwrite ($restorelog_file,"The TIMECLOSE was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $choice->timeclose += $restore->course_startdateoffset;
- $date = usergetdate($choice->timeclose);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TIMECLOSE is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$choice->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//To mantain compatibilty, in 1.4 the publish setting meaning has changed. We
View
@@ -46,11 +46,11 @@ function data_restore_mods($mod,$restore) {
if ($data) {
//Now get completed xmlized object
- $info = $data->info;
- //First, check the course_id backup folder exists in CFG->dataroot
- $dest_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
- check_dir_exists($dest_dir,true);
- $restorelog_file = fopen("$dest_dir/restorelog.html","a");
+ $info = $data->info;
+ // if necessary, write to restorelog and adjust date/time fields
+ if ($restore->course_startdateoffset) {
+ restore_log_date_changes('Database', $restore, $info['MOD']['#'], array('TIMEAVAILABLEFROM', 'TIMEAVAILABLETO','TIMEVIEWFROM', 'TIMEVIEWTO'));
+ }
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
@@ -65,30 +65,9 @@ function data_restore_mods($mod,$restore) {
}
$database->comments = backup_todb($info['MOD']['#']['COMMENTS']['0']['#']);
$database->timeavailablefrom = backup_todb($info['MOD']['#']['TIMEAVAILABLEFROM']['0']['#']);
- $date = usergetdate($database->timeavailablefrom);
- fwrite ($restorelog_file,"<br>The Database - ".$database->name." <br>");
- fwrite ($restorelog_file,"The TIMEAVAILABLEFROM was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $database->timeavailablefrom += $restore->course_startdateoffset;
- $date = usergetdate($database->timeavailablefrom);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TTIMEAVAILABLEFROM is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$database->timeavailableto = backup_todb($info['MOD']['#']['TIMEAVAILABLETO']['0']['#']);
- $date = usergetdate($database->timeavailableto);
- fwrite ($restorelog_file,"The TIMEAVAILABLETO was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $database->timeavailableto += $restore->course_startdateoffset;
- $date = usergetdate($database->timeavailableto);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TIMEAVAILABLETO is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$database->timeviewfrom = backup_todb($info['MOD']['#']['TIMEVIEWFROM']['0']['#']);
- $date = usergetdate($database->timeviewfrom);
- fwrite ($restorelog_file,"The TIMEVIEWFROM was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $database->timeviewfrom += $restore->course_startdateoffset;
- $date = usergetdate($database->timeviewfrom);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TIMEVIEWFROM is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
$database->timeviewto = backup_todb($info['MOD']['#']['TIMEVIEWTO']['0']['#']);
- $date = usergetdate($database->timeviewto);
- fwrite ($restorelog_file,"The TIMEVIEWTO was " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
- $database->timeviewto += $restore->course_startdateoffset;
- $date = usergetdate($database->timeviewto);
- fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the TIMEVIEWTO is now " .$date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
// Only relevant for restoring backups from 1.6 in a 1.7 install.
if (isset($info['MOD']['#']['PARTICIPANTS']['0']['#'])) {
$database->participants = backup_todb($info['MOD']['#']['PARTICIPANTS']['0']['#']);
@@ -47,12 +47,12 @@ function exercise_restore_mods($mod,$restore) {
$data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
if ($data) {
- //Now get completed xmlized object
- $info = $data->info;
- //First, check the course_id backup folder exists in CFG->dataroot
- $dest_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
- check_dir_exists($dest_dir,true);
- $restorelog_file = fopen("$dest_dir/restorelog.html","a");
+ //Now get completed xmlized object
+ $info = $data->info;
+ // if necessary, write to restorelog and adjust date/time fields
+ if ($restore->course_startdateoffset) {
+ restore_log_date_changes('Exercise', $restore, $info['MOD']['#'], array('DEADLINE'));
+ }
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
Oops, something went wrong.

0 comments on commit cf0b1fa

Please sign in to comment.