mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00

Conflicts: lib/Alchemy/Phrasea/Controller/Admin/Publications.php lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php lib/Alchemy/Phrasea/Controller/Api/V1.php lib/Alchemy/Phrasea/Controller/Lightbox.php lib/Alchemy/Phrasea/Controller/Permalink.php lib/Alchemy/Phrasea/Controller/Prod/Feed.php lib/Alchemy/Phrasea/Controller/Prod/Order.php lib/Alchemy/Phrasea/Controller/Prod/Push.php lib/Alchemy/Phrasea/Controller/Prod/Share.php lib/Alchemy/Phrasea/Controller/Root/Login.php lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php lib/Alchemy/Phrasea/Controller/Root/Session.php lib/Alchemy/Phrasea/Controller/Setup.php lib/Alchemy/Phrasea/Core/CLIProvider/LessBuilderServiceProvider.php lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php lib/classes/Feed/Entry/Item.php lib/classes/record/adapter.php lib/classes/task/Scheduler.php lib/classes/task/manager.php lib/classes/task/period/RecordMover.php lib/classes/task/period/archive.php lib/classes/task/period/cindexer.php lib/classes/task/period/ftp.php lib/classes/task/period/ftpPull.php lib/classes/task/period/subdef.php lib/classes/task/period/writemeta.php tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php tests/classes/Feed/Entry/Feed_Entry_ItemTest.php tests/classes/PhraseanetPHPUnitAbstract.php
91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2013 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Controller\Prod;
|
|
|
|
use Silex\Application;
|
|
use Silex\ControllerProviderInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
|
|
class Download implements ControllerProviderInterface
|
|
{
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function connect(Application $app)
|
|
{
|
|
$app['controller.prod.download'] = $this;
|
|
|
|
$controllers = $app['controllers_factory'];
|
|
|
|
$controllers->before(function (Request $request) use ($app) {
|
|
$app['firewall']->requireAuthentication();
|
|
});
|
|
|
|
$controllers->post('/', 'controller.prod.download:checkDownload')
|
|
->bind('check_download');
|
|
|
|
return $controllers;
|
|
}
|
|
|
|
/**
|
|
* Download a set of documents
|
|
*
|
|
* @param Application $app
|
|
* @param Request $request
|
|
* @return RedirectResponse
|
|
*/
|
|
public function checkDownload(Application $app, Request $request)
|
|
{
|
|
$lst = $request->request->get('lst');
|
|
$ssttid = $request->request->get('ssttid', '');
|
|
$subdefs = $request->request->get('obj', array());
|
|
|
|
$download = new \set_export($app, $lst, $ssttid);
|
|
|
|
if (0 === $download->get_total_download()) {
|
|
$app->abort(403);
|
|
}
|
|
|
|
$list = $download->prepare_export(
|
|
$app['authentication']->getUser(),
|
|
$app['filesystem'],
|
|
$subdefs,
|
|
$request->request->get('title') === 'title' ? true : false,
|
|
$request->request->get('businessfields')
|
|
);
|
|
|
|
$list['export_name'] = sprintf('%s.zip', $download->getExportName());
|
|
|
|
$token = $app['tokens']->getUrlToken(
|
|
\random::TYPE_DOWNLOAD,
|
|
$app['authentication']->getUser()->get_id(),
|
|
new \DateTime('+3 hours'), // Token lifetime
|
|
serialize($list)
|
|
);
|
|
|
|
if (!$token) {
|
|
throw new \RuntimeException('Download token could not be generated');
|
|
}
|
|
|
|
$app['events-manager']->trigger('__DOWNLOAD__', array(
|
|
'lst' => $lst,
|
|
'downloader' => $app['authentication']->getUser()->get_id(),
|
|
'subdefs' => $subdefs,
|
|
'from_basket' => $ssttid,
|
|
'export_file' => $download->getExportName()
|
|
));
|
|
|
|
return $app->redirectPath('prepare_download', array('token' => $token));
|
|
}
|
|
}
|