mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 00:20:37 +01:00
MDL-68533 mod_assign: stream files when creating zip
This commit is contained in:
parent
38cd9a6bd7
commit
3b687239da
@ -2505,27 +2505,6 @@ class assign {
|
||||
return $useridlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate zip file from array of given files.
|
||||
*
|
||||
* @param array $filesforzipping - array of files to pass into archive_to_pathname.
|
||||
* This array is indexed by the final file name and each
|
||||
* element in the array is an instance of a stored_file object.
|
||||
* @return path of temp file - note this returned file does
|
||||
* not have a .zip extension - it is a temp file.
|
||||
*/
|
||||
protected function pack_files($filesforzipping) {
|
||||
global $CFG;
|
||||
// Create path for new zip file.
|
||||
$tempzip = tempnam($CFG->tempdir . '/', 'assignment_');
|
||||
// Zip files.
|
||||
$zipper = new zip_packer();
|
||||
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
|
||||
return $tempzip;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all assignment notifications that have yet to be mailed out, and mails them.
|
||||
*
|
||||
@ -3660,13 +3639,26 @@ class assign {
|
||||
'action'=>'grading'));
|
||||
$result .= $this->get_renderer()->continue_button($url);
|
||||
$result .= $this->view_footer();
|
||||
} else if ($zipfile = $this->pack_files($filesforzipping)) {
|
||||
\mod_assign\event\all_submissions_downloaded::create_from_assign($this)->trigger();
|
||||
// Send file and delete after sending.
|
||||
send_temp_file($zipfile, $filename);
|
||||
// We will not get here - send_temp_file calls exit.
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
|
||||
// Log zip as downloaded.
|
||||
\mod_assign\event\all_submissions_downloaded::create_from_assign($this)->trigger();
|
||||
|
||||
// Close the session.
|
||||
\core\session\manager::write_close();
|
||||
|
||||
$zipwriter = \core_files\archive_writer::get_stream_writer($filename, \core_files\archive_writer::ZIP_WRITER);
|
||||
|
||||
// Stream the files into the zip.
|
||||
foreach ($filesforzipping as $pathinzip => $storedfile) {
|
||||
$zipwriter->add_file_from_stored_file($pathinzip, $storedfile);
|
||||
}
|
||||
|
||||
// Finish the archive.
|
||||
$zipwriter->finish();
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user