]> git.mjollnir.org Git - moodle.git/commitdiff
Implemented copying course_files and user_files.
authorstronk7 <stronk7>
Wed, 28 May 2003 19:43:11 +0000 (19:43 +0000)
committerstronk7 <stronk7>
Wed, 28 May 2003 19:43:11 +0000 (19:43 +0000)
backup/lib.php
backup/restore_execute.html
backup/restorelib.php

index 368b68409201df6c46f5e6217b6c7d586d6f2f9e..8323d127bf9b0cb365f13b11ea4a47edce2e0893 100644 (file)
@@ -67,6 +67,7 @@
             if (!$create) {
                 $status = false;
             } else {
+                umask(0000);
                 $status = mkdir ($dir,$CFG->directorypermissions);
             }
         }
index 3ce9acf0514e1cb0785648dc20a198dac694b70c..0563a57186b500bb5113cb6042bdf7c3499d649a 100644 (file)
         }
     }
 
-    //Now create users as needed
+    //Now create user_files as needed
     if ($status and ($restore->user_files)) {
         echo "<li>Copying User Files";
+        $status = restore_user_files($restore);
+        //If all is ok (and we have a counter)
+        if ($status and ($status !== true)) {
+            //Inform about user dirs created from backup
+            echo "<ul>";
+            echo "<li>User Zones: ".$status;
+            echo "</ul>";
+        }
+    }
 
+    //Now create course files as needed
+    if ($status and ($restore->course_files)) {
+        echo "<li>Copying Course Files";
+        $status = restore_course_files($restore);
+        //If all is ok (and we have a counter)
+        if ($status and ($status !== true)) {
+            //Inform about user dirs created from backup
+            echo "<ul>";
+            echo "<li>Main Files/Folders: ".$status;
+            echo "</ul>";
+        }       
     }
 
+    
+
+
+
+
+
+
+
+
+
+
+
+
 
 
+    //Now create log entries as needed
+    if ($status and ($restore->logs)) {
+        echo "<li>Creating Log Entries <b>(not implemented)</b>. Execute after everything...";
+    }    
 
     //Now, if all is OK, adjust the instance field in course_modules !!
 
index 7ec2684f1f9050f280475eda9a5ceda1b7bb38d9..0526fbde1c6e1ff51dfe821b22c6ce52c5510591 100644 (file)
 
         return $status;
     }
+
+    //This function restores the userfiles from the temp (user_files) directory to the
+    //dataroot/users directory
+    function restore_user_files($restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //First, we check to "users" exists and create is as necessary
+        //in CFG->dataroot
+        $dest_dir = $CFG->dataroot."/users";
+        $status = check_dir_exists($dest_dir,true);
+
+        //Now, we iterate over "user_files" records to check if that user dir must be
+        //copied (and renamed) to the "users" dir.
+        $rootdir = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/user_files";
+        //Check if directory exists
+        if (is_dir($rootdir)) {
+            $list = list_directories ($rootdir);
+            if ($list) {
+                //Iterate
+                $counter = 0;
+                foreach ($list as $dir) {
+                    //Look for dir like username in backup_ids
+                    $data = get_record ("backup_ids","backup_code",$restore->backup_unique_code,
+                                                     "table_name","user",
+                                                     "old_id",$dir);
+                    //If thar user exists in backup_ids
+                    if ($data) {
+                        //Only it user has been created now
+                        if (strpos($data->info,"new") !== false) {
+                            //Copy the old_dir to its new location (and name) !!
+                            //Only if destination doesn't exists
+                            if (!file_exists($dest_dir."/".$data->new_id)) {
+                                $status = backup_copy_file($rootdir."/".$dir,
+                                              $dest_dir."/".$data->new_id);
+                                $counter ++;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        //If status is ok and whe have dirs created, returns counter to inform
+        if ($status and $counter) {
+            return $counter;
+        } else {
+            return $status;
+        }
+    }
+
+    //This function restores the course files from the temp (course_files) directory to the
+    //dataroot/course_id directory
+    function restore_course_files($restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //First, we check to "course_id" exists and create is as necessary
+        //in CFG->dataroot
+        $dest_dir = $CFG->dataroot."/".$restore->course_id;
+        $status = check_dir_exists($dest_dir,true);
+
+        //Now, we iterate over "course_files" records to check if that file/dir must be
+        //copied to the "dest_dir" dir.
+        $rootdir = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/course_files";
+        //Check if directory exists
+        if (is_dir($rootdir)) {
+            $list = list_directories_and_files ($rootdir);
+            if ($list) {
+                //Iterate
+                $counter = 0;
+                foreach ($list as $dir) {
+                    //Copy the dir to its new location 
+                    //Only if destination file/dir doesn exists
+                    if (!file_exists($dest_dir."/".$dir)) {
+                        $status = backup_copy_file($rootdir."/".$dir,
+                                      $dest_dir."/".$dir);
+                        $counter ++;
+                    }
+                }
+            }
+        }
+        //If status is ok and whe have dirs created, returns counter to inform
+        if ($status and $counter) {
+            return $counter;
+        } else {
+            return $status;
+        }
+    }
    
 
     //=====================================================================================