Add accepted formats on import form and add delete not registred exports and imports
modifié: core/lib/Thelia/Config/Resources/export.xml modifié: core/lib/Thelia/Config/Resources/import.xml modifié: core/lib/Thelia/Controller/Admin/ImportExportController.php modifié: core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php modifié: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php modifié: core/lib/Thelia/Core/FileFormat/Formatting/FormatterManager.php modifié: core/lib/Thelia/Model/Export.php modifié: core/lib/Thelia/Model/Import.php modifié: templates/backOffice/default/ajax/import-modal.html modifié: templates/backOffice/default/import-page.html
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
</export_categories>
|
</export_categories>
|
||||||
|
|
||||||
<exports>
|
<exports>
|
||||||
<export id="thelia.export.mailing" category_id="thelia.export.customer" class="Thelia\ImportExport\Export\MailingExport">
|
<export id="thelia.export.mailing" category_id="thelia.export.customer" class="Thelia\ImportExport\Export\Type\MailingExport">
|
||||||
<export_descriptive locale="fr_FR">
|
<export_descriptive locale="fr_FR">
|
||||||
<title>Mailing</title>
|
<title>Mailing</title>
|
||||||
<description>Exporter le nom, prénom et adresse mail des clients inscrits et des abonnées à la newsletter</description>
|
<description>Exporter le nom, prénom et adresse mail des clients inscrits et des abonnées à la newsletter</description>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</import_categories>
|
</import_categories>
|
||||||
|
|
||||||
<imports>
|
<imports>
|
||||||
<import id="thelia.import.stock" class="Thelia\ImportExport\Import\ProductStockImport" category_id="thelia.import.products">
|
<import id="thelia.import.stock" class="Thelia\ImportExport\Import\Type\ProductStockImport" category_id="thelia.import.products">
|
||||||
<import_descriptive locale="fr_FR">
|
<import_descriptive locale="fr_FR">
|
||||||
<title>Importez votre stock</title>
|
<title>Importez votre stock</title>
|
||||||
</import_descriptive>
|
</import_descriptive>
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ class ImportExportController extends BaseAdminController
|
|||||||
* Get needed services
|
* Get needed services
|
||||||
*/
|
*/
|
||||||
$this->hydrate();
|
$this->hydrate();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +111,7 @@ class ImportExportController extends BaseAdminController
|
|||||||
|
|
||||||
$data = $handler->buildFormatterData();
|
$data = $handler->buildFormatterData();
|
||||||
|
|
||||||
|
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
|
||||||
$formatter = $this->formatterManager->get(
|
$formatter = $this->formatterManager->get(
|
||||||
$boundForm->get("formatter")->getData()
|
$boundForm->get("formatter")->getData()
|
||||||
);
|
);
|
||||||
@@ -247,7 +250,18 @@ class ImportExportController extends BaseAdminController
|
|||||||
/**
|
/**
|
||||||
* Inject allowed formats
|
* Inject allowed formats
|
||||||
*/
|
*/
|
||||||
$this->archiveBuilderManager;
|
/** @var \Thelia\ImportExport\AbstractHandler $handler */
|
||||||
|
$this->hydrate();
|
||||||
|
$handler = $import->getHandleClassInstance($this->container);
|
||||||
|
|
||||||
|
$formats =
|
||||||
|
$this->formatterManager->getExtensionsByTypes($handler->getHandledTypes(), true) +
|
||||||
|
$this->archiveBuilderManager->getExtensions(true)
|
||||||
|
;
|
||||||
|
|
||||||
|
$parserContext->set(
|
||||||
|
"ALLOWED_EXTENSIONS", implode(", ", $formats)
|
||||||
|
);
|
||||||
|
|
||||||
/** Then render the form */
|
/** Then render the form */
|
||||||
if ($this->getRequest()->isXmlHttpRequest()) {
|
if ($this->getRequest()->isXmlHttpRequest()) {
|
||||||
@@ -328,4 +342,5 @@ class ImportExportController extends BaseAdminController
|
|||||||
|
|
||||||
return $export;
|
return $export;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\DependencyInjection\Loader;
|
namespace Thelia\Core\DependencyInjection\Loader;
|
||||||
|
|
||||||
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\Propel;
|
use Propel\Runtime\Propel;
|
||||||
use Symfony\Component\Config\Resource\FileResource;
|
use Symfony\Component\Config\Resource\FileResource;
|
||||||
use Symfony\Component\Config\Util\XmlUtils;
|
use Symfony\Component\Config\Util\XmlUtils;
|
||||||
@@ -310,6 +311,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
$con->beginTransaction();
|
$con->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$refs = [];
|
||||||
/** @var SimpleXMLElement $exportCategory */
|
/** @var SimpleXMLElement $exportCategory */
|
||||||
foreach ($exportCategories as $exportCategory) {
|
foreach ($exportCategories as $exportCategory) {
|
||||||
$id = (string) $exportCategory->getAttributeAsPhp("id");
|
$id = (string) $exportCategory->getAttributeAsPhp("id");
|
||||||
@@ -336,8 +338,16 @@ class XmlFileLoader extends FileLoader
|
|||||||
->save($con);
|
->save($con);
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$refs[] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExportCategoryQuery::create()
|
||||||
|
->filterByRef($refs, Criteria::NOT_IN)
|
||||||
|
->find()
|
||||||
|
->delete()
|
||||||
|
;
|
||||||
|
|
||||||
$con->commit();
|
$con->commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$con->rollBack();
|
$con->rollBack();
|
||||||
@@ -356,6 +366,8 @@ class XmlFileLoader extends FileLoader
|
|||||||
$con->beginTransaction();
|
$con->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$refs = [];
|
||||||
|
|
||||||
/** @var SimpleXMLElement $export */
|
/** @var SimpleXMLElement $export */
|
||||||
foreach ($exports as $export) {
|
foreach ($exports as $export) {
|
||||||
$id = (string) $export->getAttributeAsPhp("id");
|
$id = (string) $export->getAttributeAsPhp("id");
|
||||||
@@ -441,8 +453,16 @@ class XmlFileLoader extends FileLoader
|
|||||||
->save($con)
|
->save($con)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$refs[] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExportQuery::create()
|
||||||
|
->filterByRef($refs, Criteria::NOT_IN)
|
||||||
|
->find()
|
||||||
|
->delete()
|
||||||
|
;
|
||||||
|
|
||||||
$con->commit();
|
$con->commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$con->rollBack();
|
$con->rollBack();
|
||||||
@@ -461,6 +481,8 @@ class XmlFileLoader extends FileLoader
|
|||||||
$con->beginTransaction();
|
$con->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$refs = [];
|
||||||
|
|
||||||
/** @var SimpleXMLElement $importCategory */
|
/** @var SimpleXMLElement $importCategory */
|
||||||
foreach ($importCategories as $importCategory) {
|
foreach ($importCategories as $importCategory) {
|
||||||
$id = (string) $importCategory->getAttributeAsPhp("id");
|
$id = (string) $importCategory->getAttributeAsPhp("id");
|
||||||
@@ -487,8 +509,16 @@ class XmlFileLoader extends FileLoader
|
|||||||
->save($con);
|
->save($con);
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$refs[] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImportCategoryQuery::create()
|
||||||
|
->filterByRef($refs, Criteria::NOT_IN)
|
||||||
|
->find()
|
||||||
|
->delete()
|
||||||
|
;
|
||||||
|
|
||||||
$con->commit();
|
$con->commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$con->rollBack();
|
$con->rollBack();
|
||||||
@@ -507,6 +537,8 @@ class XmlFileLoader extends FileLoader
|
|||||||
$con->beginTransaction();
|
$con->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$refs = [];
|
||||||
|
|
||||||
/** @var SimpleXMLElement $import */
|
/** @var SimpleXMLElement $import */
|
||||||
foreach ($imports as $import) {
|
foreach ($imports as $import) {
|
||||||
$id = (string) $import->getAttributeAsPhp("id");
|
$id = (string) $import->getAttributeAsPhp("id");
|
||||||
@@ -592,8 +624,16 @@ class XmlFileLoader extends FileLoader
|
|||||||
->save($con)
|
->save($con)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$refs[] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImportQuery::create()
|
||||||
|
->filterByRef($refs, Criteria::NOT_IN)
|
||||||
|
->find()
|
||||||
|
->delete()
|
||||||
|
;
|
||||||
|
|
||||||
$con->commit();
|
$con->commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$con->rollBack();
|
$con->rollBack();
|
||||||
|
|||||||
@@ -109,13 +109,15 @@ class ArchiveBuilderManager
|
|||||||
*
|
*
|
||||||
* Return the extensions handled by archive builders
|
* Return the extensions handled by archive builders
|
||||||
*/
|
*/
|
||||||
public function getExtensions()
|
public function getExtensions($withDot = false)
|
||||||
{
|
{
|
||||||
$extensions = [];
|
$extensions = [];
|
||||||
|
|
||||||
/** @var AbstractArchiveBuilder $archiveBuilder */
|
/** @var AbstractArchiveBuilder $archiveBuilder */
|
||||||
foreach ($this->archiveBuilders as $archiveBuilder) {
|
foreach ($this->archiveBuilders as $archiveBuilder) {
|
||||||
$extensions += [$archiveBuilder->getName() => $archiveBuilder->getExtension()];
|
$extensionName = $withDot ? ".": "";
|
||||||
|
$extensionName .= $archiveBuilder->getExtension();
|
||||||
|
$extensions += [$archiveBuilder->getName() => $extensionName];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $extensions;
|
return $extensions;
|
||||||
|
|||||||
@@ -105,13 +105,28 @@ class FormatterManager
|
|||||||
*
|
*
|
||||||
* Return the extensions handled by archive builders
|
* Return the extensions handled by archive builders
|
||||||
*/
|
*/
|
||||||
public function getExtensions()
|
public function getExtensions($withDot = false)
|
||||||
{
|
{
|
||||||
$extensions = [];
|
$extensions = [];
|
||||||
|
|
||||||
/** @var AbstractFormatter $formatter */
|
/** @var AbstractFormatter $formatter */
|
||||||
foreach ($this->formatters as $formatter) {
|
foreach ($this->formatters as $formatter) {
|
||||||
$extensions += [$formatter->getName() => $formatter->getExtension()];
|
$extensionName = $withDot ? ".": "";
|
||||||
|
$extensionName .= $formatter->getExtension();
|
||||||
|
$extensions += [$formatter->getName() => $extensionName];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExtensionsByTypes($types, $withDot = false) {
|
||||||
|
$extensions = [];
|
||||||
|
|
||||||
|
/** @var AbstractFormatter $formatter */
|
||||||
|
foreach ($this->getFormattersByTypes($types) as $formatter) {
|
||||||
|
$extensionName = $withDot ? ".": "";
|
||||||
|
$extensionName .= $formatter->getExtension();
|
||||||
|
$extensions += [$formatter->getName() => $extensionName];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $extensions;
|
return $extensions;
|
||||||
@@ -123,6 +138,10 @@ class FormatterManager
|
|||||||
*/
|
*/
|
||||||
public function getFormatterByExtension($extension)
|
public function getFormatterByExtension($extension)
|
||||||
{
|
{
|
||||||
|
if ($extension[0] === ".") {
|
||||||
|
$extension = substr($extension, 1);
|
||||||
|
}
|
||||||
|
|
||||||
$extensions = $this->getExtensions();
|
$extensions = $this->getExtensions();
|
||||||
|
|
||||||
if (!in_array($extension, $extensions)) {
|
if (!in_array($extension, $extensions)) {
|
||||||
|
|||||||
@@ -125,10 +125,10 @@ class Export extends BaseExport
|
|||||||
if (!$instance instanceof ExportHandler) {
|
if (!$instance instanceof ExportHandler) {
|
||||||
throw new \ErrorException(
|
throw new \ErrorException(
|
||||||
Translator::getInstance()->trans(
|
Translator::getInstance()->trans(
|
||||||
"The class \"%class\" must implement %interface",
|
"The class \"%class\" must extend %baseClass",
|
||||||
[
|
[
|
||||||
"%class" => $class,
|
"%class" => $class,
|
||||||
"%interface" => "\\Thelia\\ImportExport\\Export\\ExportHandler",
|
"%baseClass" => "Thelia\\ImportExport\\Export\\ExportHandler",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Thelia\Model;
|
|||||||
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\ImportExport\Import\ImportHandler;
|
use Thelia\ImportExport\Import\ImportHandler;
|
||||||
use Thelia\Model\Base\Import as BaseImport;
|
use Thelia\Model\Base\Import as BaseImport;
|
||||||
use Thelia\Model\Map\ImportTableMap;
|
use Thelia\Model\Map\ImportTableMap;
|
||||||
@@ -97,22 +98,26 @@ class Import extends BaseImport
|
|||||||
|
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
throw new \ErrorException(
|
throw new \ErrorException(
|
||||||
|
Translator::getInstance()->trans(
|
||||||
"The class \"%class\" doesn't exist",
|
"The class \"%class\" doesn't exist",
|
||||||
[
|
[
|
||||||
"%class" => $class
|
"%class" => $class
|
||||||
]
|
]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance = new $class($container);
|
$instance = new $class($container);
|
||||||
|
|
||||||
if (!$class instanceof ImportHandler) {
|
if (!$instance instanceof ImportHandler) {
|
||||||
throw new \ErrorException(
|
throw new \ErrorException(
|
||||||
"The class \"%class\" must implement %interface",
|
Translator::getInstance()->trans(
|
||||||
|
"The class \"%class\" must extend %baseClass",
|
||||||
[
|
[
|
||||||
"%class" => $class,
|
"%class" => $class,
|
||||||
"%interface" => "\\Thelia\\ImportExport\\Import\\ImportHandler",
|
"%baseClass" => "Thelia\\ImportExport\\Import\\ImportHandler",
|
||||||
]
|
]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
{custom_render_form_field form=$form field="file_upload"}
|
{custom_render_form_field form=$form field="file_upload"}
|
||||||
<input type="file" required aria-required="true" name="{$name}" id="{$label_attr.for}" />
|
<input type="file" required aria-required="true" name="{$name}" id="{$label_attr.for}" />
|
||||||
<div class="small">Accepted formats: </div>
|
<div class="small">Accepted formats: {$ALLOWED_EXTENSIONS}</div>
|
||||||
{/custom_render_form_field}
|
{/custom_render_form_field}
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
<form action="{$URL}" method="post" {form_enctype form=$form}>
|
<form action="{$URL}" method="post" {form_enctype form=$form}>
|
||||||
{custom_render_form_field form=$form field="file_upload"}
|
{custom_render_form_field form=$form field="file_upload"}
|
||||||
<input type="file" required aria-required="true" name="{$name}" id="{$label_attr.for}" />
|
<input type="file" required aria-required="true" name="{$name}" id="{$label_attr.for}" />
|
||||||
|
<div class="small">Accepted formats: {$ALLOWED_EXTENSIONS}</div>
|
||||||
{/custom_render_form_field}
|
{/custom_render_form_field}
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary" title="{intl l="Import this file"}">{intl l="Import this file"}</button>
|
<button type="submit" class="btn btn-primary" title="{intl l="Import this file"}">{intl l="Import this file"}</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user