mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-22609 undoing directory variables magic from last commit, keeping just the userid-->submissionid itemid change
This commit is contained in:
parent
246c082a4c
commit
8cf8f2b743
1 changed files with 10 additions and 14 deletions
|
@ -68,18 +68,15 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $submission->cmid);
|
$context = get_context_instance(CONTEXT_MODULE, $submission->cmid);
|
||||||
|
|
||||||
// migrate submitted files first
|
// migrate submitted files first
|
||||||
$newpath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->id/";
|
$path = $basepath;
|
||||||
if (!file_exists($newpath)) {
|
|
||||||
mkdir($newpath);
|
|
||||||
}
|
|
||||||
$filearea = 'assignment_submission';
|
$filearea = 'assignment_submission';
|
||||||
$items = new DirectoryIterator($basepath);
|
$items = new DirectoryIterator($path);
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
if (!$item->isFile()) {
|
if (!$item->isFile()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!$item->isReadable()) {
|
if (!$item->isReadable()) {
|
||||||
echo $OUTPUT->notification(" File not readable, skipping: ".$basepath.$item->getFilename());
|
echo $OUTPUT->notification(" File not readable, skipping: ".$path.$item->getFilename());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$filename = clean_param($item->getFilename(), PARAM_FILE);
|
$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)) {
|
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);
|
$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())) {
|
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||||
unlink($basepath.$item->getFilename());
|
unlink($path.$item->getFilename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($items); //release file handles
|
unset($items); //release file handles
|
||||||
|
|
||||||
// migrate teacher response files
|
// migrate teacher response files
|
||||||
$basepath = $basepath.'responses/';
|
$path = $basepath.'responses/';
|
||||||
$newpath = $newpath.'responses/';
|
if (file_exists($path)) {
|
||||||
if (file_exists($basepath)) {
|
|
||||||
$filearea = 'assignment_response';
|
$filearea = 'assignment_response';
|
||||||
$items = new DirectoryIterator($basepath);
|
$items = new DirectoryIterator($path);
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
if (!$item->isFile()) {
|
if (!$item->isFile()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -115,8 +111,8 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||||
if ($submission->teacher) {
|
if ($submission->teacher) {
|
||||||
$file_record['userid'] = $submission->teacher;
|
$file_record['userid'] = $submission->teacher;
|
||||||
}
|
}
|
||||||
if ($fs->create_file_from_pathname($file_record, $basepath.$item->getFilename())) {
|
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||||
unlink($basepath.$item->getFilename());
|
unlink($path.$item->getFilename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue