Fix form hidden fields and begin export controller
modifié: core/lib/Thelia/Controller/Admin/ImportExportController.php modifié: core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php modifié: templates/backOffice/default/ajax/export-modal.html modifié: templates/backOffice/default/export-page.html
This commit is contained in:
@@ -11,9 +11,12 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Loop\Export as ExportLoop;
|
||||
use Thelia\Core\Template\Loop\Import as ImportLoop;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Form\ExportForm;
|
||||
use Thelia\Model\ExportQuery;
|
||||
|
||||
/**
|
||||
@@ -23,6 +26,19 @@ use Thelia\Model\ExportQuery;
|
||||
*/
|
||||
class ImportExportController extends BaseAdminController
|
||||
{
|
||||
/** @var \Thelia\Core\FileFormat\Archive\ArchiveBuilderManager */
|
||||
protected $archiveBuilderManager;
|
||||
|
||||
/** @var \Thelia\Core\FileFormat\Formatting\FormatterManager */
|
||||
protected $formatterManager;
|
||||
|
||||
public function hydrate()
|
||||
{
|
||||
|
||||
$this->archiveBuilderManager = $this->container->get("thelia.manager.archive_builder_manager");
|
||||
$this->formatterManager = $this->container->get("thelia.manager.formatter_manager");
|
||||
}
|
||||
|
||||
public function import($id)
|
||||
{
|
||||
|
||||
@@ -30,7 +46,93 @@ class ImportExportController extends BaseAdminController
|
||||
|
||||
public function export($id)
|
||||
{
|
||||
if (null === $export = $this->getExport($id)) {
|
||||
return $this->render("404");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get needed services
|
||||
*/
|
||||
$this->hydrate();
|
||||
|
||||
/**
|
||||
* Get the archive builders
|
||||
*/
|
||||
$archiveBuilders = [];
|
||||
foreach ($this->archiveBuilderManager->getNames() as $archiveBuilder) {
|
||||
$archiveBuilders[$archiveBuilder] = $archiveBuilder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the allowed formatters to inject them into the form
|
||||
*/
|
||||
$handler = $export->getHandleClassInstance($this->container);
|
||||
|
||||
$types = $handler->getHandledType();
|
||||
|
||||
if (!is_array($types)) {
|
||||
$types = [$types];
|
||||
}
|
||||
|
||||
$formatters = [];
|
||||
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
|
||||
foreach ($this->formatterManager->getAll() as $formatter) {
|
||||
if (in_array($formatter->getExportType(), $types)) {
|
||||
$formatters[$formatter->getName()] = $formatter->getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define and validate the form
|
||||
*/
|
||||
$form = new ExportForm($this->getRequest());
|
||||
$form->setArchiveBuilderNames($archiveBuilders);
|
||||
$form->setFormatters($formatters);
|
||||
$errorMessage = null;
|
||||
|
||||
try {
|
||||
$boundForm = $this->validateForm($form);
|
||||
|
||||
$data = $handler->buildFormatterData();
|
||||
|
||||
$formatter = $this->formatterManager->get(
|
||||
$boundForm->get("formatter")->getData()
|
||||
);
|
||||
|
||||
$formattedContent = $formatter->encode($data);
|
||||
|
||||
if (!$boundForm->get("do_compress")->getData())
|
||||
{
|
||||
return new Response(
|
||||
$formattedContent,
|
||||
200,
|
||||
[
|
||||
"Content-Type" => $formatter->getMimeType(),
|
||||
"Content-Disposition" => $formatter::FILENAME . "." . $formatter->getExtension(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
} catch(FormValidationException $e) {
|
||||
$errorMessage = $this->createStandardFormValidationErrorMessage($e);
|
||||
} catch(\Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* If has an error, display it
|
||||
*/
|
||||
if (null !== $errorMessage) {
|
||||
$form->setErrorMessage($errorMessage);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($form)
|
||||
->setGeneralError($errorMessage)
|
||||
;
|
||||
}
|
||||
|
||||
return $this->exportView($id);
|
||||
}
|
||||
|
||||
public function importView($id)
|
||||
|
||||
Reference in New Issue
Block a user