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);
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue