]> git.mjollnir.org Git - moodle.git/commitdiff
move restore dates in a HotPot record to a separate function
authorgbateson <gbateson>
Wed, 11 Oct 2006 01:32:40 +0000 (01:32 +0000)
committergbateson <gbateson>
Wed, 11 Oct 2006 01:32:40 +0000 (01:32 +0000)
mod/hotpot/restorelib.php

index 992e570bfa13cad51e3256d2251727eab0fc694e..44a5bddf5ef2999698ce6a799120b6421a8e52db 100644 (file)
@@ -108,38 +108,9 @@ function hotpot_restore_mods($mod, $restore) {
         }
 
         // if necessary, adjust HotPot date/time fields and write to restorelog
-        if (!empty($restore->course_startdateoffset)) {
-
-            // check course backup data directory exists
-            $course_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
-            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', 'TIMECLOSE', 'TIMECREATED', 'TIMEMODIFIED');
-            foreach ($TAGS as $TAG) {
-
-                // check $TAG has a sensible value
-                if (!empty($xml[$TAG][0]['#']) && is_string($xml[$TAG][0]['#'])) {
-
-                    // write old date to $restorelog
-                    $value = $xml[$TAG][0]['#'];
-                    $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;
-                }
-            }
-        }
+        hotpot_restore_dates(
+            'Hotpot', $restore, $xml, array('TIMEOPEN', 'TIMECLOSE', 'TIMECREATED', 'TIMEMODIFIED')
+        );  
 
         $status = hotpot_restore_records(
             $restore, $status, $xml, $table, $foreign_keys, $more_restore
@@ -508,4 +479,39 @@ function hotpot_restore_logs($restore, $log) {
     } // end switch
     return $status ? $log : false;
 }
+function hotpot_restore_dates($recordtype, &$restore, &$xml, $TAGS, $NAMETAG='NAME') {
+    if (!empty($restore->course_startdateoffset)) {
+
+            // check course backup data directory exists
+            $course_dir = $CFG->dataroot."/".$restore->course_id."/backupdata";
+            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', 'TIMECLOSE', 'TIMECREATED', 'TIMEMODIFIED');
+            foreach ($TAGS as $TAG) {
+
+                // check $TAG has a sensible value
+                if (!empty($xml[$TAG][0]['#']) && is_string($xml[$TAG][0]['#'])) {
+
+                    // write old date to $restorelog
+                    $value = $xml[$TAG][0]['#'];
+                    $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 (as a string)
+                    $xml[$TAG][0]['#'] = "$value";
+                }
+            }
+        }
+    }
+}
 ?>