Refactor images and document export interfaces, and implement it

modifié:         core/lib/Thelia/Controller/Admin/ImportExportController.php
	renommé:         core/lib/Thelia/ImportExport/DocumentsAwareInterface.php -> core/lib/Thelia/ImportExport/DocumentsExportInterface.php
	renommé:         core/lib/Thelia/ImportExport/ImagesAwareInterface.php -> core/lib/Thelia/ImportExport/ImagesExportInterface.php
This commit is contained in:
Benjamin Perche
2014-07-15 10:13:16 +02:00
parent 44de50c805
commit 4d5461bd08
3 changed files with 19 additions and 12 deletions

View File

@@ -17,8 +17,8 @@ use Thelia\Core\Template\Loop\Export as ExportLoop;
use Thelia\Core\Template\Loop\Import as ImportLoop; use Thelia\Core\Template\Loop\Import as ImportLoop;
use Thelia\Form\Exception\FormValidationException; use Thelia\Form\Exception\FormValidationException;
use Thelia\Form\ExportForm; use Thelia\Form\ExportForm;
use Thelia\ImportExport\DocumentsAwareInterface; use Thelia\ImportExport\DocumentsExportInterface;
use Thelia\ImportExport\ImagesAwareInterface; use Thelia\ImportExport\ImagesExportInterface;
use Thelia\Model\ExportQuery; use Thelia\Model\ExportQuery;
use Thelia\Model\ImportQuery; use Thelia\Model\ImportQuery;
@@ -118,24 +118,27 @@ class ImportExportController extends BaseAdminController
$formattedContent = $formatter->encode($data); $formattedContent = $formatter->encode($data);
if (!$boundForm->get("do_compress")->getData()) { if (!$boundForm->get("do_compress")->getData()) {
$filename = $formatter::FILENAME . "." . $formatter->getExtension();
return new Response( return new Response(
$formattedContent, $formattedContent,
200, 200,
[ [
"Content-Type" => $formatter->getMimeType(), "Content-Type" => $formatter->getMimeType(),
"Content-Disposition" => "Content-Disposition" =>
"attachment; filename=\"".$formatter::FILENAME . "attachment; filename=\"" . $filename . "\"",
"." . $formatter->getExtension() ."\"",
] ]
); );
} else { } else {
/** @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder $archiveBuilder */ /** @var \Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface $archiveBuilder */
$archiveBuilder = $this->archiveBuilderManager->get($boundForm->get("archive_builder")->getData()); $archiveBuilder = $this->archiveBuilderManager->get(
$boundForm->get("archive_builder")->getData()
);
/** /**
* Put the images in the archive * Put the images in the archive
*/ */
if ($boundForm->get("images")->getData() && $handler instanceof ImagesAwareInterface) { if ($boundForm->get("images")->getData() && $handler instanceof ImagesExportInterface) {
foreach ($handler->getImagesPaths() as $image) { foreach ($handler->getImagesPaths() as $image) {
$archiveBuilder->addFile($image, "images"); $archiveBuilder->addFile($image, "images");
} }
@@ -144,7 +147,7 @@ class ImportExportController extends BaseAdminController
/** /**
* Then the documents * Then the documents
*/ */
if ($boundForm->get("documents")->getData() && $handler instanceof DocumentsAwareInterface) { if ($boundForm->get("documents")->getData() && $handler instanceof DocumentsExportInterface) {
foreach ($handler->getDocumentsPaths() as $document) { foreach ($handler->getDocumentsPaths() as $document) {
$archiveBuilder->addFile($document, "documents"); $archiveBuilder->addFile($document, "documents");
} }

View File

@@ -12,12 +12,14 @@
namespace Thelia\ImportExport; namespace Thelia\ImportExport;
/** /**
* Interface DocumentsAwareInterface * Interface DocumentsExportInterface
* @package Thelia\ImportExport * @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr> * @author Benjamin Perche <bperche@openstudio.fr>
*/ */
interface DocumentsAwareInterface interface DocumentsExportInterface
{ {
const DOCUMENTS_DIRECTORY = "documents";
/** /**
* @return array * @return array
* *

View File

@@ -13,12 +13,14 @@ namespace Thelia\ImportExport;
/** /**
* interface ImagesAwareInterface * interface ImagesExportInterface
* @package Thelia\ImportExport * @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr> * @author Benjamin Perche <bperche@openstudio.fr>
*/ */
interface ImagesAwareInterface interface ImagesExportInterface
{ {
const IMAGES_DIRECTORY = "images";
/** /**
* @return array * @return array
* *