Merge branch 'MDL-68481_master' of git://github.com/mdjnelson/moodle

This commit is contained in:
Jun Pataleta 2020-12-16 15:20:12 +08:00
commit eacff87304
2 changed files with 22 additions and 12 deletions

View File

@ -40,20 +40,29 @@ if (!$downloadable) {
print_error('cannotdownloaddir', 'repository');
}
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_folder', 'content');
if (empty($files)) {
print_error('cannotdownloaddir', 'repository');
}
// Log zip as downloaded.
folder_downloaded($folder, $course, $cm, $context);
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'mod_folder', 'content', 0, '/', '.');
if (!$file) {
print_error('cannotdownloaddir', 'repository');
}
// Close the session.
\core\session\manager::write_close();
$zipper = get_file_packer('application/zip');
$filename = shorten_filename(clean_filename($folder->name . "-" . date("Ymd")) . ".zip");
$temppath = make_request_directory() . $filename;
$zipwriter = \core_files\archive_writer::get_stream_writer($filename, \core_files\archive_writer::ZIP_WRITER);
if ($zipper->archive_to_pathname(array('/' => $file), $temppath)) {
send_temp_file($temppath, $filename);
} else {
print_error('cannotdownloaddir', 'repository');
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$pathinzip = $file->get_filepath() . $file->get_filename();
$zipwriter->add_file_from_stored_file($pathinzip, $file);
}
// Finish the archive.
$zipwriter->finish();
exit();

View File

@ -72,7 +72,8 @@ class mod_folder_renderer extends plugin_renderer_base {
if ($downloadable) {
$downloadbutton = $this->output->single_button(
new moodle_url('/mod/folder/download_folder.php', array('id' => $cm->id)),
get_string('downloadfolder', 'folder')
get_string('downloadfolder', 'folder'),
'get'
);
$buttons .= $downloadbutton;