Skip to content

Commit

Permalink
MDL-76011 lib: Updated the zip writer to retain the modified date.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Oct 27, 2022
1 parent dbb2dee commit 91bf858
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion files/classes/local/archive_writer/zip_writer.php
Expand Up @@ -26,6 +26,7 @@

use ZipStream\Option\Archive;
use ZipStream\ZipStream;
use ZipStream\Option\File as FileOptions;
use core_files\archive_writer;
use core_files\local\archive_writer\file_writer_interface as file_writer_interface;
use core_files\local\archive_writer\stream_writer_interface as stream_writer_interface;
Expand Down Expand Up @@ -110,8 +111,12 @@ public function add_file_from_stream(string $name, $stream): void {
}

public function add_file_from_stored_file(string $name, \stored_file $file): void {
$datetime = new \DateTime();
$datetime->setTimestamp($file->get_timemodified());
$fileoptions = new FileOptions();
$fileoptions->setTime($datetime);
$filehandle = $file->get_content_file_handle();
$this->archive->addFileFromStream($this->sanitise_filepath($name), $filehandle);
$this->archive->addFileFromStream($this->sanitise_filepath($name), $filehandle, $fileoptions);
fclose($filehandle);
}

Expand Down

0 comments on commit 91bf858

Please sign in to comment.