mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
Merge branch 'wip-MDL-39177-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
89f6db3776
@ -219,6 +219,8 @@ switch ($action) {
|
||||
|
||||
// Find unused name for directory to extract the archive.
|
||||
$temppath = $fs->get_unused_dirname($user_context->id, 'user', 'draft', $draftid, $filepath. pathinfo($filename, PATHINFO_FILENAME). '/');
|
||||
$donotremovedirs = array();
|
||||
$doremovedirs = array($temppath);
|
||||
// Extract archive and move all files from $temppath to $filepath
|
||||
if ($file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $draftid, $temppath, $USER->id) !== false) {
|
||||
$extractedfiles = $fs->get_directory_files($user_context->id, 'user', 'draft', $draftid, $temppath, true);
|
||||
@ -233,8 +235,12 @@ switch ($action) {
|
||||
// File or directory did not exist, just move it.
|
||||
$file->rename($realpath, $file->get_filename());
|
||||
} else if (!$file->is_directory()) {
|
||||
// File already existed, overwrite it (nothing to do with existing directories).
|
||||
// File already existed, overwrite it
|
||||
repository::overwrite_existing_draftfile($draftid, $realpath, $file->get_filename(), $file->get_filepath(), $file->get_filename());
|
||||
} else {
|
||||
// Directory already existed, remove temporary dir but make sure we don't remove the existing dir
|
||||
$doremovedirs[] = $file->get_filepath();
|
||||
$donotremovedirs[] = $realpath;
|
||||
}
|
||||
}
|
||||
$return = new stdClass();
|
||||
@ -243,11 +249,10 @@ switch ($action) {
|
||||
$return = false;
|
||||
}
|
||||
// Remove remaining temporary directories.
|
||||
foreach ($fs->get_directory_files($user_context->id, 'user', 'draft', $draftid, $temppath, true, true, 'filepath desc, filename desc') as $file) {
|
||||
$file->delete();
|
||||
}
|
||||
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $temppath, '.')) {
|
||||
$file->delete();
|
||||
foreach (array_diff($doremovedirs, $donotremovedirs) as $filepath) {
|
||||
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, '.')) {
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
die(json_encode($return));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user