From 1b0de7144a401834f2ad5ab9156633120a8ee9d6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 17:20:29 +0200 Subject: [PATCH] end updating module list --- .../Thelia/Command/Skeleton/Module/module.xml | 18 +++++ core/lib/Thelia/Module/BaseModule.php | 2 +- core/lib/Thelia/Module/ModuleManagement.php | 66 ++++++++++++++++++- .../Thelia/Module/schema/module/module.xsd | 2 +- local/modules/Cheque/Config/module.xml | 5 +- local/modules/Colissimo/Config/module.xml | 18 +++++ local/modules/FakeCB/Config/module.xml | 18 +++++ .../modules/TheliaDebugBar/Config/module.xml | 18 +++++ 8 files changed, 143 insertions(+), 4 deletions(-) mode change 100755 => 100644 local/modules/Colissimo/Config/module.xml mode change 100755 => 100644 local/modules/FakeCB/Config/module.xml mode change 100755 => 100644 local/modules/TheliaDebugBar/Config/module.xml diff --git a/core/lib/Thelia/Command/Skeleton/Module/module.xml b/core/lib/Thelia/Command/Skeleton/Module/module.xml index e69de29bb..ae3dbbe53 100755 --- a/core/lib/Thelia/Command/Skeleton/Module/module.xml +++ b/core/lib/Thelia/Command/Skeleton/Module/module.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 8f3ccb2f5..c7979be6e 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -187,7 +187,7 @@ abstract class BaseModule extends ContainerAware $this->reflected = new \ReflectionObject($this); } - return dirname($this->reflected->getFileName()); + return basename(dirname($this->reflected->getFileName())); } abstract public function install(); diff --git a/core/lib/Thelia/Module/ModuleManagement.php b/core/lib/Thelia/Module/ModuleManagement.php index 56563964f..84e6c6457 100644 --- a/core/lib/Thelia/Module/ModuleManagement.php +++ b/core/lib/Thelia/Module/ModuleManagement.php @@ -22,7 +22,15 @@ /*************************************************************************************/ namespace Thelia\Module; + +use Propel\Runtime\Connection\ConnectionInterface; +use Propel\Runtime\Exception\PropelException; +use Propel\Runtime\Propel; use Symfony\Component\Finder\Finder; +use Thelia\Model\Map\ModuleTableMap; +use Thelia\Model\Module; +use Thelia\Model\ModuleI18n; +use Thelia\Model\ModuleQuery; /** @@ -33,6 +41,7 @@ use Symfony\Component\Finder\Finder; class ModuleManagement { protected $baseModuleDir; + protected $reflected; public function __construct() { @@ -50,8 +59,63 @@ class ModuleManagement $descriptorValidator = new ModuleDescriptorValidator(); foreach ($finder as $file) { $content = $descriptorValidator->getDescriptor($file->getRealPath()); - var_dump($content); exit; + $reflected = new \ReflectionClass((string)$content->fullnamespace); + $code = basename(dirname($reflected->getFileName())); + if(null === ModuleQuery::create()->filterByCode($code)->findOne()) { + $module = new Module(); + $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); + $con->beginTransaction(); + try { + $module + ->setCode($code) + ->setFullNamespace((string)$content->fullnamespace) + ->setType($this->getModuleType($reflected)) + ->setActivate(0) + ->save($con); + + $this->saveDescription($module, $content, $con); + + $con->commit(); + } catch(PropelException $e) { + $con->rollBack(); + throw $e; + } + + } } } + private function saveDescription(Module $module,\SimpleXMLElement $content, ConnectionInterface $con) + { + + foreach($content->descriptive as $description) + { + $locale = $description->attributes()->locale; + + $moduleI18n = new ModuleI18n(); + + $moduleI18n + ->setLocale($locale) + ->setModule($module) + ->setTitle($description->title) + ->setDescription(isset($description->description)?$description->description:null) + ->setPostscriptum(isset($description->postscriptum)?$description->postscriptum:null) + ->setChapo(isset($description->subtitle)?$description->subtitle:null) + ->save($con); + } + } + + private function getModuleType(\ReflectionClass $reflected) + { + if($reflected->implementsInterface('Thelia\Module\DeliveryModuleInterface')) { + return BaseModule::DELIVERY_MODULE_TYPE; + } else if($reflected->implementsInterface('Thelia\Module\PaymentModuleInterface')) { + return BaseModule::PAYMENT_MODULE_TYPE; + } else { + return BaseModule::CLASSIC_MODULE_TYPE; + } + + + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Module/schema/module/module.xsd b/core/lib/Thelia/Module/schema/module/module.xsd index bbe2f47d8..bcd7bd292 100644 --- a/core/lib/Thelia/Module/schema/module/module.xsd +++ b/core/lib/Thelia/Module/schema/module/module.xsd @@ -3,7 +3,7 @@ - + The full namespace for the main class module (for example MyModule\MyModule) diff --git a/local/modules/Cheque/Config/module.xml b/local/modules/Cheque/Config/module.xml index d0ef5f619..1df6cf589 100755 --- a/local/modules/Cheque/Config/module.xml +++ b/local/modules/Cheque/Config/module.xml @@ -1,9 +1,12 @@ - Cheque\\Cheque + Cheque\Cheque Cheque + + Cheque + 1.1 Manuel Raynaud diff --git a/local/modules/Colissimo/Config/module.xml b/local/modules/Colissimo/Config/module.xml old mode 100755 new mode 100644 index e69de29bb..1f47ad9c9 --- a/local/modules/Colissimo/Config/module.xml +++ b/local/modules/Colissimo/Config/module.xml @@ -0,0 +1,18 @@ + + + Colissimo\Colissimo + + colisimo + + + colisimo + + 1.0 + + Manuel Raynaud + mraynaud@openstudio.fr + + delivery + 2.0.0 + alpha + diff --git a/local/modules/FakeCB/Config/module.xml b/local/modules/FakeCB/Config/module.xml old mode 100755 new mode 100644 index e69de29bb..0beea57f4 --- a/local/modules/FakeCB/Config/module.xml +++ b/local/modules/FakeCB/Config/module.xml @@ -0,0 +1,18 @@ + + + FakeCB\FakeCB + + fake cb + + + simulation cb + + 1.0 + + Manuel Raynaud + mraynaud@openstudio.fr + + payment + 2.0.0 + alpha + diff --git a/local/modules/TheliaDebugBar/Config/module.xml b/local/modules/TheliaDebugBar/Config/module.xml old mode 100755 new mode 100644 index e69de29bb..61a4c1b0e --- a/local/modules/TheliaDebugBar/Config/module.xml +++ b/local/modules/TheliaDebugBar/Config/module.xml @@ -0,0 +1,18 @@ + + + TheliaDebugBar\TheliaDebugBar + + debugbar for thelia + + + debugbar pour thelia + + 1.0 + + Manuel Raynaud + mraynaud@openstudio.fr + + classic + 2.0.0 + alpha +