diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php index eb81bdabb..dbecd9312 100644 --- a/core/lib/Thelia/Controller/Admin/ImportExportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -11,6 +11,8 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\ImportExport\Export as ExportEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Loop\Export as ExportLoop; @@ -115,12 +117,24 @@ class ImportExportController extends BaseAdminController $boundForm->get("formatter")->getData() ); - $formattedContent = $formatter->encode($data); - $filename = $formatter::FILENAME . "." . $formatter->getExtension(); if (!$boundForm->get("do_compress")->getData()) { + /** + * Build an event containing the formatter and the handler. + * Used for specific configuration (e.g: XML node names) + */ + $event = new ExportEvent($formatter, $handler); + + if (!$boundForm->get("do_compress")->getData()) + { + /** + * Dispatch the event + */ + $this->dispatch(TheliaEvents::BEFORE_EXPORT, $event); + + $formattedContent = $formatter->encode($data); return new Response( $formattedContent, @@ -137,21 +151,31 @@ class ImportExportController extends BaseAdminController $boundForm->get("archive_builder")->getData() ); - /** - * Put the images in the archive - */ - if ($boundForm->get("images")->getData() && $handler instanceof ImagesExportInterface) { - foreach ($handler->getImagesPaths() as $image) { - $archiveBuilder->addFile($image, "images"); + $event->setArchiveBuilder($archiveBuilder); + $this->dispatch(TheliaEvents::BEFORE_EXPORT, $event); + + $formattedContent = $formatter->encode($data); + + $includeImages = $boundForm->get("images")->getData(); + $includeDocuments = $boundForm->get("documents")->getData(); + + if ($includeImages && $handler instanceof ImagesExportInterface) { + foreach ($handler->getImagesPaths() as $name => $documentPath) { + $archiveBuilder->addFile( + $documentPath, + $handler::IMAGES_DIRECTORY, + is_integer($name) ? null : $name + ); } } - /** - * Then the documents - */ - if ($boundForm->get("documents")->getData() && $handler instanceof DocumentsExportInterface) { - foreach ($handler->getDocumentsPaths() as $document) { - $archiveBuilder->addFile($document, "documents"); + if ($includeDocuments && $handler instanceof DocumentsExportInterface) { + foreach ($handler->getDocumentsPaths() as $name => $documentPath) { + $archiveBuilder->addFile( + $documentPath, + $handler::DOCUMENTS_DIRECTORY, + is_integer($name) ? null : $name + ); } } diff --git a/core/lib/Thelia/Core/Event/ImportExport/Export.php b/core/lib/Thelia/Core/Event/ImportExport/Export.php new file mode 100644 index 000000000..4e3c5a5f5 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ImportExport/Export.php @@ -0,0 +1,101 @@ + + */ +class Export extends ActionEvent +{ + /** @var \Thelia\ImportExport\ExportHandler */ + protected $handler; + + /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter */ + protected $formatter; + + /** @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder */ + protected $archiveBuilder; + + function __construct( + AbstractFormatter $formatter, + ExportHandler $handler, + AbstractArchiveBuilder $archiveBuilder = null + ) { + $this->archiveBuilder = $archiveBuilder; + $this->formatter = $formatter; + $this->handler = $handler; + } + + /** + * @param AbstractArchiveBuilder $archiveBuilder + * @return $this + */ + public function setArchiveBuilder(AbstractArchiveBuilder $archiveBuilder) + { + $this->archiveBuilder = $archiveBuilder; + + return $this; + } + + /** + * @return \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder + */ + public function getArchiveBuilder() + { + return $this->archiveBuilder; + } + + /** + * @param AbstractFormatter $formatter + * @return $this + */ + public function setFormatter(AbstractFormatter $formatter) + { + $this->formatter = $formatter; + + return $this; + } + + /** + * @return \Thelia\Core\FileFormat\Formatting\AbstractFormatter + */ + public function getFormatter() + { + return $this->formatter; + } + + /** + * @param ExportHandler $handler + * @return $this + */ + public function setHandler(ExportHandler $handler) + { + $this->handler = $handler; + + return $this; + } + + /** + * @return \Thelia\ImportExport\ExportHandler + */ + public function getHandler() + { + return $this->handler; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 9c2962801..40d0e758c 100644 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -766,4 +766,8 @@ final class TheliaEvents const BEFORE_UPDATEBRAND = "action.before_updateBrand"; const AFTER_UPDATEBRAND = "action.after_updateBrand"; + + // -- Export ---------------------------------------------- + + const BEFORE_EXPORT = "Thelia.before.export"; } diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php index 558446bae..df9a1b8d2 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php @@ -25,6 +25,7 @@ class XMLFormatter extends AbstractFormatter { public $root = "data"; public $nodeName = "node"; + public $rowName = "row"; /** * @return string @@ -85,7 +86,13 @@ class XMLFormatter extends AbstractFormatter $node = $container->appendChild(new \DOMElement($this->nodeName)); $this->recursiveBuild($entry, $node); } else { - $container->appendChild(new \DOMElement($key, $entry)); + $node = new \DOMElement($this->nodeName); + $container->appendChild($node); + + /** @var \DOMElement $lastChild */ + $lastChild = $container->lastChild; + $lastChild->setAttribute("name",$key); + $lastChild->setAttribute("value", $entry); } } @@ -102,7 +109,13 @@ class XMLFormatter extends AbstractFormatter $newNode = $node->appendChild(new \DOMElement($key)); $this->recursiveBuild($entry, $newNode); } else { - $node->appendChild(new \DOMElement($key, $entry)); + $inputNode = new \DOMElement($this->rowName); + $node->appendChild($inputNode); + + /** @var \DOMElement $lastChild */ + $lastChild = $node->lastChild; + $lastChild->setAttribute("name",$key); + $lastChild->setAttribute("value", $entry); } } } diff --git a/templates/backOffice/default/ajax/export-modal.html b/templates/backOffice/default/ajax/export-modal.html index 46a32cbce..9b6936f91 100644 --- a/templates/backOffice/default/ajax/export-modal.html +++ b/templates/backOffice/default/ajax/export-modal.html @@ -15,21 +15,16 @@
{form_field form=$form field="formatter"} -
- - - {if $error} -
{$message}
- {/if} -
+ + {/form_field}
@@ -45,7 +40,10 @@
- {custom_render_form_field form=$form field="archive_builder"} + {form_field form=$form field="archive_builder"} + - {/custom_render_form_field} + {/form_field}
{form_field form=$form field="images"} diff --git a/templates/backOffice/default/export-page.html b/templates/backOffice/default/export-page.html index 80e633758..671e1e49a 100644 --- a/templates/backOffice/default/export-page.html +++ b/templates/backOffice/default/export-page.html @@ -1,7 +1,7 @@ {extends file="admin-layout.tpl"} {block name="no-return-functions"} - {$admin_current_location = 'modules'} + {$admin_current_location = 'tools'} {/block} {block name="page-title"}{intl l='Export'}: {$TITLE}{/block}