Skip to content

Commit

Permalink
MDL-22609 undoing directory variables magic from last commit, keeping…
Browse files Browse the repository at this point in the history
… just the userid-->submissionid itemid change
skodak committed Jul 2, 2010
1 parent 246c082 commit 8cf8f2b
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions mod/assignment/db/upgrade.php
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

0 comments on commit 8cf8f2b

Please sign in to comment.