mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Use Zippy to zip
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
"alchemy/oauth2php" : "1.0.0",
|
"alchemy/oauth2php" : "1.0.0",
|
||||||
"alchemy/phlickr" : "0.2.7",
|
"alchemy/phlickr" : "0.2.7",
|
||||||
"alchemy/task-manager" : "2.0.x-dev@dev",
|
"alchemy/task-manager" : "2.0.x-dev@dev",
|
||||||
|
"alchemy/zippy" : "0.2.x-dev@dev",
|
||||||
"cboden/ratchet" : "~0.3",
|
"cboden/ratchet" : "~0.3",
|
||||||
"dailymotion/sdk" : "~1.5",
|
"dailymotion/sdk" : "~1.5",
|
||||||
"data-uri/data-uri" : "~0.1.0",
|
"data-uri/data-uri" : "~0.1.0",
|
||||||
|
65
composer.lock
generated
65
composer.lock
generated
@@ -3,7 +3,7 @@
|
|||||||
"This file locks the dependencies of your project to a known state",
|
"This file locks the dependencies of your project to a known state",
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||||
],
|
],
|
||||||
"hash": "6ff48c308a23b2876dbda7b44f6f1d1a",
|
"hash": "ee3972e781af8721a6af65018129861f",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "alchemy-fr/tcpdf-clone",
|
"name": "alchemy-fr/tcpdf-clone",
|
||||||
@@ -355,6 +355,68 @@
|
|||||||
],
|
],
|
||||||
"time": "2014-02-14 12:39:44"
|
"time": "2014-02-14 12:39:44"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "alchemy/zippy",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/alchemy-fr/Zippy.git",
|
||||||
|
"reference": "8ccc695f66c3b61ffdb3b9e88474602da52401ae"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/alchemy-fr/Zippy/zipball/8ccc695f66c3b61ffdb3b9e88474602da52401ae",
|
||||||
|
"reference": "8ccc695f66c3b61ffdb3b9e88474602da52401ae",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"doctrine/collections": "~1.0",
|
||||||
|
"guzzle/guzzle": "~3.0",
|
||||||
|
"php": ">=5.3.3",
|
||||||
|
"pimple/pimple": "~1.0",
|
||||||
|
"symfony/filesystem": "~2.0",
|
||||||
|
"symfony/process": "~2.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"ext-zip": "*",
|
||||||
|
"phpunit/phpunit": "~3.7",
|
||||||
|
"sami/sami": "dev-master@dev",
|
||||||
|
"symfony/finder": "~2.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-zip": "To use the ZipExtensionAdapter"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "0.2.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"Alchemy": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Alchemy",
|
||||||
|
"email": "dev.team@alchemy.fr",
|
||||||
|
"homepage": "http://www.alchemy.fr/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Zippy, the archive manager companion",
|
||||||
|
"keywords": [
|
||||||
|
"bzip",
|
||||||
|
"compression",
|
||||||
|
"tar",
|
||||||
|
"zip"
|
||||||
|
],
|
||||||
|
"time": "2014-02-18 22:09:18"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "cboden/ratchet",
|
"name": "cboden/ratchet",
|
||||||
"version": "v0.3.0",
|
"version": "v0.3.0",
|
||||||
@@ -4584,6 +4646,7 @@
|
|||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
"alchemy/task-manager": 20,
|
"alchemy/task-manager": 20,
|
||||||
|
"alchemy/zippy": 20,
|
||||||
"imagine/imagine": 20,
|
"imagine/imagine": 20,
|
||||||
"neutron/process-manager": 20,
|
"neutron/process-manager": 20,
|
||||||
"silex/silex": 20,
|
"silex/silex": 20,
|
||||||
|
@@ -110,6 +110,7 @@ use Alchemy\Phrasea\Core\Provider\TemporaryFilesystemServiceProvider;
|
|||||||
use Alchemy\Phrasea\Core\Provider\TokensServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\TokensServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\TranslationServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\TranslationServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider;
|
||||||
|
use Alchemy\Phrasea\Core\Provider\ZippyServiceProvider;
|
||||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
use Alchemy\Phrasea\Form\Extension\HelpTypeExtension;
|
use Alchemy\Phrasea\Form\Extension\HelpTypeExtension;
|
||||||
@@ -286,6 +287,7 @@ class Application extends SilexApplication
|
|||||||
$this->register(new PHPExiftoolServiceProvider());
|
$this->register(new PHPExiftoolServiceProvider());
|
||||||
$this->register(new ReCaptchaServiceProvider());
|
$this->register(new ReCaptchaServiceProvider());
|
||||||
$this->register(new SubdefServiceProvider());
|
$this->register(new SubdefServiceProvider());
|
||||||
|
$this->register(new ZippyServiceProvider());
|
||||||
|
|
||||||
$this['recaptcha.public-key'] = $this->share(function (Application $app) {
|
$this['recaptcha.public-key'] = $this->share(function (Application $app) {
|
||||||
if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) {
|
if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) {
|
||||||
|
30
lib/Alchemy/Phrasea/Core/Provider/ZippyServiceProvider.php
Normal file
30
lib/Alchemy/Phrasea/Core/Provider/ZippyServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2014 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
|
use Alchemy\Zippy\Zippy;
|
||||||
|
use Silex\Application;
|
||||||
|
use Silex\ServiceProviderInterface;
|
||||||
|
|
||||||
|
class ZippyServiceProvider implements ServiceProviderInterface
|
||||||
|
{
|
||||||
|
public function register(Application $app)
|
||||||
|
{
|
||||||
|
$app['zippy'] = $app->share(function () {
|
||||||
|
return Zippy::load();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(Application $app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -695,11 +695,6 @@ class set_export extends set_abstract
|
|||||||
*/
|
*/
|
||||||
public static function build_zip(Application $app, $token, Array $list, $zipFile)
|
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) {
|
if (isset($list['complete']) && $list['complete'] === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -711,6 +706,7 @@ class set_export extends set_abstract
|
|||||||
$app['tokens']->updateToken($token, serialize($list));
|
$app['tokens']->updateToken($token, serialize($list));
|
||||||
|
|
||||||
$toRemove = [];
|
$toRemove = [];
|
||||||
|
$archiveFiles = [];
|
||||||
|
|
||||||
foreach ($files as $record) {
|
foreach ($files as $record) {
|
||||||
if (isset($record["subdefs"])) {
|
if (isset($record["subdefs"])) {
|
||||||
@@ -722,10 +718,7 @@ class set_export extends set_abstract
|
|||||||
. $obj["ajout"]
|
. $obj["ajout"]
|
||||||
. '.' . $obj["exportExt"];
|
. '.' . $obj["exportExt"];
|
||||||
|
|
||||||
$name = $app['unicode']->remove_diacritics($name);
|
$archiveFiles[$app['unicode']->remove_diacritics($name)] = $path;
|
||||||
|
|
||||||
$zip->addFile($path, $name);
|
|
||||||
|
|
||||||
if ($o == 'caption') {
|
if ($o == 'caption') {
|
||||||
if (!in_array(dirname($path), $toRemove)) {
|
if (!in_array(dirname($path), $toRemove)) {
|
||||||
$toRemove[] = dirname($path);
|
$toRemove[] = dirname($path);
|
||||||
@@ -737,7 +730,7 @@ class set_export extends set_abstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$app['zippy']->create($zipFile, $archiveFiles);
|
||||||
|
|
||||||
$list['complete'] = true;
|
$list['complete'] = true;
|
||||||
|
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Tests\Phrasea\Core\Provider;
|
||||||
|
|
||||||
|
class ZippyServiceProviderTest extends ServiceProviderTestCase
|
||||||
|
{
|
||||||
|
public function provideServiceDescription()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['Alchemy\Phrasea\Core\Provider\ZippyServiceProvider', 'zippy', 'Alchemy\Zippy\Zippy'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user