MDL-51863 packer: ensure empty zip files behavior remains consistent
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 26 Oct 2015 16:59:40 +0000 (17:59 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 26 Oct 2015 20:16:54 +0000 (21:16 +0100)
commit70ae75674dcbe028d79d0622bfddb94c73abdb6b
treeb7c34d6d587f2cbeab29d4ca7c9dfe7a22e4f65c
parent9382ac38d60bee1226e3ba13906770552bea6012
MDL-51863 packer: ensure empty zip files behavior remains consistent

With PHP bug #70322 fixed, ZipArchive::close() did start returning false
and throwing PHP Warnings with recent PHP versions (5.6.14 and up).
Previously (5.6.13 verified) it was returning true, and false in older
versions (5.4.x verified).

This change does silent the 2 "hacky" calls to close() that we perform
in core leaving the 3rd one (used for files having files) unmodified.

A new unit test has been created to cover the close() behavior, ideally
supporting both old and new PHP versions without harcoding any PHP
version.

Note that we don't use to rely much on results coming from close(), and
that's a good thing given the buggy behavior commented above. This just
keeps empty zips working like they were before.
lib/filestorage/tests/zip_packer_test.php
lib/filestorage/zip_archive.php