From b6c9a7dab421aa28e71ff47c061dea0484b64369 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 18 Jul 2014 13:35:12 +0200 Subject: [PATCH] =?UTF-8?q?Delete=20exports=20and=20imports=20where=20the?= =?UTF-8?q?=20class=20is=20not=20valid=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/Template/Loop/ImportExportType?= =?UTF-8?q?.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thel?= =?UTF-8?q?ia/Model/Export.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Model/Import.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Template/Loop/ImportExportType.php | 24 ++++++++----- core/lib/Thelia/Model/Export.php | 27 ++++++++++++++ core/lib/Thelia/Model/Import.php | 35 ++++++++++++++++++- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php index d1f9a4802..cf1567184 100644 --- a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php @@ -13,6 +13,7 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; +use Propel\Runtime\Exception\ClassNotFoundException; use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; @@ -48,15 +49,20 @@ abstract class ImportExportType extends BaseI18nLoop implements PropelSearchLoop $this->getBaseUrl() . DS . $type->getId() ); - $loopResultRow - ->set("ID", $type->getId()) - ->set("TITLE", $type->getVirtualColumn("i18n_TITLE")) - ->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION")) - ->set("URL", $url) - ->set("POSITION", $type->getPosition()) - ->set("CATEGORY_ID", $type->getByName($this->getCategoryName())) - ->set("HANDLE_CLASS", $type->getHandleClass()) - ; + try { + $loopResultRow + ->set("HANDLE_CLASS", $type->getHandleClass()) + ->set("ID", $type->getId()) + ->set("TITLE", $type->getVirtualColumn("i18n_TITLE")) + ->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION")) + ->set("URL", $url) + ->set("POSITION", $type->getPosition()) + ->set("CATEGORY_ID", $type->getByName($this->getCategoryName())) + ; + } catch(ClassNotFoundException $e) { + + } catch(\ErrorException $e) {} + $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index a0edc92b7..d3e868840 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -3,6 +3,7 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\Connection\ConnectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Core\Translation\Translator; use Thelia\ImportExport\Export\DocumentsExportInterface; @@ -110,6 +111,8 @@ class Export extends BaseExport } if (!class_exists($class)) { + $this->delete(); + throw new \ErrorException( Translator::getInstance()->trans( "The class \"%class\" doesn't exist", @@ -123,6 +126,8 @@ class Export extends BaseExport $instance = new $class($container); if (!$instance instanceof ExportHandler) { + $this->delete(); + throw new \ErrorException( Translator::getInstance()->trans( "The class \"%class\" must extend %baseClass", @@ -137,6 +142,28 @@ class Export extends BaseExport return static::$cache = $instance; } + /** + * @param ConnectionInterface $con + * + * Handle the position of other exports + */ + public function delete(ConnectionInterface $con = null) + { + $imports = ExportQuery::create() + ->filterByPosition($this->getPosition(), Criteria::GREATER_THAN) + ->find() + ; + + foreach ($imports as $import) { + $import->setPosition($import->getPosition() - 1); + } + + $imports->save(); + + parent::delete($con); + } + + public function hasImages(ContainerInterface $container) { if (static::$cache === null) { diff --git a/core/lib/Thelia/Model/Import.php b/core/lib/Thelia/Model/Import.php index 5993e3d34..58b5e0940 100644 --- a/core/lib/Thelia/Model/Import.php +++ b/core/lib/Thelia/Model/Import.php @@ -2,11 +2,17 @@ namespace Thelia\Model; +use Exception; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\Connection\ConnectionInterface; +use Propel\Runtime\Exception\ClassNotFoundException; +use Propel\Runtime\Exception\PropelException; +use Propel\Runtime\Propel; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Core\Translation\Translator; use Thelia\ImportExport\Import\ImportHandler; use Thelia\Model\Base\Import as BaseImport; +use Thelia\Model\ImportQuery as ChildImportQuery; use Thelia\Model\Map\ImportTableMap; class Import extends BaseImport @@ -102,7 +108,9 @@ class Import extends BaseImport $class = $this->getHandleClass(); if (!class_exists($class)) { - throw new \ErrorException( + $this->delete(); + + throw new ClassNotFoundException( Translator::getInstance()->trans( "The class \"%class\" doesn't exist", [ @@ -115,6 +123,8 @@ class Import extends BaseImport $instance = new $class($container); if (!$instance instanceof ImportHandler) { + $this->delete(); + throw new \ErrorException( Translator::getInstance()->trans( "The class \"%class\" must extend %baseClass", @@ -128,4 +138,27 @@ class Import extends BaseImport return $instance; } + + /** + * @param ConnectionInterface $con + * + * Handle the position of other imports + */ + public function delete(ConnectionInterface $con = null) + { + $imports = ImportQuery::create() + ->filterByPosition($this->getPosition(), Criteria::GREATER_THAN) + ->find() + ; + + foreach ($imports as $import) { + $import->setPosition($import->getPosition() - 1); + } + + $imports->save(); + + parent::delete($con); + } + + }