]> git.mjollnir.org Git - moodle.git/commitdiff
Moved uploaded assignment files into a subdirectory called moddata,
authormartin <martin>
Wed, 28 Aug 2002 13:07:10 +0000 (13:07 +0000)
committermartin <martin>
Wed, 28 Aug 2002 13:07:10 +0000 (13:07 +0000)
where data from other modules can also live later on.

Also added a README for that directory to warn teachers not to mess
with it, version code to perform the upgrade, tweaks to assignment/lib.php
and a tweak to reading module so that assignment files aren't listed
in the list of possible readings (could get messy).

lang/en/docs/module_files.txt [new file with mode: 0644]
lang/en/moodle.php
lib/moodlelib.php
lib/setup.php
mod/assignment/lib.php
mod/assignment/version.php

diff --git a/lang/en/docs/module_files.txt b/lang/en/docs/module_files.txt
new file mode 100644 (file)
index 0000000..e9036fd
--- /dev/null
@@ -0,0 +1,15 @@
+ABOUT THIS DIRECTORY
+--------------------
+
+DO NOT CHANGE, RENAME OR MOVE ANY OF THE FILES IN THIS DIRECTORY
+unless you really know what you are doing.  
+
+Changing these files could mess up your course.
+
+This directory contains files uploaded to your course within 
+particular modules (mostly by students), such as assignment
+submissions and forum attachments.
+
+The names of the directories and files within this directory 
+are very specific and automatically maintained by Moodle.
+
index d8128261ce0facd3b75247c0a45292fd02972d3d..5873ca5e89dda92ffbef6e975fa52a1851fe0314 100644 (file)
@@ -294,6 +294,7 @@ $string[phone] = "Phone";
 $string[preview] = "Preview";
 $string[previeworchoose] = "Preview or choose a theme";
 $string[question] = "Question";
+$string[readme] = "README";   // This is a file name
 $string[recentactivity] = "Recent activity";
 $string[resources] = "Resources";
 $string[returningtosite] = "Returning to this web site?";
index 9a4f99d09072f503e785ad92abb4d6d03997664a..04b52b7c51dab183a42b526b8f05a8d954eab978 100644 (file)
@@ -1323,18 +1323,36 @@ function make_upload_directory($directory) {
     return $currdir;
 }
 
+function make_mod_upload_directory($courseid) {
+    global $CFG;
+
+    if (! $moddata = make_upload_directory("$courseid/$CFG->moddata")) {
+        return false;
+    }
+
+    $strreadme = get_string("readme");
+
+    if (file_exists("$CFG->dirroot/lang/$CFG->lang/docs/module_files.txt")) {
+        copy("$CFG->dirroot/lang/$CFG->lang/docs/module_files.txt", "$moddata/$strreadme.txt");
+    } else {
+        copy("$CFG->dirroot/lang/en/docs/module_files.txt", "$moddata/$strreadme.txt");
+    }
+    return $moddata;
+}
+
 
-function get_directory_list( $rootdir ) {
+function get_directory_list($rootdir, $excludefile="") {
 // Returns an array with all the filenames in 
 // all subdirectories, relative to the given rootdir.
+// If excludefile is defined, then that file/directory is ignored
 
     $dirs = array();
    
     $dir = opendir( $rootdir );
 
-    while( $file = readdir( $dir ) ) {
-        $fullfile = $rootdir."/".$file;
-        if ($file != "." and $file != "..") {
+    while ($file = readdir($dir)) {
+        if ($file != "." and $file != ".." and $file != $excludefile) {
+            $fullfile = $rootdir."/".$file;
             if (filetype($fullfile) == "dir") {
                 $subdirs = get_directory_list($fullfile);
                 foreach ($subdirs as $subdir) {
index a29d4cb4dad44e79d9c893d57b6bcd60a9ef0cd2..d7aa4d6692f54ca64d8c956b0ba47b4d067a30a0 100644 (file)
@@ -50,6 +50,7 @@
     $CFG->stylesheet  = "$CFG->wwwroot/theme/$CFG->theme/styles.css";
     $CFG->header      = "$CFG->dirroot/theme/$CFG->theme/header.html";
     $CFG->footer      = "$CFG->dirroot/theme/$CFG->theme/footer.html";
+    $CFG->moddata     = "moddata";
 
 // Load up theme variables (colours etc)
 
index df44e77439bdb57c49192604d707ad8b32114114..e37050290d123e19449cf0b5070b7fe25873ad94 100644 (file)
@@ -189,7 +189,9 @@ function assignment_cron () {
 
 function assignment_file_area_name($assignment, $user) {
 //  Creates a directory file name, suitable for make_upload_directory()
-    return "$assignment->course/assignment/$assignment->id/$user->id";
+    global $CFG;
+
+    return "$assignment->course/$CFG->moddata/assignment/$assignment->id/$user->id";
 }
 
 function assignment_file_area($assignment, $user) {
index b3823181edb758b231200986d58c463ce0496f33..7d53002032677be196a379827a67e0305dbb7eb7 100644 (file)
@@ -5,13 +5,15 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002082000;
+$module->version  = 2002082805;
 $module->cron     = 60;
 
 function assignment_upgrade($oldversion) {
 // This function does anything necessary to upgrade
 // older versions to match current functionality
 
+    global $CFG;
+
     if ($oldversion < 2002080500) {
 
         execute_sql("
@@ -57,6 +59,32 @@ function assignment_upgrade($oldversion) {
         execute_sql(" ALTER TABLE `assignment_submissions` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ");
     }
 
+    if ($oldversion < 2002082805) {
+        // assignment file area was moved, so rename all the directories in existing courses
+
+        $basedir = opendir("$CFG->dataroot");
+        while ($dir = readdir($basedir)) {
+            if ($dir == "." || $dir == ".." || $dir == "users") {
+                continue;
+            }
+            if (filetype("$CFG->dataroot/$dir") != "dir") {
+                continue;
+            }
+            $coursedir = "$CFG->dataroot/$dir";
+
+            if (! $coursemoddata = make_mod_upload_directory($dir)) {
+                echo "Error: could not create mod upload directory: $coursemoddata";
+                continue;
+            }
+
+            if (file_exists("$coursedir/assignment")) {
+                if (! rename("$coursedir/assignment", "$coursemoddata/assignment")) {
+                    echo "Error: could not move $coursedir/assignment to $coursemoddata/assignment\n";
+                }
+            }
+        }
+    }
+
     return true;
 }