diff --git a/lib/filestorage/tests/zip_packer_test.php b/lib/filestorage/tests/zip_packer_test.php index da203d4fa30..b39bcdfa3e5 100644 --- a/lib/filestorage/tests/zip_packer_test.php +++ b/lib/filestorage/tests/zip_packer_test.php @@ -446,6 +446,22 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p array(file_progress::INDETERMINATE, file_progress::INDETERMINATE), $this->progress[0]); + // Archive to pathname using entire folder and subfolder instead of file list. + unlink($archive); + $folder = make_temp_directory('zip_packer_progress'); + file_put_contents($folder . '/test1.txt', 'hello'); + $subfolder = $folder . '/sub'; + check_dir_exists($subfolder); + file_put_contents($subfolder . '/test2.txt', 'world'); + file_put_contents($subfolder . '/test3.txt', 'and'); + file_put_contents($subfolder . '/test4.txt', 'other'); + file_put_contents($subfolder . '/test5.txt', 'worlds'); + $this->progress = array(); + $result = $packer->archive_to_pathname(array('' => $folder), $archive, true, $this); + $this->assertTrue($result); + // Should send progress at least once per file. + $this->assertTrue(count($this->progress) >= 5); + // Archive to storage. $this->progress = array(); $archivefile = $packer->archive_to_storage($this->files, $context->id, diff --git a/lib/filestorage/zip_packer.php b/lib/filestorage/zip_packer.php index dcd9025b686..175a55217a1 100644 --- a/lib/filestorage/zip_packer.php +++ b/lib/filestorage/zip_packer.php @@ -122,7 +122,7 @@ class zip_packer extends file_packer { } } else if (is_string($file)) { - if (!$this->archive_pathname($ziparch, $archivepath, $file)) { + if (!$this->archive_pathname($ziparch, $archivepath, $file, $progress)) { debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER); if (!$ignoreinvalidfiles) { $abort = true; @@ -141,7 +141,7 @@ class zip_packer extends file_packer { } } else { - if (!$this->archive_stored($ziparch, $archivepath, $file)) { + if (!$this->archive_stored($ziparch, $archivepath, $file, $progress)) { debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER); if (!$ignoreinvalidfiles) { $abort = true; @@ -242,7 +242,7 @@ class zip_packer extends file_packer { continue; } $newpath = $archivepath.'/'.$file->getFilename(); - $this->archive_pathname($ziparch, $newpath, $file->getPathname()); + $this->archive_pathname($ziparch, $newpath, $file->getPathname(), $progress); } unset($files); // Release file handles. return true;