MDL-22609 undoing directory variables magic from last commit, keeping just the userid...
[moodle.git] / mod / assignment / db / upgrade.php
index a3995d3..0e18eeb 100644 (file)
@@ -68,18 +68,15 @@ function xmldb_assignment_upgrade($oldversion) {
                 $context = get_context_instance(CONTEXT_MODULE, $submission->cmid);
 
                 // migrate submitted files first
-                $newpath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->id/";
-                if (!file_exists($newpath)) {
-                    mkdir($newpath);
-                }
+                $path = $basepath;
                 $filearea = 'assignment_submission';
-                $items = new DirectoryIterator($basepath);
+                $items = new DirectoryIterator($path);
                 foreach ($items as $item) {
                     if (!$item->isFile()) {
                         continue;
                     }
                     if (!$item->isReadable()) {
-                        echo $OUTPUT->notification(" File not readable, skipping: ".$basepath.$item->getFilename());
+                        echo $OUTPUT->notification(" File not readable, skipping: ".$path.$item->getFilename());
                         continue;
                     }
                     $filename = clean_param($item->getFilename(), PARAM_FILE);
@@ -88,19 +85,18 @@ function xmldb_assignment_upgrade($oldversion) {
                     }
                     if (!$fs->file_exists($context->id, $filearea, $submission->userid, '/', $filename)) {
                         $file_record = array('contextid'=>$context->id, 'filearea'=>$filearea, 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid);
-                        if ($fs->create_file_from_pathname($file_record, $basepath.$item->getFilename())) {
-                            unlink($basepath.$item->getFilename());
+                        if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
+                            unlink($path.$item->getFilename());
                         }
                     }
                 }
                 unset($items); //release file handles
 
                 // migrate teacher response files
-                $basepath = $basepath.'responses/';
-                $newpath = $newpath.'responses/';
-                if (file_exists($basepath)) {
+                $path = $basepath.'responses/';
+                if (file_exists($path)) {
                     $filearea = 'assignment_response';
-                    $items = new DirectoryIterator($basepath);
+                    $items = new DirectoryIterator($path);
                     foreach ($items as $item) {
                         if (!$item->isFile()) {
                             continue;
@@ -115,8 +111,8 @@ function xmldb_assignment_upgrade($oldversion) {
                             if ($submission->teacher) {
                                 $file_record['userid'] = $submission->teacher;
                             }
-                            if ($fs->create_file_from_pathname($file_record, $basepath.$item->getFilename())) {
-                                unlink($basepath.$item->getFilename());
+                            if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
+                                unlink($path.$item->getFilename());
                             }
                         }
                     }