Add image and document export helpers
modifié: core/lib/Thelia/Controller/Admin/ExportController.php modifié: core/lib/Thelia/ImportExport/Export/ExportHandler.php
This commit is contained in:
@@ -168,16 +168,15 @@ class ExportController extends BaseAdminController
|
||||
* Build an event containing the formatter and the handler.
|
||||
* Used for specific configuration (e.g: XML node names)
|
||||
*/
|
||||
$data = $handler
|
||||
->buildData($lang)
|
||||
->setLang($lang)
|
||||
;
|
||||
|
||||
$event = new ImportExportEvent($formatter, $handler , $data);
|
||||
$event = new ImportExportEvent($formatter, $handler);
|
||||
|
||||
$filename = $formatter::FILENAME . "." . $formatter->getExtension();
|
||||
|
||||
if ($archiveBuilder === null) {
|
||||
$data = $handler->buildData($lang);
|
||||
|
||||
$event->setData($data);
|
||||
$this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
|
||||
|
||||
$formattedContent = $formatter
|
||||
@@ -198,6 +197,24 @@ class ExportController extends BaseAdminController
|
||||
);
|
||||
} else {
|
||||
$event->setArchiveBuilder($archiveBuilder);
|
||||
|
||||
if ($includeImages && $handler instanceof ImagesExportInterface) {
|
||||
$this->processExportImages($handler, $archiveBuilder);
|
||||
|
||||
$handler->setImageExport(true);
|
||||
}
|
||||
|
||||
if ($includeDocuments && $handler instanceof DocumentsExportInterface) {
|
||||
$this->processExportDocuments($handler, $archiveBuilder);
|
||||
|
||||
$handler->setDocumentExport(true);
|
||||
}
|
||||
|
||||
$data = $handler
|
||||
->buildData($lang)
|
||||
->setLang($lang)
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
|
||||
|
||||
$formattedContent = $formatter
|
||||
@@ -207,13 +224,6 @@ class ExportController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
|
||||
|
||||
if ($includeImages && $handler instanceof ImagesExportInterface) {
|
||||
$this->processExportImages($handler, $archiveBuilder);
|
||||
}
|
||||
|
||||
if ($includeDocuments && $handler instanceof DocumentsExportInterface) {
|
||||
$this->processExportDocuments($handler, $archiveBuilder);
|
||||
}
|
||||
|
||||
$archiveBuilder->addFileFromString(
|
||||
$event->getContent(), $filename
|
||||
|
||||
@@ -17,6 +17,7 @@ use Thelia\Core\FileFormat\Formatting\FormatterData;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\Exception\LoopException;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Files\FileModelInterface;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\ImportExport\AbstractHandler;
|
||||
|
||||
@@ -32,6 +33,10 @@ abstract class ExportHandler extends AbstractHandler
|
||||
/** @var array */
|
||||
protected $order = array();
|
||||
|
||||
protected $isImageExport = false;
|
||||
|
||||
protected $isDocumentExport = false;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
@@ -209,6 +214,39 @@ abstract class ExportHandler extends AbstractHandler
|
||||
return $loopInstance;
|
||||
}
|
||||
|
||||
protected function addFileToArray(FileModelInterface $model, array &$paths)
|
||||
{
|
||||
$path = $model->getUploadDir() . DS . $model->getFile();
|
||||
|
||||
if (is_file($path) && is_readable($path)) {
|
||||
$paths[$model->getTitle() . DS . $model->getFile()] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
public function setDocumentExport($bool)
|
||||
{
|
||||
$this->isDocumentExport = (bool) $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setImageExport($bool)
|
||||
{
|
||||
$this->isImageExport = (bool) $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDocumentExport()
|
||||
{
|
||||
return $this->isDocumentExport;
|
||||
}
|
||||
|
||||
public function isImageExport()
|
||||
{
|
||||
return $this->isImageExport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Lang $lang
|
||||
* @return ModelCriteria|array|BaseLoop
|
||||
|
||||
Reference in New Issue
Block a user