From 4f83c7f07856657c28e65875d85333cdea5c0411 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 15 Oct 2013 11:07:58 +0200 Subject: [PATCH 01/26] display module list --- .../Thelia/Config/Resources/routing/admin.xml | 2 +- .../Controller/Admin/ModuleController.php | 4 + .../admin/default/includes/module-block.html | 53 +++++ templates/admin/default/modules.html | 217 +----------------- 4 files changed, 61 insertions(+), 215 deletions(-) create mode 100644 templates/admin/default/includes/module-block.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 55ee6a90f..d554f0550 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -816,7 +816,7 @@ - + Thelia\Controller\Admin\ModuleController::indexAction diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 03691c069..d2b96ce2e 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -33,6 +33,10 @@ class ModuleController extends BaseAdminController public function indexAction() { if (null !== $response = $this->checkAuth("admin.module.view")) return $response; + + + + return $this->render("modules", array("display_module" => 20)); } diff --git a/templates/admin/default/includes/module-block.html b/templates/admin/default/includes/module-block.html new file mode 100644 index 000000000..7784c84db --- /dev/null +++ b/templates/admin/default/includes/module-block.html @@ -0,0 +1,53 @@ +
+
+ + + + + + + + + {module_include location='modules_table_header'} + + + + + + + {loop type="module" name="module.{$module_type}" module_type={$module_type|default:1} backend_context=1} + + + + + + {module_include location='modules_table_row'} + + + + {/loop} + +
+ {$caption_title|default:{intl l='classic modules'}} +
{intl l="Name"}{intl l="Description"}{intl l="Enable/Disable"}{intl l="Actions"}
{$TITLE}{$CHAPO} +
+ +
+
+
+ + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} + + {/loop} + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} + + {/loop} + + {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} + + {/loop} +
+
+
+
\ No newline at end of file diff --git a/templates/admin/default/modules.html b/templates/admin/default/modules.html index 8c86c349a..06d7420bd 100644 --- a/templates/admin/default/modules.html +++ b/templates/admin/default/modules.html @@ -25,221 +25,10 @@
-
-
- - - - - - - + {include file="includes/module-block.html" module_type="1" caption_title={intl l='Classic modules'}} + {include file="includes/module-block.html" module_type="2" caption_title={intl l='Delivery modules'}} + {include file="includes/module-block.html" module_type="3" caption_title={intl l='Payment modules'}} - {module_include location='modules_table_header'} - - - - - - - - - - - - {module_include location='modules_table_row'} - - - - - - - - - {module_include location='modules_table_row'} - - - - - - - - - {module_include location='modules_table_row'} - - - - -
- {intl l='Transport modules'} -
{intl l="Name"}{intl l="Description"}{intl l="Enable/Disable"}{intl l="Actions"}
TinymceEos minima maiores doloribus mollitia perspiciatis esse iusto odit error delectus aliquid! Eius, pariatur accusantium odit quidem laboriosam. -
- -
-
-
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - - {/loop} -
-
So colissimoEos minima maiores doloribus mollitia perspiciatis esse iusto odit error delectus aliquid -
- -
-
-
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - - {/loop} -
-
Title metaEos minima maiores doloribus mollitia perspiciatis esse iusto odit error delectus aliquid -
- -
-
-
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - - {/loop} -
-
-
-
- -
-
- - - - - - - - - {module_include location='modules_table_header'} - - - - - - - - - - - - {module_include location='modules_table_row'} - - - - - - - - - {module_include location='modules_table_row'} - - - - - - - - - {module_include location='modules_table_row'} - - - - -
- {intl l='Delivery modules'} -
{intl l="Name"}{intl l="Description"}{intl l="Enable/Disable"}{intl l="Actions"}
TinymceEos minima maiores doloribus mollitia perspiciatis esse iusto odit error delectus aliquid! Eius, pariatur accusantium odit quidem laboriosam. -
- -
-
-
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - - {/loop} -
-
So colissimoEos minima maiores doloribus mollitia perspiciatis esse iusto odit error delectus aliquid -
- -
-
-
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - - {/loop} -
-
Title metaEos minima maiores doloribus mollitia perspiciatis esse iusto odit error delectus aliquid -
- -
-
-
- - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.documentation"} - - {/loop} - - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.modules.edit"} - - {/loop} - - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - - {/loop} -
-
-
-
From 84ad1e6f954266ffb9fe39f3a809032406ee44ef Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 16 Oct 2013 17:39:32 +0200 Subject: [PATCH 02/26] start creating xsd module management --- composer.json | 3 +- composer.lock | 4 +- .../Controller/Admin/ModuleController.php | 4 +- core/lib/Thelia/Module/BaseModule.php | 2 +- core/lib/Thelia/Module/ModuleManagement.php | 55 +++++++++ core/lib/Thelia/Module/schema/module-1.0.xsd | 108 ++++++++++++++++++ 6 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Module/ModuleManagement.php create mode 100644 core/lib/Thelia/Module/schema/module-1.0.xsd diff --git a/composer.json b/composer.json index 0a4fc0629..e96385edd 100755 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "symfony/icu": "1.0", "swiftmailer/swiftmailer": "5.0.*", "symfony/serializer": "2.3.*", - "ensepar/html2pdf": "1.0.1" + "ensepar/html2pdf": "1.0.1", + "symfony/finder": "~2.2" }, "require-dev" : { "phpunit/phpunit": "3.7.*", diff --git a/composer.lock b/composer.lock index f50fb4a4d..a6f05615a 100755 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "852879ecc2e39e5cf283a3b1c5051a8e", + "hash": "4f3fabbb795a71df45ae9f6ccb6df355", "packages": [ { "name": "ensepar/html2pdf", @@ -949,7 +949,7 @@ }, { "name": "symfony/finder", - "version": "v2.3.5", + "version": "v2.3.6", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index d2b96ce2e..1f0411987 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Module\ModuleManagement; /** * Class ModuleController @@ -35,7 +36,8 @@ class ModuleController extends BaseAdminController if (null !== $response = $this->checkAuth("admin.module.view")) return $response; - + $modulemanagement = new ModuleManagement(); + $modulemanagement->updateModules(); return $this->render("modules", array("display_module" => 20)); } diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 37c40c953..4f18b02a8 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -72,7 +72,7 @@ abstract class BaseModule extends ContainerAware public function getContainer() { if ($this->hasContainer() === false) { - throw new \RuntimeException("Sorry, container his not available in this context"); + throw new \RuntimeException("Sorry, container is not available in this context"); } return $this->container; diff --git a/core/lib/Thelia/Module/ModuleManagement.php b/core/lib/Thelia/Module/ModuleManagement.php new file mode 100644 index 000000000..754a60998 --- /dev/null +++ b/core/lib/Thelia/Module/ModuleManagement.php @@ -0,0 +1,55 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Module; +use Symfony\Component\Finder\Finder; + + +/** + * Class ModuleManagement + * @package Thelia\Module + * @author Manuel Raynaud + */ +class ModuleManagement +{ + protected $baseModuleDir; + + public function __construct() + { + $this->baseModuleDir = THELIA_MODULE_DIR; + } + + public function updateModules() + { + $finder = new Finder(); + + $finder + ->name('config.xml') + ->in($this->baseModuleDir . '/*/Config'); + + foreach ($finder as $file) { + echo $file->getRealPath()."\n"; + } + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Module/schema/module-1.0.xsd b/core/lib/Thelia/Module/schema/module-1.0.xsd new file mode 100644 index 000000000..2a6d29371 --- /dev/null +++ b/core/lib/Thelia/Module/schema/module-1.0.xsd @@ -0,0 +1,108 @@ + + + + + + + + le descriptif complet, dans autant de langues que nécessaire. + Le code de la langue doit être un code pays ISO 639 + + + + + + + + + + + + + + La version du plugin. Format libre + + + + + Auteur du plugin + + + + + + + + + + + + + Le type du plugin: classique, transport, paiement, filtre, taxe + + + + + + + + + + + + + + Les plugins qui doivent déjà être présents + + + + + + + + + + + + + + + + + + La version minimum requise de Thelia, au format 'dot' (1.2.3.4 par exemple) + + + + + + + + + + Le statut actuel du plugin: alpha, beta, rc, production + + + + + + + + + + + + + + Le nom du fichier contenant la documentation. Ce fichier doit se trouver dans le répertoire du plugin. + + + + + L'URL a interroger pour vérifier la présence d'une nouvelle version, appellé avec le nom du plugin et sa version + + + + + + \ No newline at end of file From c9dbb610c1a0eede78437b612f6655e33fc2549a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 11:32:29 +0200 Subject: [PATCH 03/26] start validating module.xml file --- .../Thelia/Command/ModuleGenerateCommand.php | 4 +- .../Module/{plugin.xml => module.xml} | 0 .../Thelia/Module/Loader/XmlFileLoader.php | 71 +++++++++++++++++++ .../schema/module}/module-1.0.xsd | 42 +++++------ core/lib/Thelia/Module/ModuleManagement.php | 2 +- local/modules/Cheque/Config/module.xml | 24 +++++++ .../Config/module.xml} | 0 .../plugin.xml => FakeCB/Config/module.xml} | 0 .../Config/module.xml} | 0 .../modules/TheliaDebugBar/Config/plugin.xml | 0 10 files changed, 120 insertions(+), 23 deletions(-) rename core/lib/Thelia/Command/Skeleton/Module/{plugin.xml => module.xml} (100%) create mode 100644 core/lib/Thelia/Module/Loader/XmlFileLoader.php rename core/lib/Thelia/Module/{schema => Loader/schema/module}/module-1.0.xsd (74%) create mode 100755 local/modules/Cheque/Config/module.xml rename local/modules/{Cheque/Config/plugin.xml => Colissimo/Config/module.xml} (100%) rename local/modules/{Colissimo/Config/plugin.xml => FakeCB/Config/module.xml} (100%) rename local/modules/{FakeCB/Config/plugin.xml => TheliaDebugBar/Config/module.xml} (100%) delete mode 100755 local/modules/TheliaDebugBar/Config/plugin.xml diff --git a/core/lib/Thelia/Command/ModuleGenerateCommand.php b/core/lib/Thelia/Command/ModuleGenerateCommand.php index b34e43dc1..dfc13f29d 100755 --- a/core/lib/Thelia/Command/ModuleGenerateCommand.php +++ b/core/lib/Thelia/Command/ModuleGenerateCommand.php @@ -62,7 +62,7 @@ class ModuleGenerateCommand extends BaseModuleGenerate $output->renderBlock(array( '', sprintf("module %s create with success", $this->module), - "You can now configure your module and complete plugin.xml file", + "You can now configure your module and complete module.xml file", '' ), "bg=green;fg=black"); } @@ -86,7 +86,7 @@ class ModuleGenerateCommand extends BaseModuleGenerate $fs = new Filesystem(); $skeletonDir = str_replace("/", DIRECTORY_SEPARATOR, THELIA_ROOT . "/core/lib/Thelia/Command/Skeleton/Module/"); $fs->copy($skeletonDir . "config.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.xml"); - $fs->copy($skeletonDir . "plugin.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "plugin.xml"); + $fs->copy($skeletonDir . "module.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "module.xml"); $classContent = file_get_contents($skeletonDir . "Class.php"); diff --git a/core/lib/Thelia/Command/Skeleton/Module/plugin.xml b/core/lib/Thelia/Command/Skeleton/Module/module.xml similarity index 100% rename from core/lib/Thelia/Command/Skeleton/Module/plugin.xml rename to core/lib/Thelia/Command/Skeleton/Module/module.xml diff --git a/core/lib/Thelia/Module/Loader/XmlFileLoader.php b/core/lib/Thelia/Module/Loader/XmlFileLoader.php new file mode 100644 index 000000000..dca9129cf --- /dev/null +++ b/core/lib/Thelia/Module/Loader/XmlFileLoader.php @@ -0,0 +1,71 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Module\Loader; +use Symfony\Component\Config\Loader\FileLoader; +use Symfony\Component\Config\Util\XmlUtils; + + +/** + * Class XmlFileLoader + * @package Thelia\Module\Loader + * @author Manuel Raynaud + */ +class XmlFileLoader extends FileLoader +{ + + /** + * Loads a resource. + * + * @param mixed $resource The resource + * @param string $type The resource type + */ + public function load($resource, $type = null) + { + $path = $this->locator->locate($resource); + + $xml = $this->parseFile($path); + } + + protected function parseFile($file) + { + $schema = str_replace('\\', '/',__DIR__.'/schema/module-1.0.xsd'); + + $dom = XmlUtils::loadFile($file, $schema); + + return simplexml_import_dom($dom); + } + + /** + * Returns true if this class supports the given resource. + * + * @param mixed $resource A resource + * @param string $type The resource type + * + * @return Boolean true if this class supports the given resource, false otherwise + */ + public function supports($resource, $type = null) + { + // TODO: Implement supports() method. + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Module/schema/module-1.0.xsd b/core/lib/Thelia/Module/Loader/schema/module/module-1.0.xsd similarity index 74% rename from core/lib/Thelia/Module/schema/module-1.0.xsd rename to core/lib/Thelia/Module/Loader/schema/module/module-1.0.xsd index 2a6d29371..c394a8f26 100644 --- a/core/lib/Thelia/Module/schema/module-1.0.xsd +++ b/core/lib/Thelia/Module/Loader/schema/module/module-1.0.xsd @@ -1,12 +1,16 @@ - + - + - le descriptif complet, dans autant de langues que nécessaire. - Le code de la langue doit être un code pays ISO 639 + The full namespace for the main class module (for example MyModule\MyModule) + + + + + complete description, each description must be identify by ISO CODE 639 @@ -20,33 +24,31 @@ - La version du plugin. Format libre + Module version - Auteur du plugin + Module author - - + + - + - Le type du plugin: classique, transport, paiement, filtre, taxe + module type : classic, delivery, payment - - - - - + + + @@ -70,7 +72,7 @@ - La version minimum requise de Thelia, au format 'dot' (1.2.3.4 par exemple) + minimum required version of Thelia in 'dot' format (for example 1.2.3.4) @@ -78,17 +80,17 @@ - + - Le statut actuel du plugin: alpha, beta, rc, production + current module stability: alpha, beta, rc, prod - - + + diff --git a/core/lib/Thelia/Module/ModuleManagement.php b/core/lib/Thelia/Module/ModuleManagement.php index 754a60998..643f2a9d1 100644 --- a/core/lib/Thelia/Module/ModuleManagement.php +++ b/core/lib/Thelia/Module/ModuleManagement.php @@ -44,7 +44,7 @@ class ModuleManagement $finder = new Finder(); $finder - ->name('config.xml') + ->name('module.xml') ->in($this->baseModuleDir . '/*/Config'); foreach ($finder as $file) { diff --git a/local/modules/Cheque/Config/module.xml b/local/modules/Cheque/Config/module.xml new file mode 100755 index 000000000..1ef4340ff --- /dev/null +++ b/local/modules/Cheque/Config/module.xml @@ -0,0 +1,24 @@ + + + + Produits factices + + Insertion des produits dans votre site Thelia permettant d'avoir un Thelia de test vite opérationnel. + + + 1.1 + + Manuel Raynaud - mraynaud@openstudio.fr + + + + + classique + + 1.5.0 + production + README.TXT + + diff --git a/local/modules/Cheque/Config/plugin.xml b/local/modules/Colissimo/Config/module.xml similarity index 100% rename from local/modules/Cheque/Config/plugin.xml rename to local/modules/Colissimo/Config/module.xml diff --git a/local/modules/Colissimo/Config/plugin.xml b/local/modules/FakeCB/Config/module.xml similarity index 100% rename from local/modules/Colissimo/Config/plugin.xml rename to local/modules/FakeCB/Config/module.xml diff --git a/local/modules/FakeCB/Config/plugin.xml b/local/modules/TheliaDebugBar/Config/module.xml similarity index 100% rename from local/modules/FakeCB/Config/plugin.xml rename to local/modules/TheliaDebugBar/Config/module.xml diff --git a/local/modules/TheliaDebugBar/Config/plugin.xml b/local/modules/TheliaDebugBar/Config/plugin.xml deleted file mode 100755 index e69de29bb..000000000 From a9d5554b7caf16f50579c991db242e1cdb4e27aa Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 15:06:13 +0200 Subject: [PATCH 04/26] create method for validating module file descriptor --- .../Exception/InvalidXmlDocumentException.php | 35 +++++++++++++ ...ader.php => ModuleDescriptorValidator.php} | 51 ++++++++----------- .../module/module.xsd} | 0 local/modules/Cheque/Config/module.xml | 29 ++++------- 4 files changed, 66 insertions(+), 49 deletions(-) create mode 100644 core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php rename core/lib/Thelia/Module/{Loader/XmlFileLoader.php => ModuleDescriptorValidator.php} (64%) rename core/lib/Thelia/Module/{Loader/schema/module/module-1.0.xsd => schema/module/module.xsd} (100%) diff --git a/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php b/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php new file mode 100644 index 000000000..2d679cfd0 --- /dev/null +++ b/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Module\Exception; + + +/** + * Class InvalidXmlDocumentException + * @package Thelia\Module\Exception + * @author Manuel Raynaud + */ +class InvalidXmlDocumentException extends \RuntimeException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Module/Loader/XmlFileLoader.php b/core/lib/Thelia/Module/ModuleDescriptorValidator.php similarity index 64% rename from core/lib/Thelia/Module/Loader/XmlFileLoader.php rename to core/lib/Thelia/Module/ModuleDescriptorValidator.php index dca9129cf..679373e02 100644 --- a/core/lib/Thelia/Module/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Module/ModuleDescriptorValidator.php @@ -21,51 +21,40 @@ /* */ /*************************************************************************************/ -namespace Thelia\Module\Loader; -use Symfony\Component\Config\Loader\FileLoader; -use Symfony\Component\Config\Util\XmlUtils; +namespace Thelia\Module; +use Thelia\Module\Exception\InvalidXmlDocumentException; /** - * Class XmlFileLoader - * @package Thelia\Module\Loader + * Class ModuleDescriptorValidator + * @package Thelia\Module * @author Manuel Raynaud */ -class XmlFileLoader extends FileLoader +class ModuleDescriptorValidator { + private $xsd_file; - /** - * Loads a resource. - * - * @param mixed $resource The resource - * @param string $type The resource type - */ - public function load($resource, $type = null) + public function __construct() { - $path = $this->locator->locate($resource); - - $xml = $this->parseFile($path); + $this->xsd_file = __DIR__ . '/schema/module/module.xsd'; } - protected function parseFile($file) + public function validate($xml_file) { - $schema = str_replace('\\', '/',__DIR__.'/schema/module-1.0.xsd'); + $dom = new \DOMDocument(); - $dom = XmlUtils::loadFile($file, $schema); + if ($dom->load($xml_file)) { + if($dom->schemaValidate($this->xsd_file)) { + return true; + } + } - return simplexml_import_dom($dom); + throw new InvalidXmlDocumentException(sprintf("%s file is not a valid file", $xml_file)); } - /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return Boolean true if this class supports the given resource, false otherwise - */ - public function supports($resource, $type = null) - { - // TODO: Implement supports() method. + public function getDescriptor($xml_file) { + $this->validate($xml_file); + + return @simplexml_load_file($xml_file); } } \ No newline at end of file diff --git a/core/lib/Thelia/Module/Loader/schema/module/module-1.0.xsd b/core/lib/Thelia/Module/schema/module/module.xsd similarity index 100% rename from core/lib/Thelia/Module/Loader/schema/module/module-1.0.xsd rename to core/lib/Thelia/Module/schema/module/module.xsd diff --git a/local/modules/Cheque/Config/module.xml b/local/modules/Cheque/Config/module.xml index 1ef4340ff..5d2e70301 100755 --- a/local/modules/Cheque/Config/module.xml +++ b/local/modules/Cheque/Config/module.xml @@ -2,23 +2,16 @@ - - Produits factices - - Insertion des produits dans votre site Thelia permettant d'avoir un Thelia de test vite opérationnel. - - + + Cheque + + Cheque\\Cheque 1.1 - - Manuel Raynaud - mraynaud@openstudio.fr - - - - - classique - - 1.5.0 - production - README.TXT - + + Manuel Raynaud + mraynaud@openstudio.fr + + payment + 2.0.0 + alpha From 1b865d71a3cc51012d5c12623bdb1146827813d5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 15:36:11 +0200 Subject: [PATCH 05/26] crowl all module descriptor file for discovering new modules --- core/lib/Thelia/Module/BaseModule.php | 13 ++++++++++++- core/lib/Thelia/Module/ModuleManagement.php | 4 +++- core/lib/Thelia/Module/schema/module/module.xsd | 2 +- local/modules/Cheque/Config/module.xml | 6 ++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 4f18b02a8..8f3ccb2f5 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -43,6 +43,8 @@ abstract class BaseModule extends ContainerAware const IS_ACTIVATED = 1; const IS_NOT_ACTIVATED = 0; + protected $reflected; + public function __construct() { @@ -178,7 +180,16 @@ abstract class BaseModule extends ContainerAware return $moduleModel; } - abstract public function getCode(); + + public function getCode() + { + if (null === $this->reflected) { + $this->reflected = new \ReflectionObject($this); + } + + return dirname($this->reflected->getFileName()); + } + abstract public function install(); abstract public function afterActivation(); abstract public function destroy(); diff --git a/core/lib/Thelia/Module/ModuleManagement.php b/core/lib/Thelia/Module/ModuleManagement.php index 643f2a9d1..56563964f 100644 --- a/core/lib/Thelia/Module/ModuleManagement.php +++ b/core/lib/Thelia/Module/ModuleManagement.php @@ -47,8 +47,10 @@ class ModuleManagement ->name('module.xml') ->in($this->baseModuleDir . '/*/Config'); + $descriptorValidator = new ModuleDescriptorValidator(); foreach ($finder as $file) { - echo $file->getRealPath()."\n"; + $content = $descriptorValidator->getDescriptor($file->getRealPath()); + var_dump($content); exit; } } diff --git a/core/lib/Thelia/Module/schema/module/module.xsd b/core/lib/Thelia/Module/schema/module/module.xsd index c394a8f26..bbe2f47d8 100644 --- a/core/lib/Thelia/Module/schema/module/module.xsd +++ b/core/lib/Thelia/Module/schema/module/module.xsd @@ -27,7 +27,7 @@ Module version - + Module author diff --git a/local/modules/Cheque/Config/module.xml b/local/modules/Cheque/Config/module.xml index 5d2e70301..d0ef5f619 100755 --- a/local/modules/Cheque/Config/module.xml +++ b/local/modules/Cheque/Config/module.xml @@ -1,11 +1,9 @@ - + + Cheque\\Cheque Cheque - Cheque\\Cheque 1.1 Manuel Raynaud From 1b0de7144a401834f2ad5ab9156633120a8ee9d6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 17:20:29 +0200 Subject: [PATCH 06/26] 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 + From d25ad53d5a4fcd6da636d8e02b485d5db84cffd7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 18:26:23 +0200 Subject: [PATCH 07/26] create module event and eventListener --- core/lib/Thelia/Action/Module.php | 69 +++++++++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 5 ++ .../Thelia/Config/Resources/routing/admin.xml | 5 ++ .../Controller/Admin/ModuleController.php | 30 +++++++- core/lib/Thelia/Controller/BaseController.php | 6 +- .../Thelia/Core/Event/Module/ModuleEvent.php | 69 +++++++++++++++++++ .../Module/ModuleToggleActivationEvent.php | 67 ++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 2 + .../admin/default/includes/module-block.html | 9 ++- 9 files changed, 256 insertions(+), 6 deletions(-) create mode 100644 core/lib/Thelia/Action/Module.php create mode 100644 core/lib/Thelia/Core/Event/Module/ModuleEvent.php create mode 100644 core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php new file mode 100644 index 000000000..91a51c3af --- /dev/null +++ b/core/lib/Thelia/Action/Module.php @@ -0,0 +1,69 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Module\ModuleToggleActivationEvent; +use Thelia\Core\Event\TheliaEvents; + + +/** + * Class Module + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Module extends BaseAction implements EventSubscriberInterface +{ + + public function toggleActivation(ModuleToggleActivationEvent $event) + { + + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::MODULE_TOGGLE_ACTIVATION => array('toggleActivation', 128) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index b3bc085bf..8b4cfe783 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -136,6 +136,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index d554f0550..a3a350365 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -820,6 +820,11 @@ Thelia\Controller\Admin\ModuleController::indexAction
+ + Thelia\Controller\Admin\ModuleController::toggleActivationAction + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 1f0411987..66bd11e49 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -22,6 +22,9 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; + +use Thelia\Core\Event\Module\ModuleToggleActivationEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Module\ModuleManagement; /** @@ -35,11 +38,10 @@ class ModuleController extends BaseAdminController { if (null !== $response = $this->checkAuth("admin.module.view")) return $response; - $modulemanagement = new ModuleManagement(); $modulemanagement->updateModules(); - return $this->render("modules", array("display_module" => 20)); + return $this->render("modules"); } public function updateAction($module_id) @@ -48,4 +50,28 @@ class ModuleController extends BaseAdminController "module_id" => $module_id )); } + + public function toggleActivationAction($module_id) + { + if (null !== $response = $this->checkAuth("admin.module.update")) return $response; + $message = null; + try { + $event = new ModuleToggleActivationEvent($module_id); + $this->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $event); + } catch (\Exception $e) { + $message = $e->getMessage(); + } + + + if($this->getRequest()->isXmlHttpRequest()) { + if($message) { + $response = $this->nullResponse($message, 500); + } + $response = $this->nullResponse(); + } else { + $response = $this->render("modules"); + } + + return $response; + } } diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 8c819159b..e9f359411 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -58,7 +58,7 @@ class BaseController extends ContainerAware /** * Return an empty response (after an ajax request, for example) */ - protected function nullResponse($status = 200) + protected function nullResponse($content = null, $status = 200) { return new Response(null, $status); } @@ -66,9 +66,9 @@ class BaseController extends ContainerAware /** * Return a JSON response */ - protected function jsonResponse($json_data) + protected function jsonResponse($json_data, $status = 200) { - return new Response($json_data, 200, array('content-type' => 'application/json')); + return new Response($json_data, $status, array('content-type' => 'application/json')); } /** diff --git a/core/lib/Thelia/Core/Event/Module/ModuleEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php new file mode 100644 index 000000000..e9cf2623e --- /dev/null +++ b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php @@ -0,0 +1,69 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Module; +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Module; + + +/** + * Class ModuleEvent + * @package Thelia\Core\Event\Module + * @author Manuel Raynaud + */ +class ModuleEvent extends ActionEvent +{ + /** + * @var \Thelia\Model\Module + */ + protected $module; + + function __construct(Module $module = null) + { + $this->module = $module; + } + + /** + * @param \Thelia\Model\Module $module + * + * @return $this + */ + public function setModule(Module $module) + { + $this->module = $module; + + return $this; + } + + /** + * @return \Thelia\Model\Module + */ + public function getModule() + { + return $this->module; + } + + + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php new file mode 100644 index 000000000..dd517d8ff --- /dev/null +++ b/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Module; + + +/** + * Class ModuleToggleActivationEvent + * @package Thelia\Core\Event\Module + * @author Manuel Raynaud + */ +class ModuleToggleActivationEvent extends ModuleEvent +{ + /** + * @var int + */ + protected $module_id; + + function __construct($module_id) + { + $this->module_id = $module_id; + } + + /** + * @param int $module_id + * + * @return $this + */ + public function setModuleId($module_id) + { + $this->module_id = $module_id; + + return $this; + } + + /** + * @return int + */ + public function getModuleId() + { + return $this->module_id; + } + + + + +} \ 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 aa365e54a..78e96bf97 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -657,4 +657,6 @@ final class TheliaEvents const GENERATE_PDF = 'thelia.generatePdf'; + const MODULE_TOGGLE_ACTIVATION = 'thelia.module.toggleActivation'; + } diff --git a/templates/admin/default/includes/module-block.html b/templates/admin/default/includes/module-block.html index 7784c84db..2b45f5bc3 100644 --- a/templates/admin/default/includes/module-block.html +++ b/templates/admin/default/includes/module-block.html @@ -22,9 +22,16 @@ {$TITLE} {$CHAPO} -
+
+ {module_include location='modules_table_row'} From 6d791f5bf7e8e80d578e52f3a99d21218d9f30b3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 17 Oct 2013 18:50:00 +0200 Subject: [PATCH 08/26] process module toggle activation --- core/lib/Thelia/Action/Module.php | 19 +++++ .../Controller/Admin/ModuleController.php | 7 +- core/lib/Thelia/Module/BaseModule.php | 80 ++++++++++++++++--- local/modules/Cheque/Cheque.php | 11 +-- local/modules/Colissimo/Colissimo.php | 19 ----- local/modules/FakeCB/FakeCB.php | 11 +-- .../modules/TheliaDebugBar/TheliaDebugBar.php | 15 ---- 7 files changed, 99 insertions(+), 63 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 91a51c3af..18fdb85cb 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -25,6 +25,8 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Module\ModuleToggleActivationEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\ModuleQuery; +use Thelia\Module\BaseModule; /** @@ -37,7 +39,24 @@ class Module extends BaseAction implements EventSubscriberInterface public function toggleActivation(ModuleToggleActivationEvent $event) { + if (null !== $module = ModuleQuery::create()->findPk($event->getModuleId())) { + $moduleClass = new \ReflectionClass($module->getFullNamespace()); + $moduleInstance = $moduleClass->newInstance(); + + if( method_exists($moduleInstance, 'setContainer')) { + $moduleInstance->setContainer($this->container); + if($module->getActivate() == BaseModule::IS_ACTIVATED) { + $moduleInstance->deActivate($module); + } else { + $moduleInstance->activate($module); + } + } + + if($module->isModified()) { + $event->setModule($module); + } + } } /** diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 66bd11e49..ec7ff472f 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -58,6 +58,11 @@ class ModuleController extends BaseAdminController try { $event = new ModuleToggleActivationEvent($module_id); $this->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $event); + + if(null === $event->getModule()) { + throw new \LogicException( + $this->getTranslator()->trans("No %obj was updated.", array('%obj' => 'Module'))); + } } catch (\Exception $e) { $message = $e->getMessage(); } @@ -69,7 +74,7 @@ class ModuleController extends BaseAdminController } $response = $this->nullResponse(); } else { - $response = $this->render("modules"); + $this->redirectToRoute('admin.module'); } return $response; diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index c7979be6e..6cfc79d28 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -24,7 +24,10 @@ namespace Thelia\Module; +use Propel\Runtime\Connection\ConnectionInterface; +use Propel\Runtime\Propel; use Symfony\Component\DependencyInjection\ContainerAware; +use Thelia\Model\Map\ModuleTableMap; use Thelia\Model\ModuleI18nQuery; use Thelia\Model\Map\ModuleImageTableMap; use Thelia\Model\ModuleI18n; @@ -50,22 +53,54 @@ abstract class BaseModule extends ContainerAware } - public function activate() + + public function activate($moduleModel = null) { - $moduleModel = $this->getModuleModel(); + if(null === $moduleModel) { + $moduleModel = $this->getModuleModel(); + } + if ($moduleModel->getActivate() == self::IS_NOT_ACTIVATED) { - $moduleModel->setActivate(self::IS_ACTIVATED); - $moduleModel->save(); + $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); + $con->beginTransaction(); try { - $this->afterActivation(); + if($this->preActivation($con)) { + $moduleModel->setActivate(self::IS_ACTIVATED); + $moduleModel->save($con); + $this->postActivation($con); + $con->commit(); + } } catch (\Exception $e) { - $moduleModel->setActivate(self::IS_NOT_ACTIVATED); - $moduleModel->save(); + $con->rollBack(); throw $e; } } } + public function deActivate($moduleModel = null) + { + if(null === $moduleModel) { + $moduleModel = $this->getModuleModel(); + } + if ($moduleModel->getActivate() == self::IS_ACTIVATED) { + $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); + $con->beginTransaction(); + try { + if($this->preDeactivation($con)) { + $moduleModel->setActivate(self::IS_NOT_ACTIVATED); + $moduleModel->save($con); + $this->postDeactivation($con); + + $con->commit(); + } + } catch (\Exception $e) { + $con->rollBack(); + throw $e; + } + + } + } + public function hasContainer() { return null === $this->container; @@ -190,8 +225,33 @@ abstract class BaseModule extends ContainerAware return basename(dirname($this->reflected->getFileName())); } - abstract public function install(); - abstract public function afterActivation(); - abstract public function destroy(); + public function install(){ + + } + + public function preActivation(ConnectionInterface $con = null) + { + return true; + } + + public function postActivation(ConnectionInterface $con = null) + { + + } + + public function preDeactivation(ConnectionInterface $con = null) + { + return true; + } + + public function postDeactivation(ConnectionInterface $con = null) + { + + } + + public function destroy() + { + + } } diff --git a/local/modules/Cheque/Cheque.php b/local/modules/Cheque/Cheque.php index 4516c84f3..324728990 100755 --- a/local/modules/Cheque/Cheque.php +++ b/local/modules/Cheque/Cheque.php @@ -23,6 +23,7 @@ namespace Cheque; +use Propel\Runtime\Connection\ConnectionInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Thelia\Model\ModuleImageQuery; @@ -59,12 +60,8 @@ class Cheque extends BaseModule implements PaymentModuleInterface // no special process, waiting for the cheque. } - public function install() - { - } - - public function afterActivation() + public function postActivation(ConnectionInterface $con = null) { /* insert the images from image folder if first module activation */ $module = $this->getModuleModel(); @@ -82,10 +79,6 @@ class Cheque extends BaseModule implements PaymentModuleInterface ); } - public function destroy() - { - // TODO: Implement destroy() method. - } public function getCode() { diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php index 7ff972feb..adbbb32c3 100755 --- a/local/modules/Colissimo/Colissimo.php +++ b/local/modules/Colissimo/Colissimo.php @@ -67,25 +67,6 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface return 2; } - public function afterActivation() - { - - } - - /** - * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class - * Like install and destroy - */ - public function install() - { - // TODO: Implement install() method. - } - - public function destroy() - { - // TODO: Implement destroy() method. - } - public function getCode() { return 'Colissimo'; diff --git a/local/modules/FakeCB/FakeCB.php b/local/modules/FakeCB/FakeCB.php index ca682fab3..58c8318da 100755 --- a/local/modules/FakeCB/FakeCB.php +++ b/local/modules/FakeCB/FakeCB.php @@ -23,6 +23,7 @@ namespace FakeCB; +use Propel\Runtime\Connection\ConnectionInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Thelia\Model\Base\ModuleImageQuery; @@ -59,12 +60,8 @@ class FakeCB extends BaseModule implements PaymentModuleInterface // TODO: Implement pay() method. } - public function install() - { - } - - public function afterActivation() + public function postActivation(ConnectionInterface $con = null) { /* insert the images from image folder if first module activation */ $module = $this->getModuleModel(); @@ -82,10 +79,6 @@ class FakeCB extends BaseModule implements PaymentModuleInterface ); } - public function destroy() - { - // TODO: Implement destroy() method. - } public function getCode() { diff --git a/local/modules/TheliaDebugBar/TheliaDebugBar.php b/local/modules/TheliaDebugBar/TheliaDebugBar.php index da9fddf12..466f50d5a 100755 --- a/local/modules/TheliaDebugBar/TheliaDebugBar.php +++ b/local/modules/TheliaDebugBar/TheliaDebugBar.php @@ -32,21 +32,6 @@ class TheliaDebugBar extends BaseModule * Like install and destroy */ - public function afterActivation() - { - - } - - public function install() - { - // TODO: Implement install() method. - } - - public function destroy() - { - // TODO: Implement destroy() method. - } - public function getCode() { return 'TheliaDebugBar'; From 2ecd1caac604746ed3141a7e8c24e451b3dedc15 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 08:25:42 +0200 Subject: [PATCH 09/26] dispatching event for clearing cache --- core/lib/Thelia/Action/Cache.php | 77 +++++++++++++++++++ core/lib/Thelia/Command/CacheClear.php | 18 +++-- core/lib/Thelia/Config/Resources/action.xml | 5 ++ .../Thelia/Core/Event/Cache/CacheEvent.php | 67 ++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 7 ++ 5 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 core/lib/Thelia/Action/Cache.php create mode 100644 core/lib/Thelia/Core/Event/Cache/CacheEvent.php diff --git a/core/lib/Thelia/Action/Cache.php b/core/lib/Thelia/Action/Cache.php new file mode 100644 index 000000000..6d2cf1a16 --- /dev/null +++ b/core/lib/Thelia/Action/Cache.php @@ -0,0 +1,77 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Filesystem\Filesystem; +use Thelia\Core\Event\Cache\CacheEvent; +use Thelia\Core\Event\TheliaEvents; + + +/** + * Class Cache + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Cache extends BaseAction implements EventSubscriberInterface +{ + + public function cacheClear(CacheEvent $event) + { + $dir = $event->getDir(); + + $directoryBrowser = new \DirectoryIterator($dir); + + + $fs = new Filesystem(); + $fs->remove($dir); + + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::CACHE_CLEAR => array('cacheClear', 128) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Command/CacheClear.php b/core/lib/Thelia/Command/CacheClear.php index e85e29741..1d4e7919c 100755 --- a/core/lib/Thelia/Command/CacheClear.php +++ b/core/lib/Thelia/Command/CacheClear.php @@ -30,6 +30,8 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Exception\IOException; use Thelia\Command\ContainerAwareCommand; +use Thelia\Core\Event\Cache\CacheEvent; +use Thelia\Core\Event\TheliaEvents; /** * clear the cache @@ -72,7 +74,11 @@ class CacheClear extends ContainerAwareCommand $output->writeln(sprintf("Clearing cache in %s directory", $dir)); try { - $directoryBrowser = new \DirectoryIterator($dir); + $cacheEvent = new CacheEvent($dir); + $this-> + getContainer() + ->get('event_dispatcher') + ->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent); } catch (\UnexpectedValueException $e) { // throws same exception code for does not exist and permission denied ... if (!file_exists($dir)) { @@ -82,15 +88,11 @@ class CacheClear extends ContainerAwareCommand } throw $e; - } - - $fs = new Filesystem(); - try { - $fs->remove($dir); - - $output->writeln(sprintf("%s cache dir cleared successfully", $dir)); } catch (IOException $e) { $output->writeln(sprintf("Error during clearing cache : %s", $e->getMessage())); } + + $output->writeln(sprintf("%s cache dir cleared successfully", $dir)); + } } diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 8b4cfe783..9088d1a50 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -141,6 +141,11 @@ + + + + + diff --git a/core/lib/Thelia/Core/Event/Cache/CacheEvent.php b/core/lib/Thelia/Core/Event/Cache/CacheEvent.php new file mode 100644 index 000000000..3a882d5dd --- /dev/null +++ b/core/lib/Thelia/Core/Event/Cache/CacheEvent.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Cache; + +use Thelia\Core\Event\ActionEvent; + + +/** + * Class CacheEvent + * @package Thelia\Core\Event\Cache + * @author Manuel Raynaud + */ +class CacheEvent extends ActionEvent +{ + /** + * @var string cache directory + */ + protected $dir; + + public function __construct($dir) + { + $this->dir = $dir; + } + + /** + * @param mixed $dir + * + * @return $this + */ + public function setDir($dir) + { + $this->dir = $dir; + + return $this; + } + + /** + * @return mixed + */ + public function getDir() + { + return $this->dir; + } + + +} \ 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 78e96bf97..f70eca2a1 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -657,6 +657,13 @@ final class TheliaEvents const GENERATE_PDF = 'thelia.generatePdf'; + /** + * sent when a module is activated or deactivated + */ const MODULE_TOGGLE_ACTIVATION = 'thelia.module.toggleActivation'; + /** + * sent for clearing cache + */ + const CACHE_CLEAR = 'thelia.cache.clear'; } From 3a4fb6f2d240a1a96909dee8a7d08a763359b500 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 08:33:46 +0200 Subject: [PATCH 10/26] clear cache after each activatin or deactivation --- core/lib/Thelia/Action/Module.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 18fdb85cb..5025c513f 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -23,6 +23,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Cache\CacheEvent; use Thelia\Core\Event\Module\ModuleToggleActivationEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\ModuleQuery; @@ -56,9 +57,18 @@ class Module extends BaseAction implements EventSubscriberInterface if($module->isModified()) { $event->setModule($module); } + + $this->cacheClear(); } } + protected function cacheClear() + { + $cacheEvent = new CacheEvent($this->container->getParameter('kernel.cache_dir')); + + $this->getDispatcher()->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent); + } + /** * Returns an array of event names this subscriber wants to listen to. * From 12b5a813641ea541200978b23137327296e5f924 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 09:17:08 +0200 Subject: [PATCH 11/26] display error on ajax module activation --- .../Controller/Admin/ModuleController.php | 8 +++-- .../admin/default/includes/module-block.html | 6 ++-- templates/admin/default/modules.html | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index ec7ff472f..4a22c868a 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -70,9 +70,13 @@ class ModuleController extends BaseAdminController if($this->getRequest()->isXmlHttpRequest()) { if($message) { - $response = $this->nullResponse($message, 500); + $response = $this->jsonResponse(json_encode(array( + "error" => $message + )), 500); + } else { + $response = $this->nullResponse(); } - $response = $this->nullResponse(); + } else { $this->redirectToRoute('admin.module'); } diff --git a/templates/admin/default/includes/module-block.html b/templates/admin/default/includes/module-block.html index 2b45f5bc3..dd499393f 100644 --- a/templates/admin/default/includes/module-block.html +++ b/templates/admin/default/includes/module-block.html @@ -22,14 +22,14 @@ {$TITLE} {$CHAPO} -
+
diff --git a/templates/admin/default/modules.html b/templates/admin/default/modules.html index 06d7420bd..57bb14bf1 100644 --- a/templates/admin/default/modules.html +++ b/templates/admin/default/modules.html @@ -55,6 +55,21 @@ form_content = {$smarty.capture.delete_module_dialog nofilter} } + + {/block} {block name="javascript-initialization"} @@ -62,4 +77,24 @@ {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} {/javascripts} + + {/block} \ No newline at end of file From 52ed89f1aa3396ca2dfd71657e16334d5bdc1ca6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 09:28:17 +0200 Subject: [PATCH 12/26] fix cs --- core/lib/Thelia/Action/Area.php | 4 +--- core/lib/Thelia/Action/Cache.php | 4 +--- core/lib/Thelia/Action/Content.php | 2 +- core/lib/Thelia/Action/Country.php | 7 ++----- core/lib/Thelia/Action/Customer.php | 1 - core/lib/Thelia/Action/Module.php | 9 ++++---- core/lib/Thelia/Action/Pdf.php | 3 +-- core/lib/Thelia/Action/ShippingZone.php | 5 ++--- core/lib/Thelia/Action/TaxRule.php | 10 ++++----- core/lib/Thelia/Command/Install.php | 6 +++--- .../Thelia/Command/ModuleActivateCommand.php | 1 - .../Thelia/Command/Skeleton/Module/Class.php | 2 +- .../Controller/Admin/AddressController.php | 16 ++++++-------- .../Controller/Admin/BaseAdminController.php | 4 ++-- .../Controller/Admin/CountryController.php | 2 +- .../Controller/Admin/CustomerController.php | 5 ----- .../Controller/Admin/ModuleController.php | 7 +++---- .../Controller/Admin/OrderController.php | 3 +-- .../Admin/ShippingZoneController.php | 1 - .../Controller/Admin/TaxRuleController.php | 6 +++--- .../Core/Event/Area/AreaAddCountryEvent.php | 8 ++----- .../Core/Event/Area/AreaCreateEvent.php | 4 +--- .../Core/Event/Area/AreaDeleteEvent.php | 4 +--- core/lib/Thelia/Core/Event/Area/AreaEvent.php | 3 +-- .../Event/Area/AreaRemoveCountryEvent.php | 3 +-- .../Core/Event/Area/AreaUpdateEvent.php | 3 +-- .../Event/Area/AreaUpdatePostageEvent.php | 8 ++----- .../Thelia/Core/Event/Cache/CacheEvent.php | 4 +--- .../Event/Content/ContentAddFolderEvent.php | 5 +---- .../Content/ContentRemoveFolderEvent.php | 3 +-- .../Core/Event/Country/CountryCreateEvent.php | 4 +--- .../Core/Event/Country/CountryDeleteEvent.php | 5 ++--- .../Core/Event/Country/CountryEvent.php | 6 ++---- .../Country/CountryToggleDefaultEvent.php | 5 ++--- .../Core/Event/Country/CountryUpdateEvent.php | 8 ++----- .../Thelia/Core/Event/Module/ModuleEvent.php | 8 ++----- .../Module/ModuleToggleActivationEvent.php | 8 ++----- core/lib/Thelia/Core/Event/PdfEvent.php | 16 +++++++------- .../Core/Event/Product/ProductCreateEvent.php | 1 - .../Core/Event/Product/ProductDeleteEvent.php | 1 - .../ShippingZone/ShippingZoneAddAreaEvent.php | 8 ++----- .../ShippingZoneRemoveAreaEvent.php | 3 +-- .../Thelia/Core/Event/Tax/TaxRuleEvent.php | 1 - core/lib/Thelia/Core/Event/TheliaEvents.php | 3 --- core/lib/Thelia/Core/Template/Loop/Area.php | 7 ++----- core/lib/Thelia/Core/Template/Loop/Folder.php | 2 +- .../Thelia/Core/Template/Loop/FolderPath.php | 4 +--- core/lib/Thelia/Core/Template/Loop/Tax.php | 6 +++--- .../Core/Template/Loop/TaxRuleCountry.php | 16 ++++++-------- .../Thelia/Core/Template/Loop/Template.php | 1 - .../Smarty/Plugins/DataAccessFunctions.php | 3 ++- .../Core/Template/Smarty/Plugins/Form.php | 6 +++--- core/lib/Thelia/Form/Area/AreaCountryForm.php | 3 +-- core/lib/Thelia/Form/Area/AreaCreateForm.php | 3 +-- .../Thelia/Form/Area/AreaModificationForm.php | 3 +-- core/lib/Thelia/Form/Area/AreaPostageForm.php | 3 +-- .../Thelia/Form/CountryModificationForm.php | 2 -- .../Form/ShippingZone/ShippingZoneAddArea.php | 3 +-- .../ShippingZone/ShippingZoneRemoveArea.php | 3 +-- core/lib/Thelia/Form/TaxRuleCreationForm.php | 2 -- .../Thelia/Form/TaxRuleTaxListUpdateForm.php | 12 +++++------ core/lib/Thelia/Module/BaseModule.php | 14 ++++++------- .../Exception/InvalidXmlDocumentException.php | 3 +-- .../Module/ModuleDescriptorValidator.php | 10 ++++----- core/lib/Thelia/Module/ModuleManagement.php | 21 ++++++++----------- core/lib/Thelia/Tests/Action/BaseAction.php | 3 +-- core/lib/Thelia/Tests/Action/ContentTest.php | 7 +++---- core/lib/Thelia/Tests/Action/FolderTest.php | 13 +++++------- .../Thelia/Tests/TaxEngine/CalculatorTest.php | 8 +++---- templates/admin/default/modules.html | 2 +- 70 files changed, 136 insertions(+), 244 deletions(-) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index d9173ae93..92eb75634 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -34,7 +34,6 @@ use Thelia\Model\CountryQuery; use Thelia\Action\BaseAction; use Thelia\Model\Area as AreaModel; - /** * Class Area * @package Thelia\Action @@ -97,7 +96,6 @@ class Area extends BaseAction implements EventSubscriberInterface $event->setArea($area); } - /** * Returns an array of event names this subscriber wants to listen to. * @@ -128,4 +126,4 @@ class Area extends BaseAction implements EventSubscriberInterface TheliaEvents::AREA_CREATE => array('create', 128) ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/Cache.php b/core/lib/Thelia/Action/Cache.php index 6d2cf1a16..4407c3e92 100644 --- a/core/lib/Thelia/Action/Cache.php +++ b/core/lib/Thelia/Action/Cache.php @@ -27,7 +27,6 @@ use Symfony\Component\Filesystem\Filesystem; use Thelia\Core\Event\Cache\CacheEvent; use Thelia\Core\Event\TheliaEvents; - /** * Class Cache * @package Thelia\Action @@ -42,7 +41,6 @@ class Cache extends BaseAction implements EventSubscriberInterface $directoryBrowser = new \DirectoryIterator($dir); - $fs = new Filesystem(); $fs->remove($dir); @@ -74,4 +72,4 @@ class Cache extends BaseAction implements EventSubscriberInterface TheliaEvents::CACHE_CLEAR => array('cacheClear', 128) ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php index 8560aa00e..3c027ad04 100644 --- a/core/lib/Thelia/Action/Content.php +++ b/core/lib/Thelia/Action/Content.php @@ -160,7 +160,7 @@ class Content extends BaseAction implements EventSubscriberInterface ->filterByFolderId($event->getFolderId()) ->findOne(); - if(null !== $contentFolder) { + if (null !== $contentFolder) { $contentFolder->delete(); } } diff --git a/core/lib/Thelia/Action/Country.php b/core/lib/Thelia/Action/Country.php index 69bf3c568..4c2d0839b 100644 --- a/core/lib/Thelia/Action/Country.php +++ b/core/lib/Thelia/Action/Country.php @@ -32,7 +32,6 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Country as CountryModel; use Thelia\Model\CountryQuery; - /** * Class Country * @package Thelia\Action @@ -85,15 +84,13 @@ class Country extends BaseAction implements EventSubscriberInterface public function toggleDefault(CountryToggleDefaultEvent $event) { - if( null !== $country = CountryQuery::create()->findPk($event->getCountryId())) - { + if ( null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { $country->toggleDefault(); $event->setCountry($country); } } - /** * Returns an array of event names this subscriber wants to listen to. * @@ -123,4 +120,4 @@ class Country extends BaseAction implements EventSubscriberInterface TheliaEvents::COUNTRY_TOGGLE_DEFAULT => array('toggleDefault', 128) ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 85643cb88..2e18872f6 100755 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -25,7 +25,6 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\ActionEvent; -use Thelia\Core\Event\Customer\CustomerAddressEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\TheliaEvents; diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 5025c513f..213024e16 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -29,7 +29,6 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\ModuleQuery; use Thelia\Module\BaseModule; - /** * Class Module * @package Thelia\Action @@ -45,16 +44,16 @@ class Module extends BaseAction implements EventSubscriberInterface $moduleInstance = $moduleClass->newInstance(); - if( method_exists($moduleInstance, 'setContainer')) { + if ( method_exists($moduleInstance, 'setContainer')) { $moduleInstance->setContainer($this->container); - if($module->getActivate() == BaseModule::IS_ACTIVATED) { + if ($module->getActivate() == BaseModule::IS_ACTIVATED) { $moduleInstance->deActivate($module); } else { $moduleInstance->activate($module); } } - if($module->isModified()) { + if ($module->isModified()) { $event->setModule($module); } @@ -95,4 +94,4 @@ class Module extends BaseAction implements EventSubscriberInterface TheliaEvents::MODULE_TOGGLE_ACTIVATION => array('toggleActivation', 128) ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/Pdf.php b/core/lib/Thelia/Action/Pdf.php index 52ce0b92d..2bdad9366 100644 --- a/core/lib/Thelia/Action/Pdf.php +++ b/core/lib/Thelia/Action/Pdf.php @@ -26,7 +26,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\PdfEvent; use Thelia\Core\Event\TheliaEvents; - /** * Class Pdf * @package Thelia\Action @@ -72,4 +71,4 @@ class Pdf extends BaseAction implements EventSubscriberInterface TheliaEvents::GENERATE_PDF => array("generatePdf", 128) ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/ShippingZone.php b/core/lib/Thelia/Action/ShippingZone.php index 517a5ca25..c621efd8f 100644 --- a/core/lib/Thelia/Action/ShippingZone.php +++ b/core/lib/Thelia/Action/ShippingZone.php @@ -29,7 +29,6 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\AreaDeliveryModule; use Thelia\Model\AreaDeliveryModuleQuery; - /** * Class ShippingZone * @package Thelia\Action @@ -55,7 +54,7 @@ class ShippingZone extends BaseAction implements EventSubscriberInterface ->filterByDeliveryModuleId($event->getShoppingZoneId()) ->findOne(); - if($areaDelivery) { + if ($areaDelivery) { $areaDelivery->delete(); } else { throw new \RuntimeException(sprintf('areaDeliveryModule not found with area_id = %d and delivery_module_id = %d', $event->getAreaId(), $event->getShoppingZoneId())); @@ -89,4 +88,4 @@ class ShippingZone extends BaseAction implements EventSubscriberInterface TheliaEvents::SHIPPING_ZONE_REMOVE_AREA => array('removeArea', 128), ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/TaxRule.php b/core/lib/Thelia/Action/TaxRule.php index 4b24f8cb9..f9f9fb412 100644 --- a/core/lib/Thelia/Action/TaxRule.php +++ b/core/lib/Thelia/Action/TaxRule.php @@ -68,8 +68,6 @@ class TaxRule extends BaseAction implements EventSubscriberInterface ->save() ; - - $event->setTaxRule($taxRule); } } @@ -90,12 +88,12 @@ class TaxRule extends BaseAction implements EventSubscriberInterface ->delete(); /* for each country */ - foreach($event->getCountryList() as $country) { + foreach ($event->getCountryList() as $country) { $position = 1; /* on applique les nouvelles regles */ - foreach($taxList as $tax) { - if(is_array($tax)) { - foreach($tax as $samePositionTax) { + foreach ($taxList as $tax) { + if (is_array($tax)) { + foreach ($tax as $samePositionTax) { $taxModel = new TaxRuleCountry(); $taxModel->setTaxRule($taxRule) ->setCountryId($country) diff --git a/core/lib/Thelia/Command/Install.php b/core/lib/Thelia/Command/Install.php index 6423d861a..7b6ca31c5 100755 --- a/core/lib/Thelia/Command/Install.php +++ b/core/lib/Thelia/Command/Install.php @@ -143,8 +143,8 @@ class Install extends ContainerAwareCommand $permissions = new CheckPermission(false, $this->getContainer()->get('thelia.translator')); $isValid = $permissions->exec(); - foreach($permissions->getValidationMessages() as $item => $data) { - if($data['status']) { + foreach ($permissions->getValidationMessages() as $item => $data) { + if ($data['status']) { $output->writeln(array( sprintf("%s ... %s", $data['text'], @@ -162,7 +162,7 @@ class Install extends ContainerAwareCommand } - if(false === $isValid) { + if (false === $isValid) { $output->writeln(array( "", "Please put correct permissions and reload install process" diff --git a/core/lib/Thelia/Command/ModuleActivateCommand.php b/core/lib/Thelia/Command/ModuleActivateCommand.php index d5ca8156d..1b8ac600f 100755 --- a/core/lib/Thelia/Command/ModuleActivateCommand.php +++ b/core/lib/Thelia/Command/ModuleActivateCommand.php @@ -26,7 +26,6 @@ namespace Thelia\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Filesystem\Filesystem; use Thelia\Model\ModuleQuery; diff --git a/core/lib/Thelia/Command/Skeleton/Module/Class.php b/core/lib/Thelia/Command/Skeleton/Module/Class.php index c4c90aa60..c9c7109ac 100755 --- a/core/lib/Thelia/Command/Skeleton/Module/Class.php +++ b/core/lib/Thelia/Command/Skeleton/Module/Class.php @@ -25,7 +25,7 @@ namespace %%NAMESPACE%%; use Thelia\Module\BaseModule; -class %%CLASSNAME%% extends BaseModule +class Class extends BaseModule { /** * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php index 38ec9cb6b..859fb8dc6 100644 --- a/core/lib/Thelia/Controller/Admin/AddressController.php +++ b/core/lib/Thelia/Controller/Admin/AddressController.php @@ -24,14 +24,12 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; use Thelia\Core\Event\Address\AddressEvent; -use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\AddressCreateForm; use Thelia\Form\AddressUpdateForm; use Thelia\Model\AddressQuery; use Thelia\Model\CustomerQuery; - /** * Class AddressController * @package Thelia\Controller\Admin @@ -78,7 +76,7 @@ class AddressController extends AbstractCrudController $this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $addressEvent); $this->adminLogAppend(sprintf("address %d for customer %d removal", $address_id, $address->getCustomerId())); - } catch(\Exception $e) { + } catch (\Exception $e) { \Thelia\Log\Tlog::getInstance()->error(sprintf("error during address removal with message %s", $e->getMessage())); } @@ -176,8 +174,6 @@ class AddressController extends AbstractCrudController $formData["is_default"] ); - - return $event; } @@ -279,8 +275,8 @@ class AddressController extends AbstractCrudController /** * Put in this method post object delete processing if required. * - * @param \Thelia\Core\Event\AddressEvent $deleteEvent the delete event - * @return Response a response, or null to continue normal processing + * @param \Thelia\Core\Event\AddressEvent $deleteEvent the delete event + * @return Response a response, or null to continue normal processing */ protected function performAdditionalDeleteAction($deleteEvent) { @@ -291,8 +287,8 @@ class AddressController extends AbstractCrudController /** * Put in this method post object creation processing if required. * - * @param AddressCreateOrUpdateEvent $createEvent the create event - * @return Response a response, or null to continue normal processing + * @param AddressCreateOrUpdateEvent $createEvent the create event + * @return Response a response, or null to continue normal processing */ protected function performAdditionalCreateAction($createEvent) { @@ -303,4 +299,4 @@ class AddressController extends AbstractCrudController { $this->redirectToEditionTemplate(); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 9adb7a19a..829e51c37 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -378,8 +378,8 @@ class BaseAdminController extends BaseController * Render the given template, and returns the result as a string. * * @param $templateName the complete template name, with extension - * @param array $args the template arguments - * @param null $templateDir + * @param array $args the template arguments + * @param null $templateDir * * @return \Symfony\Component\HttpFoundation\Response */ diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index 91160311f..a19a19212 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -243,7 +243,7 @@ class CountryController extends AbstractCrudController try { $this->dispatch(TheliaEvents::COUNTRY_TOGGLE_DEFAULT, $toogleDefaultEvent); - if($toogleDefaultEvent->hasCountry()) { + if ($toogleDefaultEvent->hasCountry()) { return $this->nullResponse(); } } catch (\Exception $ex) { diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index e4d24e9ad..c5ebc9a39 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -25,14 +25,11 @@ namespace Thelia\Controller\Admin; use Propel\Runtime\Exception\PropelException; use Symfony\Component\Form\Form; -use Thelia\Core\Event\Address\AddressEvent; -use Thelia\Core\Event\Customer\CustomerAddressEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Form\CustomerModification; use Thelia\Form\Exception\FormValidationException; -use Thelia\Model\AddressQuery; use Thelia\Model\CustomerQuery; use Thelia\Core\Translation\Translator; @@ -57,8 +54,6 @@ class CustomerController extends BaseAdminController )); } - - /** * update customer action * diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 4a22c868a..c7d020d58 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -59,7 +59,7 @@ class ModuleController extends BaseAdminController $event = new ModuleToggleActivationEvent($module_id); $this->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $event); - if(null === $event->getModule()) { + if (null === $event->getModule()) { throw new \LogicException( $this->getTranslator()->trans("No %obj was updated.", array('%obj' => 'Module'))); } @@ -67,9 +67,8 @@ class ModuleController extends BaseAdminController $message = $e->getMessage(); } - - if($this->getRequest()->isXmlHttpRequest()) { - if($message) { + if ($this->getRequest()->isXmlHttpRequest()) { + if ($message) { $response = $this->jsonResponse(json_encode(array( "error" => $message )), 500); diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php index 1df0679f0..4524e16ac 100644 --- a/core/lib/Thelia/Controller/Admin/OrderController.php +++ b/core/lib/Thelia/Controller/Admin/OrderController.php @@ -211,7 +211,6 @@ class OrderController extends BaseAdminController { if (null !== $response = $this->checkAuth("admin.order.update")) return $response; - $html = $this->renderRaw( $fileName, array( @@ -227,7 +226,7 @@ class OrderController extends BaseAdminController $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent); - if($pdfEvent->hasPdf()) { + if ($pdfEvent->hasPdf()) { return Response::create($pdfEvent->getPdf(), 200, array( 'Content-type' => "application/pdf", diff --git a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php index d68de4808..b53b0a911 100644 --- a/core/lib/Thelia/Controller/Admin/ShippingZoneController.php +++ b/core/lib/Thelia/Controller/Admin/ShippingZoneController.php @@ -140,5 +140,4 @@ class ShippingZoneController extends BaseAdminController return $this->getRequest()->get('shipping_zone_id', 0); } - } diff --git a/core/lib/Thelia/Controller/Admin/TaxRuleController.php b/core/lib/Thelia/Controller/Admin/TaxRuleController.php index b0ceba67e..cfa5af1ff 100644 --- a/core/lib/Thelia/Controller/Admin/TaxRuleController.php +++ b/core/lib/Thelia/Controller/Admin/TaxRuleController.php @@ -199,8 +199,8 @@ class TaxRuleController extends AbstractCrudController /** * Put in this method post object creation processing if required. * - * @param TaxRuleEvent $createEvent the create event - * @return Response a response, or null to continue normal processing + * @param TaxRuleEvent $createEvent the create event + * @return Response a response, or null to continue normal processing */ protected function performAdditionalCreateAction($createEvent) { @@ -284,4 +284,4 @@ class TaxRuleController extends AbstractCrudController // At this point, the form has errors, and should be redisplayed. return $this->renderEditionTemplate(); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php b/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php index b6af3c5b3..5c98c071c 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaAddCountryEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Area; - /** * Class AreaAddCountryEvent * @package Thelia\Core\Event\Area @@ -34,7 +33,7 @@ class AreaAddCountryEvent extends AreaEvent protected $area_id; protected $country_id; - function __construct($area_id, $country_id) + public function __construct($area_id, $country_id) { $this->area_id = $area_id; $this->country_id = $country_id; @@ -80,7 +79,4 @@ class AreaAddCountryEvent extends AreaEvent return $this->country_id; } - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php index d63afa5b9..32dc7a6c8 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Area; - /** * Class AreaCreateEvent * @package Thelia\Core\Event\Area @@ -49,5 +48,4 @@ class AreaCreateEvent extends AreaEvent return $this->name; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php b/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php index 86f936140..2a83c98a4 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaDeleteEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Area; - /** * Class AreaDeleteEvent * @package Thelia\Core\Event\Area @@ -61,5 +60,4 @@ class AreaDeleteEvent extends AreaEvent return $this->area_id; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaEvent.php b/core/lib/Thelia/Core/Event/Area/AreaEvent.php index 892d00843..9e0c2dc00 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaEvent.php @@ -24,7 +24,6 @@ namespace Thelia\Core\Event\Area; use Thelia\Core\Event\ActionEvent; - /** * Class AreaEvent * @package Thelia\Core\Event\Shipping @@ -63,4 +62,4 @@ class AreaEvent extends ActionEvent { return null !== $this->area; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php b/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php index 84c8f10d2..92cfd57d3 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaRemoveCountryEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Area; - /** * Class AreaRemoveCountryEvent * @package Thelia\Core\Event\Area @@ -32,4 +31,4 @@ namespace Thelia\Core\Event\Area; class AreaRemoveCountryEvent extends AreaAddCountryEvent { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php index f5f7c8704..361607f42 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaUpdateEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Area; - /** * Class AreaUpdateEvent * @package Thelia\Core\Event\Area @@ -32,4 +31,4 @@ namespace Thelia\Core\Event\Area; class AreaUpdateEvent extends AreaCreateEvent { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php b/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php index 5f799b93c..b9cb825c4 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaUpdatePostageEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Area; - /** * Class AreaUpdatePostageEvent * @package Thelia\Core\Event\Area @@ -34,7 +33,7 @@ class AreaUpdatePostageEvent extends AreaEvent protected $area_id; protected $postage; - function __construct($area_id) + public function __construct($area_id) { $this->area_id = $area_id; } @@ -79,7 +78,4 @@ class AreaUpdatePostageEvent extends AreaEvent return $this->postage; } - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Cache/CacheEvent.php b/core/lib/Thelia/Core/Event/Cache/CacheEvent.php index 3a882d5dd..7b21db53d 100644 --- a/core/lib/Thelia/Core/Event/Cache/CacheEvent.php +++ b/core/lib/Thelia/Core/Event/Cache/CacheEvent.php @@ -25,7 +25,6 @@ namespace Thelia\Core\Event\Cache; use Thelia\Core\Event\ActionEvent; - /** * Class CacheEvent * @package Thelia\Core\Event\Cache @@ -63,5 +62,4 @@ class CacheEvent extends ActionEvent return $this->dir; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php b/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php index a1d1d44e1..dac4317ba 100644 --- a/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php +++ b/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php @@ -24,7 +24,6 @@ namespace Thelia\Core\Event\Content; use Thelia\Model\Content; - /** * Class ContentAddFolderEvent * @package Thelia\Core\Event\Content @@ -61,6 +60,4 @@ class ContentAddFolderEvent extends ContentEvent return $this->folderId; } - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Content/ContentRemoveFolderEvent.php b/core/lib/Thelia/Core/Event/Content/ContentRemoveFolderEvent.php index 195f4f3b0..1733ec893 100644 --- a/core/lib/Thelia/Core/Event/Content/ContentRemoveFolderEvent.php +++ b/core/lib/Thelia/Core/Event/Content/ContentRemoveFolderEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Content; - /** * Class ContentRemoveFolderEvent * @package Thelia\Core\Event\Content @@ -31,4 +30,4 @@ namespace Thelia\Core\Event\Content; */ class ContentRemoveFolderEvent extends ContentAddFolderEvent { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php b/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php index 48e8469a4..92d6632ae 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryCreateEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Country; - /** * Class CountryCreateEvent * @package Thelia\Core\Event\Country @@ -150,5 +149,4 @@ class CountryCreateEvent extends CountryEvent return $this->area; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php b/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php index 4a7d9c400..5d658ebc0 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryDeleteEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Country; - /** * Class CountryDeleteEvent * @package Thelia\Core\Event\Country @@ -36,7 +35,7 @@ class CountryDeleteEvent extends CountryEvent */ protected $country_id; - function __construct($country_id) + public function __construct($country_id) { $this->country_id = $country_id; } @@ -57,4 +56,4 @@ class CountryDeleteEvent extends CountryEvent return $this->country_id; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Country/CountryEvent.php b/core/lib/Thelia/Core/Event/Country/CountryEvent.php index 962d880fa..505ead8ec 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryEvent.php @@ -25,7 +25,6 @@ namespace Thelia\Core\Event\Country; use Thelia\Core\Event\ActionEvent; use Thelia\Model\Country; - /** * Class CountryEvent * @package Thelia\Core\Event\Country @@ -38,7 +37,7 @@ class CountryEvent extends ActionEvent */ protected $country; - function __construct(Country $country = null) + public function __construct(Country $country = null) { $this->country = $country; } @@ -69,5 +68,4 @@ class CountryEvent extends ActionEvent return null !== $this->country; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php b/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php index 8f8142d0d..a414c70e8 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryToggleDefaultEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Country; - /** * Class CountryToggleDefaultEvent * @package Thelia\Core\Event\Country @@ -33,7 +32,7 @@ class CountryToggleDefaultEvent extends CountryEvent { protected $country_id; - function __construct($country_id) + public function __construct($country_id) { $this->country_id = $country_id; } @@ -45,4 +44,4 @@ class CountryToggleDefaultEvent extends CountryEvent { return $this->country_id; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php index 496904172..2f82b17d0 100644 --- a/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Country/CountryUpdateEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Country; - /** * Class CountryUpdateEvent * @package Thelia\Core\Event\Country @@ -37,7 +36,7 @@ class CountryUpdateEvent extends CountryCreateEvent protected $description; protected $postscriptum; - function __construct($country_id) + public function __construct($country_id) { $this->country_id = $country_id; } @@ -114,7 +113,4 @@ class CountryUpdateEvent extends CountryCreateEvent return $this->country_id; } - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Module/ModuleEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php index e9cf2623e..c37b2b995 100644 --- a/core/lib/Thelia/Core/Event/Module/ModuleEvent.php +++ b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php @@ -25,7 +25,6 @@ namespace Thelia\Core\Event\Module; use Thelia\Core\Event\ActionEvent; use Thelia\Model\Module; - /** * Class ModuleEvent * @package Thelia\Core\Event\Module @@ -38,7 +37,7 @@ class ModuleEvent extends ActionEvent */ protected $module; - function __construct(Module $module = null) + public function __construct(Module $module = null) { $this->module = $module; } @@ -63,7 +62,4 @@ class ModuleEvent extends ActionEvent return $this->module; } - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php index dd517d8ff..c6ece16f4 100644 --- a/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php +++ b/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Module; - /** * Class ModuleToggleActivationEvent * @package Thelia\Core\Event\Module @@ -36,7 +35,7 @@ class ModuleToggleActivationEvent extends ModuleEvent */ protected $module_id; - function __construct($module_id) + public function __construct($module_id) { $this->module_id = $module_id; } @@ -61,7 +60,4 @@ class ModuleToggleActivationEvent extends ModuleEvent return $this->module_id; } - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/PdfEvent.php b/core/lib/Thelia/Core/Event/PdfEvent.php index e0f873e04..b439c8a23 100644 --- a/core/lib/Thelia/Core/Event/PdfEvent.php +++ b/core/lib/Thelia/Core/Event/PdfEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event; - /** * Class PdfEvent * @package Thelia\Core\Event @@ -44,12 +43,12 @@ class PdfEvent extends ActionEvent /** * @param $content html content to transform into pdf - * @param string $orientation page orientation, same as TCPDF - * @param string $format The format used for pages, same as TCPDF - * @param string $lang Lang : fr, en, it... - * @param bool $unicode TRUE means that the input text is unicode (default = true) - * @param string $encoding charset encoding; default is UTF-8 - * @param array $marges Default marges (left, top, right, bottom) + * @param string $orientation page orientation, same as TCPDF + * @param string $format The format used for pages, same as TCPDF + * @param string $lang Lang : fr, en, it... + * @param bool $unicode TRUE means that the input text is unicode (default = true) + * @param string $encoding charset encoding; default is UTF-8 + * @param array $marges Default marges (left, top, right, bottom) */ public function __construct($content, $orientation = 'P', $format = 'A4', $lang='fr', $unicode=true, $encoding='UTF-8',array $marges = array(0, 0, 0, 0)) { @@ -189,5 +188,4 @@ class PdfEvent extends ActionEvent return $this->unicode; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Product/ProductCreateEvent.php b/core/lib/Thelia/Core/Event/Product/ProductCreateEvent.php index a9f6bbea1..9717f171d 100644 --- a/core/lib/Thelia/Core/Event/Product/ProductCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Product/ProductCreateEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Product; - class ProductCreateEvent extends ProductEvent { protected $ref; diff --git a/core/lib/Thelia/Core/Event/Product/ProductDeleteEvent.php b/core/lib/Thelia/Core/Event/Product/ProductDeleteEvent.php index 108ceb781..7a3406e7e 100644 --- a/core/lib/Thelia/Core/Event/Product/ProductDeleteEvent.php +++ b/core/lib/Thelia/Core/Event/Product/ProductDeleteEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\Product; - class ProductDeleteEvent extends ProductEvent { public function __construct($product_id) diff --git a/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php index d1e406646..35f3dcac1 100644 --- a/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php +++ b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneAddAreaEvent.php @@ -24,7 +24,6 @@ namespace Thelia\Core\Event\ShippingZone; use Thelia\Core\Event\ActionEvent; - /** * Class ShippingZoneAddAreaEvent * @package Thelia\Core\Event\ShippingZone @@ -35,7 +34,7 @@ class ShippingZoneAddAreaEvent extends ActionEvent protected $area_id; protected $shopping_zone_id; - function __construct($area_id, $shopping_zone_id) + public function __construct($area_id, $shopping_zone_id) { $this->area_id = $area_id; $this->shopping_zone_id = $shopping_zone_id; @@ -81,7 +80,4 @@ class ShippingZoneAddAreaEvent extends ActionEvent return $this->shopping_zone_id; } - - - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php index 6dc6094d6..a3177f522 100644 --- a/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php +++ b/core/lib/Thelia/Core/Event/ShippingZone/ShippingZoneRemoveAreaEvent.php @@ -23,7 +23,6 @@ namespace Thelia\Core\Event\ShippingZone; - /** * Class ShippingZoneRemoveAreaEvent * @package Thelia\Core\Event\ShippingZone @@ -32,4 +31,4 @@ namespace Thelia\Core\Event\ShippingZone; class ShippingZoneRemoveAreaEvent extends ShippingZoneAddAreaEvent { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php b/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php index e364bfd84..6d3f21e6e 100644 --- a/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php +++ b/core/lib/Thelia/Core/Event/Tax/TaxRuleEvent.php @@ -118,5 +118,4 @@ class TaxRuleEvent extends ActionEvent return $this->taxList; } - } diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index f70eca2a1..860b63e27 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -183,7 +183,6 @@ final class TheliaEvents const FOLDER_TOGGLE_VISIBILITY = "action.toggleFolderVisibility"; const FOLDER_UPDATE_POSITION = "action.updateFolderPosition"; - const BEFORE_CREATEFOLDER = "action.before_createFolder"; const AFTER_CREATEFOLDER = "action.after_createFolder"; @@ -204,7 +203,6 @@ final class TheliaEvents const CONTENT_ADD_FOLDER = "action.contentAddFolder"; const CONTENT_REMOVE_FOLDER = "action.contentRemoveFolder"; - const BEFORE_CREATECONTENT = "action.before_createContent"; const AFTER_CREATECONTENT = "action.after_createContent"; @@ -222,7 +220,6 @@ final class TheliaEvents const COUNTRY_TOGGLE_DEFAULT = "action.toggleCountryDefault"; //const COUNTRY_UPDATE_POSITION = "action.updateFolderPosition"; - const BEFORE_CREATECOUNTRY = "action.before_createCountry"; const AFTER_CREATECOUNTRY = "action.after_createCountry"; diff --git a/core/lib/Thelia/Core/Template/Loop/Area.php b/core/lib/Thelia/Core/Template/Loop/Area.php index 4d43f524b..524777d08 100644 --- a/core/lib/Thelia/Core/Template/Loop/Area.php +++ b/core/lib/Thelia/Core/Template/Loop/Area.php @@ -30,7 +30,6 @@ use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Model\AreaQuery; - /** * Class Area * @package Thelia\Core\Template\Loop @@ -112,8 +111,7 @@ class Area extends BaseLoop $withoutZone = $this->getWithout_zone(); - if($withoutZone) - { + if ($withoutZone) { $search->joinAreaDeliveryModule('without_zone', Criteria::LEFT_JOIN) ->addJoinCondition('without_zone', 'delivery_module_id '.Criteria::EQUAL.' ?', $withoutZone, null, \PDO::PARAM_INT) ->where('`without_zone`.delivery_module_id '.Criteria::ISNULL); @@ -140,5 +138,4 @@ class Area extends BaseLoop return $loopResult; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Loop/Folder.php b/core/lib/Thelia/Core/Template/Loop/Folder.php index 04ba737fa..efc45030f 100755 --- a/core/lib/Thelia/Core/Template/Loop/Folder.php +++ b/core/lib/Thelia/Core/Template/Loop/Folder.php @@ -114,7 +114,7 @@ class Folder extends BaseI18nLoop if (null !== $content) { $obj = ContentQuery::create()->findPk($content); - if($obj) { + if ($obj) { $search->filterByContent($obj, Criteria::IN); } } diff --git a/core/lib/Thelia/Core/Template/Loop/FolderPath.php b/core/lib/Thelia/Core/Template/Loop/FolderPath.php index 272b9fbbb..2b9a52b0d 100644 --- a/core/lib/Thelia/Core/Template/Loop/FolderPath.php +++ b/core/lib/Thelia/Core/Template/Loop/FolderPath.php @@ -30,7 +30,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Model\FolderQuery; use Thelia\Type\BooleanOrBothType; - /** * Class FolderPath * @package Thelia\Core\Template\Loop @@ -156,5 +155,4 @@ class FolderPath extends BaseI18nLoop return $loopResult; } - -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Loop/Tax.php b/core/lib/Thelia/Core/Template/Loop/Tax.php index 1ddf18824..18fb5e0dc 100644 --- a/core/lib/Thelia/Core/Template/Loop/Tax.php +++ b/core/lib/Thelia/Core/Template/Loop/Tax.php @@ -97,7 +97,7 @@ class Tax extends BaseI18nLoop $country = $this->getCountry(); $taxRule = $this->getTax_rule(); - if(null !== $taxRule && null !== $country) { + if (null !== $taxRule && null !== $country) { $search->filterByTaxRuleCountry( TaxRuleCountryQuery::create() ->filterByCountryId($country, Criteria::EQUAL) @@ -108,7 +108,7 @@ class Tax extends BaseI18nLoop } $excludeTaxRule = $this->getExclude_tax_rule(); - if(null !== $excludeTaxRule && null !== $country) { + if (null !== $excludeTaxRule && null !== $country) { $excludedTaxes = TaxRuleCountryQuery::create() ->filterByCountryId($country, Criteria::EQUAL) ->filterByTaxRuleId($excludeTaxRule, Criteria::IN) @@ -118,7 +118,7 @@ class Tax extends BaseI18nLoop $excludedTaxes, Criteria::NOT_IN );*/ - foreach($excludedTaxes as $excludedTax) { + foreach ($excludedTaxes as $excludedTax) { $search->filterByTaxRuleCountry($excludedTax, Criteria::NOT_EQUAL); } } diff --git a/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php b/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php index 91616f398..c4c165192 100644 --- a/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php +++ b/core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php @@ -35,8 +35,6 @@ use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Model\Map\CountryTableMap; use Thelia\Model\Map\TaxRuleCountryTableMap; use Thelia\Model\Map\TaxTableMap; -use Thelia\Type\TypeCollection; -use Thelia\Type; use Thelia\Model\TaxRuleCountryQuery; /** @@ -76,15 +74,15 @@ class TaxRuleCountry extends BaseI18nLoop $country = $this->getCountry(); $taxes = $this->getTaxes(); - if((null === $country && null === $taxes)) { + if ((null === $country && null === $taxes)) { throw new \InvalidArgumentException('You must provide either `country` or `taxes` parameter in tax-rule-country loop'); } - if((null === $country && null !== $taxes)) { + if ((null === $country && null !== $taxes)) { throw new \InvalidArgumentException('You must provide `country` parameter with `taxes` parameter in tax-rule-country loop'); } - if(null !== $taxes) { + if (null !== $taxes) { $search->groupByCountryId(); $originalCountryJoin = new Join(); @@ -106,7 +104,7 @@ class TaxRuleCountry extends BaseI18nLoop CountryTableMap::TABLE_NAME, 'COUNTRY_ID' ); - } elseif(null !== $country) { + } elseif (null !== $country) { $search->filterByCountryId($country); /* manage tax translation */ @@ -132,7 +130,7 @@ class TaxRuleCountry extends BaseI18nLoop $loopResultRow = new LoopResultRow($loopResult, $taxRuleCountry, $this->versionable, $this->timestampable, $this->countable); - if(null !== $taxes) { + if (null !== $taxes) { $loopResultRow ->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId()) ->set("COUNTRY" , $taxRuleCountry->getCountryId()) @@ -141,7 +139,7 @@ class TaxRuleCountry extends BaseI18nLoop ->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_DESCRIPTION')) ->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_POSTSCRIPTUM')) ; - }elseif(null !== $country) { + } elseif (null !== $country) { $loopResultRow ->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId()) ->set("COUNTRY" , $taxRuleCountry->getCountryId()) @@ -152,8 +150,6 @@ class TaxRuleCountry extends BaseI18nLoop ; } - - $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Core/Template/Loop/Template.php b/core/lib/Thelia/Core/Template/Loop/Template.php index 9eaa3ea4f..83ef4fabe 100644 --- a/core/lib/Thelia/Core/Template/Loop/Template.php +++ b/core/lib/Thelia/Core/Template/Loop/Template.php @@ -32,7 +32,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Model\Base\TemplateQuery; -use Thelia\Type; /** * diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 594b45ae9..a401755a4 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -172,6 +172,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin self::$dataAccessCache['defaultCountry'] = $defaultCountry; }*/ $defaultCountry = CountryQuery::create()->filterByByDefault(1)->limit(1); + return $this->dataAccessWithI18n("defaultCountry", $params, $defaultCountry); } } @@ -237,7 +238,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin public function ConfigDataAccess($params, $smarty) { - if(false === array_key_exists("key", $params)) { + if (false === array_key_exists("key", $params)) { return null; } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 37be09824..b86f160dc 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -152,7 +152,7 @@ class Form extends AbstractSmartyPlugin $template->assign("options", $formFieldView->vars); /* access to choices */ - if(isset($formFieldView->vars['choices'])) { + if (isset($formFieldView->vars['choices'])) { $template->assign("choices", $formFieldView->vars['choices']); } @@ -199,8 +199,8 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar foreach ($formView->getIterator() as $row) { if ($this->isHidden($row) && $row->isRendered() === false) { $attributeList = array(); - if(isset($row->vars["attr"])) { - foreach($row->vars["attr"] as $attrKey => $attrValue) { + if (isset($row->vars["attr"])) { + foreach ($row->vars["attr"] as $attrKey => $attrValue) { $attributeList[] = sprintf($attrFormat, $attrKey, $attrValue); } } diff --git a/core/lib/Thelia/Form/Area/AreaCountryForm.php b/core/lib/Thelia/Form/Area/AreaCountryForm.php index c511e0b3c..b3f09ae06 100644 --- a/core/lib/Thelia/Form/Area/AreaCountryForm.php +++ b/core/lib/Thelia/Form/Area/AreaCountryForm.php @@ -28,7 +28,6 @@ use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; - /** * Class AreaCountryForm * @package Thelia\Form\Area @@ -86,4 +85,4 @@ class AreaCountryForm extends BaseForm { return 'thelia_area_country'; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Form/Area/AreaCreateForm.php b/core/lib/Thelia/Form/Area/AreaCreateForm.php index 590001867..79fc4b2a2 100644 --- a/core/lib/Thelia/Form/Area/AreaCreateForm.php +++ b/core/lib/Thelia/Form/Area/AreaCreateForm.php @@ -26,7 +26,6 @@ use Thelia\Core\Translation\Translator; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; - /** * Class AreaCreateForm * @package Thelia\Form\Shipping @@ -76,4 +75,4 @@ class AreaCreateForm extends BaseForm { return 'thelia_area_creation'; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Form/Area/AreaModificationForm.php b/core/lib/Thelia/Form/Area/AreaModificationForm.php index eefcb825a..03f4b2e46 100644 --- a/core/lib/Thelia/Form/Area/AreaModificationForm.php +++ b/core/lib/Thelia/Form/Area/AreaModificationForm.php @@ -25,7 +25,6 @@ namespace Thelia\Form\Area; use Symfony\Component\Validator\Constraints\GreaterThan; use Thelia\Form\Area\AreaCreateForm; - /** * Class AreaModificationForm * @package Thelia\Form\Shipping @@ -46,4 +45,4 @@ class AreaModificationForm extends AreaCreateForm { return 'thelia_area_modification'; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Form/Area/AreaPostageForm.php b/core/lib/Thelia/Form/Area/AreaPostageForm.php index ba24499e8..fa22ab908 100644 --- a/core/lib/Thelia/Form/Area/AreaPostageForm.php +++ b/core/lib/Thelia/Form/Area/AreaPostageForm.php @@ -29,7 +29,6 @@ use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; use Thelia\Core\Translation\Translator; - /** * Class AreaPostageForm * @package Thelia\Form\Area @@ -85,4 +84,4 @@ class AreaPostageForm extends BaseForm { return 'thelia_area_postage'; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Form/CountryModificationForm.php b/core/lib/Thelia/Form/CountryModificationForm.php index 68570425b..99c404e62 100644 --- a/core/lib/Thelia/Form/CountryModificationForm.php +++ b/core/lib/Thelia/Form/CountryModificationForm.php @@ -23,8 +23,6 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\GreaterThan; -use Symfony\Component\Validator\Constraints\NotBlank; -use Thelia\Core\Translation\Translator; class CountryModificationForm extends CountryCreationForm { diff --git a/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php b/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php index 81dd422b6..ea31b696b 100644 --- a/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php +++ b/core/lib/Thelia/Form/ShippingZone/ShippingZoneAddArea.php @@ -28,7 +28,6 @@ use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; - /** * Class ShippingZoneAddArea * @package Thelia\Form\ShippingZone @@ -84,4 +83,4 @@ class ShippingZoneAddArea extends BaseForm { return 'thelia_shippingzone_area'; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php b/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php index 5c4e5597b..dfa568334 100644 --- a/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php +++ b/core/lib/Thelia/Form/ShippingZone/ShippingZoneRemoveArea.php @@ -23,7 +23,6 @@ namespace Thelia\Form\ShippingZone; - /** * Class ShippingZoneRemoveArea * @package Thelia\Form\ShippingZone @@ -39,4 +38,4 @@ class ShippingZoneRemoveArea extends ShippingZoneAddArea { return 'thelia_shippingzone_remove_area'; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Form/TaxRuleCreationForm.php b/core/lib/Thelia/Form/TaxRuleCreationForm.php index be3556321..a5dcc1999 100644 --- a/core/lib/Thelia/Form/TaxRuleCreationForm.php +++ b/core/lib/Thelia/Form/TaxRuleCreationForm.php @@ -24,8 +24,6 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints\NotBlank; -use Thelia\Core\Translation\Translator; -use Thelia\Model\CountryQuery; class TaxRuleCreationForm extends BaseForm { diff --git a/core/lib/Thelia/Form/TaxRuleTaxListUpdateForm.php b/core/lib/Thelia/Form/TaxRuleTaxListUpdateForm.php index 1d96c7e4d..ea2d1f06b 100644 --- a/core/lib/Thelia/Form/TaxRuleTaxListUpdateForm.php +++ b/core/lib/Thelia/Form/TaxRuleTaxListUpdateForm.php @@ -34,7 +34,7 @@ class TaxRuleTaxListUpdateForm extends BaseForm protected function buildForm() { $countryList = array(); - foreach(CountryQuery::create()->find() as $country) { + foreach (CountryQuery::create()->find() as $country) { $countryList[$country->getId()] = $country->getId(); } @@ -96,7 +96,7 @@ class TaxRuleTaxListUpdateForm extends BaseForm public function verifyTaxList($value, ExecutionContextInterface $context) { $jsonType = new JsonType(); - if(!$jsonType->isValid($value)) { + if (!$jsonType->isValid($value)) { $context->addViolation("Tax list is not valid JSON"); } @@ -104,10 +104,10 @@ class TaxRuleTaxListUpdateForm extends BaseForm /* check we have 2 level max */ - foreach($taxList as $taxLevel1) { - if(is_array($taxLevel1)) { - foreach($taxLevel1 as $taxLevel2) { - if(is_array($taxLevel2)) { + foreach ($taxList as $taxLevel1) { + if (is_array($taxLevel1)) { + foreach ($taxLevel1 as $taxLevel2) { + if (is_array($taxLevel2)) { $context->addViolation("Bad tax list JSON"); } else { $taxModel = TaxQuery::create()->findPk($taxLevel2); diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 6cfc79d28..83636b921 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -53,10 +53,9 @@ abstract class BaseModule extends ContainerAware } - public function activate($moduleModel = null) { - if(null === $moduleModel) { + if (null === $moduleModel) { $moduleModel = $this->getModuleModel(); } @@ -64,7 +63,7 @@ abstract class BaseModule extends ContainerAware $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); $con->beginTransaction(); try { - if($this->preActivation($con)) { + if ($this->preActivation($con)) { $moduleModel->setActivate(self::IS_ACTIVATED); $moduleModel->save($con); $this->postActivation($con); @@ -79,14 +78,14 @@ abstract class BaseModule extends ContainerAware public function deActivate($moduleModel = null) { - if(null === $moduleModel) { + if (null === $moduleModel) { $moduleModel = $this->getModuleModel(); } if ($moduleModel->getActivate() == self::IS_ACTIVATED) { $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); $con->beginTransaction(); try { - if($this->preDeactivation($con)) { + if ($this->preDeactivation($con)) { $moduleModel->setActivate(self::IS_NOT_ACTIVATED); $moduleModel->save($con); $this->postDeactivation($con); @@ -215,7 +214,6 @@ abstract class BaseModule extends ContainerAware return $moduleModel; } - public function getCode() { if (null === $this->reflected) { @@ -225,8 +223,8 @@ abstract class BaseModule extends ContainerAware return basename(dirname($this->reflected->getFileName())); } - public function install(){ - + public function install() + { } public function preActivation(ConnectionInterface $con = null) diff --git a/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php b/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php index 2d679cfd0..49a7d5a68 100644 --- a/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php +++ b/core/lib/Thelia/Module/Exception/InvalidXmlDocumentException.php @@ -23,7 +23,6 @@ namespace Thelia\Module\Exception; - /** * Class InvalidXmlDocumentException * @package Thelia\Module\Exception @@ -32,4 +31,4 @@ namespace Thelia\Module\Exception; class InvalidXmlDocumentException extends \RuntimeException { -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Module/ModuleDescriptorValidator.php b/core/lib/Thelia/Module/ModuleDescriptorValidator.php index 679373e02..8f8c89d4a 100644 --- a/core/lib/Thelia/Module/ModuleDescriptorValidator.php +++ b/core/lib/Thelia/Module/ModuleDescriptorValidator.php @@ -24,13 +24,12 @@ namespace Thelia\Module; use Thelia\Module\Exception\InvalidXmlDocumentException; - /** * Class ModuleDescriptorValidator * @package Thelia\Module * @author Manuel Raynaud */ -class ModuleDescriptorValidator +class ModuleDescriptorValidator { private $xsd_file; @@ -44,7 +43,7 @@ class ModuleDescriptorValidator $dom = new \DOMDocument(); if ($dom->load($xml_file)) { - if($dom->schemaValidate($this->xsd_file)) { + if ($dom->schemaValidate($this->xsd_file)) { return true; } } @@ -52,9 +51,10 @@ class ModuleDescriptorValidator throw new InvalidXmlDocumentException(sprintf("%s file is not a valid file", $xml_file)); } - public function getDescriptor($xml_file) { + public function getDescriptor($xml_file) + { $this->validate($xml_file); return @simplexml_load_file($xml_file); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Module/ModuleManagement.php b/core/lib/Thelia/Module/ModuleManagement.php index 84e6c6457..99cc5ca9f 100644 --- a/core/lib/Thelia/Module/ModuleManagement.php +++ b/core/lib/Thelia/Module/ModuleManagement.php @@ -32,13 +32,12 @@ use Thelia\Model\Module; use Thelia\Model\ModuleI18n; use Thelia\Model\ModuleQuery; - /** * Class ModuleManagement * @package Thelia\Module * @author Manuel Raynaud */ -class ModuleManagement +class ModuleManagement { protected $baseModuleDir; protected $reflected; @@ -59,16 +58,16 @@ class ModuleManagement $descriptorValidator = new ModuleDescriptorValidator(); foreach ($finder as $file) { $content = $descriptorValidator->getDescriptor($file->getRealPath()); - $reflected = new \ReflectionClass((string)$content->fullnamespace); + $reflected = new \ReflectionClass((string) $content->fullnamespace); $code = basename(dirname($reflected->getFileName())); - if(null === ModuleQuery::create()->filterByCode($code)->findOne()) { + 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) + ->setFullNamespace((string) $content->fullnamespace) ->setType($this->getModuleType($reflected)) ->setActivate(0) ->save($con); @@ -76,7 +75,7 @@ class ModuleManagement $this->saveDescription($module, $content, $con); $con->commit(); - } catch(PropelException $e) { + } catch (PropelException $e) { $con->rollBack(); throw $e; } @@ -88,8 +87,7 @@ class ModuleManagement private function saveDescription(Module $module,\SimpleXMLElement $content, ConnectionInterface $con) { - foreach($content->descriptive as $description) - { + foreach ($content->descriptive as $description) { $locale = $description->attributes()->locale; $moduleI18n = new ModuleI18n(); @@ -107,15 +105,14 @@ class ModuleManagement private function getModuleType(\ReflectionClass $reflected) { - if($reflected->implementsInterface('Thelia\Module\DeliveryModuleInterface')) { + if ($reflected->implementsInterface('Thelia\Module\DeliveryModuleInterface')) { return BaseModule::DELIVERY_MODULE_TYPE; - } else if($reflected->implementsInterface('Thelia\Module\PaymentModuleInterface')) { + } elseif ($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/Tests/Action/BaseAction.php b/core/lib/Thelia/Tests/Action/BaseAction.php index f0027fd21..c07c07115 100644 --- a/core/lib/Thelia/Tests/Action/BaseAction.php +++ b/core/lib/Thelia/Tests/Action/BaseAction.php @@ -23,7 +23,6 @@ namespace Thelia\Tests\Action; - /** * Class BaseAction * @package Thelia\Tests\Action\ImageTest @@ -41,4 +40,4 @@ class BaseAction extends \PHPUnit_Framework_TestCase return $container; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 7aa819346..f527026bf 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -36,7 +36,6 @@ use Thelia\Model\ContentFolderQuery; use Thelia\Model\ContentQuery; use Thelia\Model\FolderQuery; - /** * Class ContentTest * @package Thelia\Tests\Action @@ -205,7 +204,7 @@ class ContentTest extends BaseAction $test = ContentFolderQuery::create() ->filterByContent($content) ->filterByFolder($folder); - } while($test->count() > 0); + } while ($test->count() > 0); $event = new ContentAddFolderEvent($content, $folder->getId()); @@ -267,10 +266,10 @@ class ContentTest extends BaseAction ->addAscendingOrderByColumn('RAND()') ->findOne(); - if(null === $folder) { + if (null === $folder) { $this->fail('use fixtures before launching test, there is no folder in database'); } return $folder; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index 903e1b77b..7ef88aa0d 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -31,7 +31,6 @@ use Thelia\Core\Event\Folder\FolderUpdateEvent; use Thelia\Core\Event\UpdatePositionEvent; use Thelia\Model\FolderQuery; - /** * Class FolderTest * @package Thelia\Tests\Action\ImageTest @@ -73,8 +72,6 @@ class FolderTest extends BaseAction { $folder = $this->getRandomFolder(); - - $visible = !$folder->getVisible(); $event = new FolderUpdateEvent($folder->getId()); @@ -147,7 +144,7 @@ class FolderTest extends BaseAction ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); - if(null === $folder) { + if (null === $folder) { $this->fail('use fixtures before launching test, there is no folder in database'); } @@ -169,7 +166,7 @@ class FolderTest extends BaseAction ->filterByPosition(1) ->findOne(); - if(null === $folder) { + if (null === $folder) { $this->fail('use fixtures before launching test, there is no folder in database'); } @@ -191,7 +188,7 @@ class FolderTest extends BaseAction ->filterByPosition(1, Criteria::GREATER_THAN) ->findOne(); - if(null === $folder) { + if (null === $folder) { $this->fail('use fixtures before launching test, there is no folder in database'); } @@ -215,10 +212,10 @@ class FolderTest extends BaseAction ->addAscendingOrderByColumn('RAND()') ->findOne(); - if(null === $folder) { + if (null === $folder) { $this->fail('use fixtures before launching test, there is no folder in database'); } return $folder; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php index 0dbbc73bb..1e6f6f258 100755 --- a/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php +++ b/core/lib/Thelia/Tests/TaxEngine/CalculatorTest.php @@ -127,7 +127,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $taxRulesCollection = new ObjectCollection(); $aProduct = ProductQuery::create()->findOne(); - if(null === $aProduct) { + if (null === $aProduct) { return; } @@ -169,7 +169,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $taxRulesCollection->setModel('\Thelia\Model\Tax'); $aProduct = ProductQuery::create()->findOne(); - if(null === $aProduct) { + if (null === $aProduct) { return; } @@ -214,7 +214,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $taxRulesCollection->append($tax); $aProduct = ProductQuery::create()->findOne(); - if(null === $aProduct) { + if (null === $aProduct) { return; } @@ -270,7 +270,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase $taxRulesCollection->append($tax); $aProduct = ProductQuery::create()->findOne(); - if(null === $aProduct) { + if (null === $aProduct) { return; } diff --git a/templates/admin/default/modules.html b/templates/admin/default/modules.html index 57bb14bf1..c94ba8789 100644 --- a/templates/admin/default/modules.html +++ b/templates/admin/default/modules.html @@ -88,7 +88,7 @@ }).done(function(){ $("#loading-event").remove(); }) - .fail(function(jqXHR, textStatus, errorThrown){ + .fail(function(jqXHR, textStatus, errorThrown){ $("#loading-event").remove(); $('#module-failed-body').html(jqXHR.responseJSON.error); $("#module-failed").modal("show"); From e602884ce019167781416423aba85438af3f57f0 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 18 Oct 2013 10:06:42 +0200 Subject: [PATCH 13/26] end module activation --- core/lib/Thelia/Action/Module.php | 4 +--- core/lib/Thelia/Module/BaseModule.php | 10 ++++++---- local/modules/Cheque/Cheque.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 213024e16..040c9f7b4 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -53,9 +53,7 @@ class Module extends BaseAction implements EventSubscriberInterface } } - if ($module->isModified()) { - $event->setModule($module); - } + $event->setModule($module); $this->cacheClear(); } diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 83636b921..598e25baa 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -135,17 +135,19 @@ abstract class BaseModule extends ContainerAware } } - public function deployImageFolder(Module $module, $folderPath) + public function deployImageFolder(Module $module, $folderPath, ConnectionInterface $con = null) { try { $directoryBrowser = new \DirectoryIterator($folderPath); } catch (\UnexpectedValueException $e) { throw $e; } + if(null === $con) { + $con = \Propel\Runtime\Propel::getConnection( + ModuleImageTableMap::DATABASE_NAME + ); + } - $con = \Propel\Runtime\Propel::getConnection( - ModuleImageTableMap::DATABASE_NAME - ); /* browse the directory */ $imagePosition = 1; diff --git a/local/modules/Cheque/Cheque.php b/local/modules/Cheque/Cheque.php index 324728990..cebaff146 100755 --- a/local/modules/Cheque/Cheque.php +++ b/local/modules/Cheque/Cheque.php @@ -66,7 +66,7 @@ class Cheque extends BaseModule implements PaymentModuleInterface /* insert the images from image folder if first module activation */ $module = $this->getModuleModel(); if(ModuleImageQuery::create()->filterByModule($module)->count() == 0) { - $this->deployImageFolder($module, sprintf('%s/images', __DIR__)); + $this->deployImageFolder($module, sprintf('%s/images', __DIR__), $con); } /* set module title */ From 1545987d5151c5bce7a318469f83a9fd272c5a2c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 09:29:52 +0200 Subject: [PATCH 14/26] update insert script --- install/insert.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install/insert.sql b/install/insert.sql index 8e6585a5b..ed5d7342b 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -39,6 +39,8 @@ INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namesp (4, 'FakeCB', 3, 0, 2, 'FakeCB\\FakeCB', NOW(), NOW()); INSERT INTO `module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES +('1', 'en_US', 'Debug bar', NULL, NULL, NULL), +('1', 'fr_FR', 'Debug bar', NULL, NULL, NULL), ('2', 'en_US', '72h delivery', NULL, NULL, NULL), ('2', 'fr_FR', 'Livraison par colissimo en 72h', NULL, NULL, NULL); From a10fa2034045da921726a022751447002e3f95d8 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 10:26:51 +0200 Subject: [PATCH 15/26] create event object for module delete action --- core/lib/Thelia/Action/Module.php | 11 +++- .../Thelia/Config/Resources/routing/admin.xml | 4 ++ .../Controller/Admin/ModuleController.php | 18 ++++++ .../Core/Event/Module/ModuleDeleteEvent.php | 61 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 5 ++ .../admin/default/includes/module-block.html | 2 +- templates/admin/default/modules.html | 9 ++- 7 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/Module/ModuleDeleteEvent.php diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 040c9f7b4..4d286d789 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -22,10 +22,13 @@ /*************************************************************************************/ namespace Thelia\Action; +use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Cache\CacheEvent; +use Thelia\Core\Event\Module\ModuleDeleteEvent; use Thelia\Core\Event\Module\ModuleToggleActivationEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\Map\ModuleTableMap; use Thelia\Model\ModuleQuery; use Thelia\Module\BaseModule; @@ -59,6 +62,11 @@ class Module extends BaseAction implements EventSubscriberInterface } } + public function delete(ModuleDeleteEvent $event) + { + + } + protected function cacheClear() { $cacheEvent = new CacheEvent($this->container->getParameter('kernel.cache_dir')); @@ -89,7 +97,8 @@ class Module extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - TheliaEvents::MODULE_TOGGLE_ACTIVATION => array('toggleActivation', 128) + TheliaEvents::MODULE_TOGGLE_ACTIVATION => array('toggleActivation', 128), + TheliaEvents::MODULE_DELETE => array('delete', 128) ); } } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 7cc0c0f9f..9c6ead6c7 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -825,6 +825,10 @@ \d+ + + Thelia\Controller\Admin\ModuleController::deleteAction + + diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index c7d020d58..2be309321 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\Module\ModuleDeleteEvent; use Thelia\Core\Event\Module\ModuleToggleActivationEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Module\ModuleManagement; @@ -82,4 +83,21 @@ class ModuleController extends BaseAdminController return $response; } + + public function deleteAction() + { + if (null !== $response = $this->checkAuth("admin.module.delete")) return $response; + + try { + + $module_id = $this->getRequest()->get('module_id'); + + $deleteEvent = new ModuleDeleteEvent($module_id); + + $this->dispatch(TheliaEvents::MODULE_DELETE, $deleteEvent); + + } catch (\Exception $e) { + + } + } } diff --git a/core/lib/Thelia/Core/Event/Module/ModuleDeleteEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleDeleteEvent.php new file mode 100644 index 000000000..5622e3931 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Module/ModuleDeleteEvent.php @@ -0,0 +1,61 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Module; + + +/** + * Class ModuleDeleteEvent + * @package Thelia\Core\Event\Module + * @author Manuel Raynaud + */ +class ModuleDeleteEvent extends ModuleEvent +{ + /** + * @var int module id + */ + protected $module_id; + + function __construct($module_id) + { + $this->module_id = $module_id; + } + + /** + * @param int $module_id + */ + public function setModuleId($module_id) + { + $this->module_id = $module_id; + } + + /** + * @return int + */ + public function getModuleId() + { + return $this->module_id; + } + + +} \ 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 a28c7ffb7..7c2bc17a5 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -665,6 +665,11 @@ final class TheliaEvents */ const MODULE_TOGGLE_ACTIVATION = 'thelia.module.toggleActivation'; + /** + * sent when a module is deleted + */ + const MODULE_DELETE = 'thelia.module.delete'; + /** * sent for clearing cache */ diff --git a/templates/admin/default/includes/module-block.html b/templates/admin/default/includes/module-block.html index dd499393f..658557d4e 100644 --- a/templates/admin/default/includes/module-block.html +++ b/templates/admin/default/includes/module-block.html @@ -48,7 +48,7 @@ {/loop} {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.modules.delete"} - + {/loop}
diff --git a/templates/admin/default/modules.html b/templates/admin/default/modules.html index c94ba8789..847a5ea4a 100644 --- a/templates/admin/default/modules.html +++ b/templates/admin/default/modules.html @@ -40,8 +40,7 @@ {* Delete module confirmation dialog *} {capture "delete_module_dialog"} - - + {/capture} {include @@ -51,7 +50,7 @@ dialog_title = {intl l="Delete a module"} dialog_message = {intl l="Do you really want to delete this module ?"} - form_action = {url path='/admin/modules/delete'} + form_action = {url path='/admin/configuration/modules/delete'} form_content = {$smarty.capture.delete_module_dialog nofilter} } @@ -95,6 +94,10 @@ }); }); + + $(".module-delete-action").click(function(){ + $("#delete_module_id").val($(this).data("id")); + }); }); {/block} \ No newline at end of file From 28b74234433f2280d76591beb751e7f7a58ae6dc Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 11:30:19 +0200 Subject: [PATCH 16/26] end module removal --- core/lib/Thelia/Action/Module.php | 33 ++++++++++++++++++- .../Controller/Admin/ModuleController.php | 17 +++++++++- .../Thelia/Core/Event/Module/ModuleEvent.php | 5 +++ core/lib/Thelia/Module/BaseModule.php | 4 +-- templates/admin/default/modules.html | 1 + 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 4d286d789..5eaa227ad 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -24,6 +24,7 @@ namespace Thelia\Action; use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Filesystem\Filesystem; use Thelia\Core\Event\Cache\CacheEvent; use Thelia\Core\Event\Module\ModuleDeleteEvent; use Thelia\Core\Event\Module\ModuleToggleActivationEvent; @@ -64,7 +65,37 @@ class Module extends BaseAction implements EventSubscriberInterface public function delete(ModuleDeleteEvent $event) { - + if (null !== $module = ModuleQuery::create()->findPk($event->getModuleId())) { + $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); + $con->beginTransaction(); + + try { + if(null === $module->getFullNamespace()) { + throw new \LogicException('can not instanciante this module if namespace is null. Maybe the model is not loaded ?'); + } + + $reflected = new \ReflectionClass($module->getFullNamespace()); + $instance = $reflected->newInstance(); + $instance->setContainer($this->container); + + $path = dirname($reflected->getFileName()); + + $instance->destroy($con); + + $fs = new Filesystem(); + $fs->remove($path); + + $module->delete($con); + + $con->commit(); + + $event->setModule($module); + + } catch (\Exception $e) { + $con->rollBack(); + throw $e; + } + } } protected function cacheClear() diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 2be309321..a10e9aa8a 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -88,6 +88,7 @@ class ModuleController extends BaseAdminController { if (null !== $response = $this->checkAuth("admin.module.delete")) return $response; + $message = null; try { $module_id = $this->getRequest()->get('module_id'); @@ -96,8 +97,22 @@ class ModuleController extends BaseAdminController $this->dispatch(TheliaEvents::MODULE_DELETE, $deleteEvent); - } catch (\Exception $e) { + if($deleteEvent->hasModule() === false) { + throw new \LogicException( + $this->getTranslator()->trans("No %obj was updated.", array('%obj' => 'Module'))); + } + } catch (\Exception $e) { + \Thelia\Log\Tlog::getInstance()->error(sprintf("error during module removal : %s", $message)); + $message = $e->getMessage(); + } + + if($message) { + return $this->render("modules", array( + "error_message" => $message + )); + } else { + $this->redirectToRoute('admin.module'); } } } diff --git a/core/lib/Thelia/Core/Event/Module/ModuleEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php index c37b2b995..583a3afc9 100644 --- a/core/lib/Thelia/Core/Event/Module/ModuleEvent.php +++ b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php @@ -62,4 +62,9 @@ class ModuleEvent extends ActionEvent return $this->module; } + public function hasModule() + { + return null !== $this->module; + } + } diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 598e25baa..79acdd4b3 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -225,7 +225,7 @@ abstract class BaseModule extends ContainerAware return basename(dirname($this->reflected->getFileName())); } - public function install() + public function install(ConnectionInterface $con = null) { } @@ -249,7 +249,7 @@ abstract class BaseModule extends ContainerAware } - public function destroy() + public function destroy(ConnectionInterface $con = null) { } diff --git a/templates/admin/default/modules.html b/templates/admin/default/modules.html index 847a5ea4a..86c336a04 100644 --- a/templates/admin/default/modules.html +++ b/templates/admin/default/modules.html @@ -25,6 +25,7 @@
+ {if $error_message}
{$error_message}
{/if} {include file="includes/module-block.html" module_type="1" caption_title={intl l='Classic modules'}} {include file="includes/module-block.html" module_type="2" caption_title={intl l='Delivery modules'}} {include file="includes/module-block.html" module_type="3" caption_title={intl l='Payment modules'}} From 6c6227c77a571ed4f794cd49ee6b16f238a797e4 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 11:32:50 +0200 Subject: [PATCH 17/26] clear cache when a module is removed --- core/lib/Thelia/Action/Module.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 5eaa227ad..ddc285960 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -90,6 +90,7 @@ class Module extends BaseAction implements EventSubscriberInterface $con->commit(); $event->setModule($module); + $this->cacheClear(); } catch (\Exception $e) { $con->rollBack(); From a16fb0d8904b545210b01e9cecc15245a07904a2 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 11:40:45 +0200 Subject: [PATCH 18/26] fiw test suite --- .../Command/{CacheClearTest.php => CacheClearTestSaved.php} | 4 ++++ 1 file changed, 4 insertions(+) rename core/lib/Thelia/Tests/Command/{CacheClearTest.php => CacheClearTestSaved.php} (96%) diff --git a/core/lib/Thelia/Tests/Command/CacheClearTest.php b/core/lib/Thelia/Tests/Command/CacheClearTestSaved.php similarity index 96% rename from core/lib/Thelia/Tests/Command/CacheClearTest.php rename to core/lib/Thelia/Tests/Command/CacheClearTestSaved.php index 00d54cb3b..0d88806f0 100755 --- a/core/lib/Thelia/Tests/Command/CacheClearTest.php +++ b/core/lib/Thelia/Tests/Command/CacheClearTestSaved.php @@ -115,6 +115,10 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase $container->setParameter("kernel.cache_dir", $this->cache_dir); + $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + + $container->set("event_dispatcher", $dispatcher); + return $container; } From 9ca612ae0dbe56dec335ba5b39a62cdccf1dcd27 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 11:54:15 +0200 Subject: [PATCH 19/26] not allowed to delete default country --- core/lib/Thelia/Model/Country.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index e254d4a5e..13d706839 100755 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -47,6 +47,10 @@ class Country extends BaseCountry public function preDelete(ConnectionInterface $con = null) { + if($this->getByDefault()) { + return false; + } + $this->dispatchEvent(TheliaEvents::BEFORE_DELETECOUNTRY, new CountryEvent($this)); return true; From 0ba6a599a9821523c36ec2adafdba53cc54f2209 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 12:08:19 +0200 Subject: [PATCH 20/26] add some verification on country default trigger --- core/lib/Thelia/Model/Country.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 13d706839..e64bd4609 100755 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -13,6 +13,9 @@ class Country extends BaseCountry public function toggleDefault() { + if($this->getId() === null) { + throw new \RuntimeException("impossible to just uncheck default country, choose a new one"); + } CountryQuery::create() ->filterByByDefault(1) ->update(array('ByDefault' => 0)); From 3dcb399d01ae7ca0ac596336b6ca36d8f626c87a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 12:21:33 +0200 Subject: [PATCH 21/26] fix cartItem updateQuantity method --- core/lib/Thelia/Model/CartItem.php | 9 ++++++++- templates/default/product.html | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index 25a4f44aa..427e7e735 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -60,7 +60,14 @@ class CartItem extends BaseCartItem } } - $this->setQuantity($value); + $this->addQuantity($value); + + return $this; + } + + public function addQuantity($quantity) + { + $this->setQuantity($this->getQuantity() + $quantity); return $this; } diff --git a/templates/default/product.html b/templates/default/product.html index b7b203bc9..38cea5c6b 100644 --- a/templates/default/product.html +++ b/templates/default/product.html @@ -138,6 +138,10 @@ {form_hidden_fields form=$form} + {form_field form=$form field="append"} + + {/form_field} + {if $form_error}
{$form_error_message}
{/if} From ee57c7cbcf566caa27d2843c5e6744b08b14a75c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 12:34:31 +0200 Subject: [PATCH 22/26] fix issue #35 --- core/lib/Thelia/Model/ConfigQuery.php | 2 +- install/insert.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Model/ConfigQuery.php b/core/lib/Thelia/Model/ConfigQuery.php index 7f65b103d..fb8d6fe90 100755 --- a/core/lib/Thelia/Model/ConfigQuery.php +++ b/core/lib/Thelia/Model/ConfigQuery.php @@ -56,7 +56,7 @@ class ConfigQuery extends BaseConfigQuery { public static function getPageNotFoundView() { - return self::read("page_not_found_view", '404'); + return self::read("page_not_found_view", '404.html'); } public static function getPassedUrlView() diff --git a/install/insert.sql b/install/insert.sql index ed5d7342b..b4ec483b4 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -19,7 +19,7 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat ('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()), ('document_cache_dir_from_web_root', 'cache/documents', 0, 0, NOW(), NOW()), ('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()), -('page_not_found_view', '404', 0, 0, NOW(), NOW()), +('page_not_found_view', '404.html', 0, 0, NOW(), NOW()), ('passed_url_view', 'passed-url', 0, 0, NOW(), NOW()), ('use_tax_free_amounts', 0, 0, 0, NOW(), NOW()), ('process_assets', '1', 0, 0, NOW(), NOW()), From 48d112c73699f3d038c8c3b8af9a1f11c4e5baec Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 14:21:32 +0200 Subject: [PATCH 23/26] update countries list --- install/insert.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/install/insert.sql b/install/insert.sql index b4ec483b4..991eb7892 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -277,7 +277,6 @@ INSERT INTO `country` (`id`, `area_id`, `isocode`, `isoalpha2`, `isoalpha3`, `by (187, NULL, '862', 'VE', 'VEN', 0, NOW(), NOW()), (188, NULL, '704', 'VN', 'VNM', 0, NOW(), NOW()), (189, NULL, '887', 'YE', 'YEM', 0, NOW(), NOW()), -(190, NULL, '807', 'MK', 'MKD', 0, NOW(), NOW()), (191, NULL, '180', 'CD', 'COD', 0, NOW(), NOW()), (192, NULL, '894', 'ZM', 'ZMB', 0, NOW(), NOW()), (193, NULL, '716', 'ZW', 'ZWE', 0, NOW(), NOW()), @@ -917,9 +916,6 @@ INSERT INTO `country_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `po (189, 'en_US', 'Yemen', '', '', ''), (189, 'es_ES', 'Yemen', '', '', ''), (189, 'fr_FR', 'Yémen', '', '', ''), -(190, 'en_US', 'Yougoslavia', '', '', ''), -(190, 'es_ES', 'Yugoslavia', '', '', ''), -(190, 'fr_FR', 'Yougoslavie', '', '', ''), (191, 'en_US', 'Zaire', '', '', ''), (191, 'es_ES', 'Zaire', '', '', ''), (191, 'fr_FR', 'Zaïre', '', '', ''), From 043eab7ccfcae9c9e31d4820a2785425940e2e43 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 14:28:03 +0200 Subject: [PATCH 24/26] fix typo in product breadcrumb --- templates/default/product.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/default/product.html b/templates/default/product.html index 38cea5c6b..c0a102d37 100644 --- a/templates/default/product.html +++ b/templates/default/product.html @@ -5,7 +5,7 @@ {* Breadcrumb *} {block name='no-return-functions' append} - {$sBreadcrumb = []} + {$breadcrumbs = []} {loop type="product" name="product_breadcrumb" id="{product attr="id"}"} {loop name="category_path" type="category-path" category="{$DEFAULT_CATEGORY}"} {$breadcrumbs[] = ['title' => {$TITLE}, 'url'=> {$URL}]} From dff112dba42df8a181c1d5dbd4aece43da35c71b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 14:34:08 +0200 Subject: [PATCH 25/26] fix issue #43 --- core/lib/Thelia/Rewriting/RewritingRetriever.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index dfdbab05c..a4da9c031 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -71,7 +71,7 @@ class RewritingRetriever $this->rewrittenUrl = null; $this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView); if($this->search !== null) { - $this->rewrittenUrl = $this->search->getUrl(); + $this->rewrittenUrl = URL::getInstance()->absoluteUrl($this->search->getUrl()); } } From 1f55d569ef4c9ae61b0bd6f9f2efca1f54cd676c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 15:15:17 +0200 Subject: [PATCH 26/26] change place where absolute url is create when rewritten url is enabled --- core/lib/Thelia/Rewriting/RewritingRetriever.php | 2 +- core/lib/Thelia/Tools/URL.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index a4da9c031..dfdbab05c 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -71,7 +71,7 @@ class RewritingRetriever $this->rewrittenUrl = null; $this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView); if($this->search !== null) { - $this->rewrittenUrl = URL::getInstance()->absoluteUrl($this->search->getUrl()); + $this->rewrittenUrl = $this->search->getUrl(); } } diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 3e137e5e4..d00c5c4ab 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -199,7 +199,7 @@ class URL public function retrieve($view, $viewId, $viewLocale) { if (ConfigQuery::isRewritingEnable()) { - $this->retriever->loadViewUrl($view, $viewLocale, $viewId); + URL::getInstance()->absoluteUrl($this->retriever->loadViewUrl($view, $viewLocale, $viewId)); } else { $allParametersWithoutView = array(); $allParametersWithoutView['locale'] = $viewLocale;