From de2ded1a430d1d8aa6f8f2668da208d59d052708 Mon Sep 17 00:00:00 2001 From: gbateson Date: Thu, 14 Sep 2006 11:10:54 +0000 Subject: [PATCH] moved restorelog code to "hotpot_restore_mods", so it is only executed when backing up a HotPot record. Also, modified restorelog code so that "course_startdateoffset" is not added to TIMEOPEN or TIMECLOSE if those fields are currently empty (empty has a special meaning for those fields) --- mod/hotpot/restorelib.php | 59 +++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/mod/hotpot/restorelib.php b/mod/hotpot/restorelib.php index d975a30b4c..d0a45c39fa 100644 --- a/mod/hotpot/restorelib.php +++ b/mod/hotpot/restorelib.php @@ -60,6 +60,7 @@ function hotpot_restore_mods($mod, $restore) { // $modinfo is an array // 'modname' : array( 'restore'=> 0=no 1=yes, 'userinfo' => 0=no 1=yes) + global $CFG; $status = true; // get course module data this hotpot activity @@ -105,6 +106,47 @@ function hotpot_restore_mods($mod, $restore) { $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record);'; } } + + // if necessary, adjust HotPot date/time fields and write to restorelog + if (!empty($restore->course_startdateoffset)) { + + // check course_directory exists + $course_dir = "$CFG->dataroot/$restore->course_id"; + check_dir_exists($course_dir, true); + + // open $restorelog and start output for this HotPot + $restorelog = fopen("$course_dir/restorelog.html", "a"); + fwrite ($restorelog, "
Hotpot - ".$xml['NAME'][0]['#']."
"); + + // loop through time fields + $TAGS = array('TIMEOPEN'=>1, 'TIMECLOSE'=>1, 'TIMECREATED'=>0, 'TIMEMODIFIED'=>0); + foreach ($TAGS as $TAG=>$ignoreifempty) { + + // get $TAG value + if (isset($xml[$TAG][0]['#'])) { + $value = $xml[$TAG][0]['#']; + } else { + $value = 0; + } + if (empty($value) && $ignoreifempty) { + // do nothing + } else { + // write old date to $restorelog + $date = usergetdate($value); + fwrite ($restorelog, "$TAG was ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']); + + // write new date to $restorelog + $value += $restore->course_startdateoffset; + $date = usergetdate($value); + fwrite ($restorelog, "   $TAG is now ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."
"); + + // update $value in $xml tree + $xml[$TAG][0]['#'] = $value; + } + } + fclose($restorelog); + } + $status = hotpot_restore_records( $restore, $status, $xml, $table, $foreign_keys, $more_restore ); @@ -290,16 +332,11 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys, // maintain a cache of info on table columns static $table_columns = array(); - global $CFG, $db; //move outside if - increase scope if (empty($table_columns[$table])) { + global $CFG, $db; $table_columns[$table] = $db->MetaColumns("$CFG->prefix$table"); } - //First, we check to "course_id" folder exists and create is as necessary in CFG->dataroot - //global $CFG; - $dest_dir = $CFG->dataroot."/".$restore->course_id; - check_dir_exists($dest_dir,true); - $file = $dest_dir."/restorelog.html"; - $restorelog_file = fopen($file,"a"); + // get values for fields in this record $record = new stdClass(); $TAGS = array_keys($xml); @@ -307,14 +344,6 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys, $value = $xml[$TAG][0]['#']; if (is_string($value)) { $tag = strtolower($TAG); - if ($TAG == "TIMEOPEN" || $TAG == "TIMECLOSE" || $TAG == "TIMECREATED" ||$TAG == "TIMEMODIFIED"){ - $date = usergetdate($value); - fwrite ($restorelog_file,"
The Hotpot - ".$record->name."
"); - fwrite ($restorelog_file,"The date was ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year'].""); - $value += $restore->course_startdateoffset; - $date = usergetdate($value); - fwrite ($restorelog_file,"   the date is now ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."
"); - } $record->$tag = backup_todb($value); } } -- 2.39.5