Use Zippy to zip

This commit is contained in:
Romain Neutron
2014-02-24 16:25:59 +01:00
parent 4535491e6c
commit 5e8e8f59d5
7 changed files with 113 additions and 137 deletions

View File

@@ -1,126 +0,0 @@
<?php
/**
* ZipArchiveImproved extends ZipArchive to add some information about the zip file and some functionality.
*
*
*
* @author Farzad Ghanei
* @uses ZipArchive
* @version 1.0.0 2009-01-18
*/
class ZipArchiveImproved extends ZipArchive
{
protected $_archiveFileName = null;
protected $_newAddedFilesCounter = 0;
protected $_newAddedFilesSize = 100;
/**
* Returns the name of the archive file.
*
* @return string
*/
public function getArchiveFileName()
{
return $this->_archiveFileName;
}
/**
* Returns the number of files that are going to be added to ZIP
* without reopenning the stream to file.
*
* @return int
*/
public function getNewAddedFilesSize()
{
return $this->_newAddedFilesSize;
}
/**
* sets the number of files that are going to be added to ZIP
* without reopenning the stream to file. if no size is specified, default is 100.
*
* @param int
* @return ZipArchiveImproved self reference
*/
public function setNewlAddedFilesSize($size = 100)
{
if (empty($size) || ! is_int($size) || $size < 1) {
$size = 100;
}
$this->_newAddedFilesSize = $size;
return $this;
}
/**
* opens a stream to a ZIP archive file. calls the ZipArchive::open() internally.
* overwrites ZipArchive::open() to add the archiveFileName functionality.
*
* @param string $fileName
* @param int $flags
*
* @return mixed
*/
public function open($fileName, $flags = null)
{
$this->_archiveFileName = $fileName;
$this->_newAddedFilesCounter = 0;
return parent::open($fileName, $flags);
}
/**
* closes the stream to ZIP archive file. calls the ZipArchive::close() internally.
* overwrites ZipArchive::close() to add the archiveFileName functionality.
*
* @return bool
*/
public function close()
{
$this->_archiveFileName = null;
$this->_newAddedFilesCounter = 0;
return parent::close();
}
/**
* closes the connection to ZIP file and openes the connection again.
*
* @return bool
*/
public function reopen()
{
$archiveFileName = $this->_archiveFileName;
if ( ! $this->close()) {
return false;
}
return $this->open($archiveFileName, self::CREATE);
}
/**
* adds a file to a ZIP archive from the given path. calls the ZipArchive::addFile() internally.
* overwrites ZipArchive::addFile() to handle maximum file connections in operating systems.
*
* @param string $fileName the path to file to be added to archive
* @param string [optional] $localname the name of the file in the ZIP archive
* @param integer $start
* @param integer $length
* @return bool
*/
public function addFile($fileName, $localname = null, $start = 0, $length = 0)
{
if ($this->_newAddedFilesCounter >= $this->_newAddedFilesSize) {
$this->reopen();
}
$added = parent::addFile($fileName, $localname, $start, $length);
if ($added) {
$this->_newAddedFilesCounter ++;
}
return $added;
}
}

View File

@@ -695,11 +695,6 @@ class set_export extends set_abstract
*/
public static function build_zip(Application $app, $token, Array $list, $zipFile)
{
$zip = new ZipArchiveImproved();
if ($zip->open($zipFile, ZIPARCHIVE::CREATE) !== true) {
return false;
}
if (isset($list['complete']) && $list['complete'] === true) {
return;
}
@@ -711,6 +706,7 @@ class set_export extends set_abstract
$app['tokens']->updateToken($token, serialize($list));
$toRemove = [];
$archiveFiles = [];
foreach ($files as $record) {
if (isset($record["subdefs"])) {
@@ -722,10 +718,7 @@ class set_export extends set_abstract
. $obj["ajout"]
. '.' . $obj["exportExt"];
$name = $app['unicode']->remove_diacritics($name);
$zip->addFile($path, $name);
$archiveFiles[$app['unicode']->remove_diacritics($name)] = $path;
if ($o == 'caption') {
if (!in_array(dirname($path), $toRemove)) {
$toRemove[] = dirname($path);
@@ -737,7 +730,7 @@ class set_export extends set_abstract
}
}
$zip->close();
$app['zippy']->create($zipFile, $archiveFiles);
$list['complete'] = true;