]> git.mjollnir.org Git - moodle.git/commitdiff
moved restorelog code to "hotpot_restore_mods", so it is only executed when backing...
authorgbateson <gbateson>
Thu, 14 Sep 2006 11:10:54 +0000 (11:10 +0000)
committergbateson <gbateson>
Thu, 14 Sep 2006 11:10:54 +0000 (11:10 +0000)
mod/hotpot/restorelib.php

index d975a30b4cd4e9af6b93d5be3136a480b2e0927f..d0a45c39fa475021a726bb584367b70616933539 100644 (file)
@@ -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, "<br>Hotpot - ".$xml['NAME'][0]['#']." <br>");
+
+            // 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, "&nbsp;&nbsp;&nbsp;$TAG is now ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
+
+                    // 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,"<br>The Hotpot - ".$record->name." <br>");
-                fwrite ($restorelog_file,"The date was ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."");
-                $value += $restore->course_startdateoffset;
-                $date = usergetdate($value);
-                fwrite ($restorelog_file,"&nbsp;&nbsp;&nbsp;the date is now ". $date['weekday'].", ".$date['mday']." ".$date['month']." ".$date['year']."<br>");
-            }
             $record->$tag = backup_todb($value);
         }
     }