/**
  * You can modify the container here before it is dumped to PHP code.
  *
  * @param ContainerBuilder $container
  *
  * @api
  */
 public function process(ContainerBuilder $container)
 {
     try {
         $chainRouter = $container->getDefinition("router.chainRequest");
     } catch (InvalidArgumentException $e) {
         return;
     }
     foreach ($container->findTaggedServiceIds("router.register") as $id => $attributes) {
         $priority = isset($attributes[0]["priority"]) ? $attributes[0]["priority"] : 0;
         $router = $container->getDefinition($id);
         $router->addMethodCall("setOption", array("matcher_cache_class", $container::camelize("ProjectUrlMatcher" . $id)));
         $router->addMethodCall("setOption", array("generator_cache_class", $container::camelize("ProjectUrlGenerator" . $id)));
         $chainRouter->addMethodCall("add", array(new Reference($id), $priority));
     }
     if (defined("THELIA_INSTALL_MODE") === false) {
         $modules = \Thelia\Model\ModuleQuery::getActivated();
         foreach ($modules as $module) {
             $moduleBaseDir = $module->getBaseDir();
             $routingConfigFilePath = $module->getAbsoluteBaseDir() . DS . "Config" . DS . "routing.xml";
             if (file_exists($routingConfigFilePath)) {
                 $definition = new Definition($container->getParameter("router.class"), array(new Reference("router.module.xmlLoader"), $routingConfigFilePath, array("cache_dir" => $container->getParameter("kernel.cache_dir"), "debug" => $container->getParameter("kernel.debug"), "matcher_cache_class" => $container::camelize("ProjectUrlMatcher" . $moduleBaseDir), "generator_cache_class" => $container::camelize("ProjectUrlGenerator" . $moduleBaseDir)), new Reference("request.context")));
                 $container->setDefinition("router." . $moduleBaseDir, $definition);
                 $chainRouter->addMethodCall("add", array(new Reference("router." . $moduleBaseDir), 150));
             }
         }
     }
 }
 protected function processHook(ContainerBuilder $container, $definition)
 {
     foreach ($container->findTaggedServiceIds('hook.event_listener') as $id => $events) {
         $class = $container->getDefinition($id)->getClass();
         // the class must extends BaseHook
         $implementClass = HookDefinition::BASE_CLASS;
         if (!is_subclass_of($class, $implementClass)) {
             throw new \InvalidArgumentException(sprintf('Hook class "%s" must extends class "%s".', $class, $implementClass));
         }
         // retrieve the module id
         $properties = $container->getDefinition($id)->getProperties();
         $module = null;
         if (array_key_exists('module', $properties)) {
             $moduleCode = explode(".", $properties['module'])[1];
             if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
                 $module = $module->getId();
             }
         }
         foreach ($events as $event) {
             $this->registerHook($class, $module, $id, $event);
         }
     }
     // now we can add listeners for active hooks and active module
     $this->addHooksMethodCall($definition);
 }
 protected function checkValidInvoice()
 {
     $order = $this->getSession()->getOrder();
     if (null === $order || null === $order->getChoosenInvoiceAddress() || null === $order->getPaymentModuleId() || null === AddressQuery::create()->findPk($order->getChoosenInvoiceAddress()) || null === ModuleQuery::create()->findPk($order->getPaymentModuleId())) {
         throw new RedirectException($this->retrieveUrlFromRouteId('order.invoice'));
     }
 }
Exemple #4
0
 /**
  * Generates the content of the hook
  *
  * {hook name="hook_code" var1="value1" var2="value2" ... }
  *
  * This function create an event, feed it with the custom variables passed to the function (var1, var2, ...) and
  * dispatch it to the hooks that respond to it.
  *
  * The name of the event is `hook.{context}.{hook_code}` where :
  *      * context : the id of the context of the smarty render : 1: frontoffice, 2: backoffice, 3: email, 4: pdf
  *      * hook_code : the code of the hook
  *
  * The event collects all the fragments of text rendered in each modules functions that listen to this event.
  * Finally, this fragments are concatenated and injected in the template
  *
  * @param array        $params the params passed in the smarty function
  * @param \TheliaSmarty\Template\SmartyParser $smarty the smarty parser
  *
  * @return string the contents generated by modules
  */
 public function processHookFunction($params, &$smarty)
 {
     $hookName = $this->getParam($params, 'name');
     $module = intval($this->getParam($params, 'module', 0));
     $moduleCode = $this->getParam($params, 'modulecode', "");
     $type = $smarty->getTemplateDefinition()->getType();
     $event = new HookRenderEvent($hookName, $params);
     $event->setArguments($this->getArgumentsFromParams($params));
     $eventName = sprintf('hook.%s.%s', $type, $hookName);
     // this is a hook specific to a module
     if (0 === $module && "" !== $moduleCode) {
         if (null !== ($mod = ModuleQuery::create()->findOneByCode($moduleCode))) {
             $module = $mod->getId();
         }
     }
     if (0 !== $module) {
         $eventName .= '.' . $module;
     }
     $this->getDispatcher()->dispatch($eventName, $event);
     $content = trim($event->dump());
     if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) {
         $content = sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>%s', $hookName, $content);
     }
     $this->hookResults[$hookName] = $content;
     // support for compatibility with module_include
     if ($type === TemplateDefinition::BACK_OFFICE) {
         $content .= $this->moduleIncludeCompat($params, $smarty);
     }
     return $content;
 }
 /**
  * Test ModuleRefreshCommand
  */
 public function testModuleRefreshCommand()
 {
     $moduleManagement = new ModuleManagement();
     $moduleManagement->updateModules();
     $module = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
     if ($module !== null) {
         $module->delete();
         $application = new Application($this->getKernel());
         $moduleRefresh = new ModuleRefreshCommand();
         $moduleRefresh->setContainer($this->getContainer());
         $application->add($moduleRefresh);
         $command = $application->find('module:refresh');
         $commandTester = new CommandTester($command);
         $commandTester->execute(['command' => $command->getName()]);
         $expected = $module;
         $actual = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
         $this->assertEquals($expected->getCode(), $actual->getCode(), 'Last standard module code must be same after deleting this one and calling module:refresh');
         $this->assertEquals($expected->getType(), $actual->getType(), 'Last standard module type must be same after deleting this one and calling module:refresh');
         $this->assertEquals($expected->getFullNamespace(), $actual->getFullNamespace(), 'Last standard module namespace must be same after deleting this one and calling module:refresh');
         // Restore activation status
         $actual->setActivate($expected->getActivate())->save();
     } else {
         $this->markTestIncomplete('This test cannot be complete without at least one standard module.');
     }
 }
 public function verifyModuleId($value, ExecutionContextInterface $context)
 {
     $module = ModuleQuery::create()->findPk($value);
     if (null === $module) {
         $context->addViolation(Translator::getInstance()->trans("Module ID not found"));
     }
 }
 protected function buildForm($change_mode = false)
 {
     $this->formBuilder->add("id", "hidden", array("required" => true, "constraints" => array(new Constraints\NotBlank(), new Constraints\Callback(array("methods" => array(array($this, "verifyProfileId")))))));
     foreach (ModuleQuery::create()->find() as $module) {
         $this->formBuilder->add(self::MODULE_ACCESS_FIELD_PREFIX . ':' . str_replace(".", ":", $module->getCode()), "choice", array("choices" => array(AccessManager::VIEW => AccessManager::VIEW, AccessManager::CREATE => AccessManager::CREATE, AccessManager::UPDATE => AccessManager::UPDATE, AccessManager::DELETE => AccessManager::DELETE), "attr" => array("tag" => "modules", "module_code" => $module->getCode()), "multiple" => true, "constraints" => array()));
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $moduleCode = $this->formatModuleName($input->getArgument("module"));
     $module = ModuleQuery::create()->findOneByCode($moduleCode);
     if (null === $module) {
         throw new \RuntimeException(sprintf("module %s not found", $moduleCode));
     }
     if ($module->getActivate() == BaseModule::IS_NOT_ACTIVATED) {
         throw new \RuntimeException(sprintf("module %s is already deactivated", $moduleCode));
     }
     try {
         $event = new ModuleToggleActivationEvent($module->getId());
         $module = ModuleQuery::create()->findPk($module->getId());
         if ($module->getMandatory() == BaseModule::IS_MANDATORY) {
             if (!$this->askConfirmation($input, $output)) {
                 return;
             }
             $event->setAssumeDeactivate(true);
         }
         if ($input->getOption("with-dependencies")) {
             $event->setRecursive(true);
         }
         $this->getDispatcher()->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $event);
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf("Deactivation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()));
     }
     //impossible to change output class in CommandTester...
     if (method_exists($output, "renderBlock")) {
         $output->renderBlock(array('', sprintf("Deactivation succeed for module %s", $moduleCode), ''), "bg=green;fg=black");
     }
 }
Exemple #9
0
 /**
  * Process theliaModule template inclusion function
  *
  * This function accepts two parameters:
  *
  * - location : this is the location in the admin template. Example: folder-edit'. The function will search for
  *   AdminIncludes/<location>.html file, and fetch it as a Smarty template.
  * - countvar : this is the name of a template variable where the number of found modules includes will be assigned.
  *
  * @param array                     $params
  * @param \Smarty_Internal_Template $template
  * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty
  *
  * @return string
  */
 public function theliaModule($params, \Smarty_Internal_Template $template)
 {
     $content = null;
     $count = 0;
     if (false !== ($location = $this->getParam($params, 'location', false))) {
         if ($this->debug === true && $this->request->get('SHOW_INCLUDE')) {
             echo sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>', $location);
         }
         $moduleLimit = $this->getParam($params, 'module', null);
         $modules = ModuleQuery::getActivated();
         /** @var \Thelia\Model\Module $module */
         foreach ($modules as $module) {
             if (null !== $moduleLimit && $moduleLimit != $module->getCode()) {
                 continue;
             }
             $file = $module->getAbsoluteAdminIncludesPath() . DS . $location . '.html';
             if (file_exists($file)) {
                 $output = trim(file_get_contents($file));
                 if (!empty($output)) {
                     $content .= $output;
                     $count++;
                 }
             }
         }
     }
     if (false !== ($countvarname = $this->getParam($params, 'countvar', false))) {
         $template->assign($countvarname, $count);
     }
     if (!empty($content)) {
         return $template->fetch(sprintf("string:%s", $content));
     }
     return "";
 }
 public function setUp()
 {
     $stubContainer = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')->disableOriginalConstructor()->getMock();
     $this->action = new ModuleHook($stubContainer, $this->getMockEventDispatcher());
     $this->module = ModuleQuery::create()->findOneByActivate(1);
     $this->hook = HookQuery::create()->findOneByActivate(true);
 }
 /**
  * @param  string                    $itemName the modume code
  * @return Module                    the module object
  * @throws \InvalidArgumentException if module was not found
  */
 protected function getModule($itemName)
 {
     if (null !== ($module = ModuleQuery::create()->findPk($itemName))) {
         return $module;
     }
     throw new \InvalidArgumentException($this->getTranslator()->trans("No module found for code '%item'", ['%item' => $itemName]));
 }
Exemple #12
0
 protected function isModuleActive($module_id)
 {
     if (null !== ($module = ModuleQuery::create()->findPk($module_id))) {
         return $module->getActivate();
     }
     return false;
 }
Exemple #13
0
 public function updateModules()
 {
     $finder = new Finder();
     $finder->name('module.xml')->in($this->baseModuleDir . '/*/Config');
     $descriptorValidator = new ModuleDescriptorValidator();
     foreach ($finder as $file) {
         $content = $descriptorValidator->getDescriptor($file->getRealPath());
         $reflected = new \ReflectionClass((string) $content->fullnamespace);
         $code = basename(dirname($reflected->getFileName()));
         $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             $module = ModuleQuery::create()->filterByCode($code)->findOne();
             if (null === $module) {
                 $module = new Module();
                 $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;
         }
     }
 }
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition('event_dispatcher')) {
         return;
     }
     $definition = $container->getDefinition('event_dispatcher');
     foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) {
         foreach ($events as $event) {
             $priority = isset($event['priority']) ? $event['priority'] : 0;
             if (!isset($event['event'])) {
                 throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
             }
             if (!isset($event['method'])) {
                 $event['method'] = 'on' . preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), function ($matches) {
                     return strtoupper($matches[0]);
                 }, $event['event']);
                 $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
             }
             $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
         }
     }
     foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) {
         // We must assume that the class value has been correctly filled, even if the service is created by a factory
         $class = $container->getDefinition($id)->getClass();
         $refClass = new \ReflectionClass($class);
         $interface = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
         if (!$refClass->implementsInterface($interface)) {
             throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
         }
         $definition->addMethodCall('addSubscriberService', array($id, $class));
     }
     // We have to check if Propel is initialized before registering hooks
     $managers = Propel::getServiceContainer()->getConnectionManagers();
     if (!array_key_exists('thelia', $managers)) {
         return;
     }
     foreach ($container->findTaggedServiceIds('hook.event_listener') as $id => $events) {
         $class = $container->getDefinition($id)->getClass();
         // the class must extends BaseHook
         $implementClass = HookDefinition::BASE_CLASS;
         if (!is_subclass_of($class, $implementClass)) {
             throw new \InvalidArgumentException(sprintf('Hook class "%s" must extends class "%s".', $class, $implementClass));
         }
         // retrieve the module id
         $properties = $container->getDefinition($id)->getProperties();
         $module = null;
         if (array_key_exists('module', $properties)) {
             $moduleCode = explode(".", $properties['module'])[1];
             if (null !== ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
                 $module = $module->getId();
             }
         }
         foreach ($events as $event) {
             $this->registerHook($class, $module, $id, $event);
         }
     }
     // now we can add listeners for active hooks and active module
     $this->addHooksMethodCall($definition);
 }
Exemple #15
0
 /**
  *
  * return false if CreditAccount module is not present
  *
  * @param ConnectionInterface $con
  * @return bool|void
  */
 public function preActivation(ConnectionInterface $con = null)
 {
     $module = ModuleQuery::create()->filterByCode('CreditAccount')->filterByActivate(self::IS_ACTIVATED)->findOne();
     if (null === $module) {
         throw new \RuntimeException(Translator::getInstance()->trans('CreditAccount must be installed and activated', [], 'loyalty'));
     }
     return true;
 }
Exemple #16
0
 public function verifyDeliveryModule($value, ExecutionContextInterface $context)
 {
     $module = ModuleQuery::create()->filterActivatedByTypeAndId(BaseModule::DELIVERY_MODULE_TYPE, $value)->findOne();
     if (null === $module) {
         $context->addViolation(Translator::getInstance()->trans("Delivery module ID not found"));
     } elseif (!$module->isDeliveryModule()) {
         $context->addViolation(sprintf(Translator::getInstance()->trans("delivery module %s is not a Thelia\\Module\\DeliveryModuleInterface"), $module->getCode()));
     }
 }
 protected function getModuleChoices()
 {
     $choices = array();
     $modules = ModuleQuery::getActivated();
     /** @var Module $module */
     foreach ($modules as $module) {
         $choices[$module->getId()] = $module->getTitle();
     }
     return $choices;
 }
 /**
  * Update module information, and invoke install() for new modules (e.g. modules
  * just discovered), or update() modules for which version number ha changed.
  *
  * @param SplFileInfo $file the module.xml file descriptor
  * @param ContainerInterface $container the container
  *
  * @return Module
  *
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function updateModule($file, ContainerInterface $container)
 {
     $descriptorValidator = $this->getDescriptorValidator();
     $content = $descriptorValidator->getDescriptor($file->getRealPath());
     $reflected = new \ReflectionClass((string) $content->fullnamespace);
     $code = basename(dirname($reflected->getFileName()));
     $version = (string) $content->version;
     $mandatory = intval($content->mandatory);
     $hidden = intval($content->hidden);
     $module = ModuleQuery::create()->filterByCode($code)->findOne();
     if (null === $module) {
         $module = new Module();
         $module->setActivate(0);
         $action = 'install';
     } elseif ($version !== $module->getVersion()) {
         $currentVersion = $module->getVersion();
         $action = 'update';
     } else {
         $action = 'none';
     }
     $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         $module->setCode($code)->setVersion($version)->setFullNamespace((string) $content->fullnamespace)->setType($this->getModuleType($reflected))->setCategory((string) $content->type)->setMandatory($mandatory)->setHidden($hidden)->save($con);
         // Update the module images, title and description when the module is installed, but not after
         // as these data may have been modified byt the administrator
         if ('install' === $action) {
             $this->saveDescription($module, $content, $con);
             if (isset($content->{"images-folder"}) && !$module->isModuleImageDeployed($con)) {
                 /** @var \Thelia\Module\BaseModule $moduleInstance */
                 $moduleInstance = $reflected->newInstance();
                 $imagesFolder = THELIA_MODULE_DIR . $code . DS . (string) $content->{"images-folder"};
                 $moduleInstance->deployImageFolder($module, $imagesFolder, $con);
             }
         }
         // Tell the module to install() or update()
         $instance = $module->createInstance();
         $instance->setContainer($container);
         if ($action == 'install') {
             $instance->install($con);
         } elseif ($action == 'update') {
             $instance->update($currentVersion, $version, $con);
         }
         if ($action !== 'none') {
             $instance->registerHooks();
         }
         $con->commit();
     } catch (\Exception $ex) {
         Tlog::getInstance()->addError("Failed to update module " . $module->getCode(), $ex);
         $con->rollBack();
         throw $ex;
     }
     return $module;
 }
 private function getModule(InputInterface $input)
 {
     $module = null;
     $moduleCode = $input->getArgument("module");
     if (!empty($moduleCode)) {
         if (null === ($module = ModuleQuery::create()->findOneByCode($moduleCode))) {
             throw new \RuntimeException(sprintf("Module %s does not exist.", $moduleCode));
         }
     }
     return $module;
 }
Exemple #20
0
 public function onMainBeforeContent(HookRenderEvent $event)
 {
     if ($this->securityContext->isGranted(["ADMIN"], [AdminResources::PRODUCT], [], [AccessManager::VIEW])) {
         $products = ProductQuery::create()->filterByVirtual(1)->filterByVisible(1)->count();
         if ($products > 0) {
             $deliveryModule = ModuleQuery::create()->retrieveVirtualProductDelivery();
             if (false === $deliveryModule) {
                 $event->add($this->render('virtual-delivery-warning.html'));
             }
         }
     }
 }
Exemple #21
0
 /**
  * @param LoopResult $loopResult
  *
  * @return LoopResult
  */
 public function parseResults(LoopResult $loopResult)
 {
     $moduleCode = $this->getModule();
     if (null === ($module = ModuleQuery::create()->filterByCode($moduleCode, Criteria::LIKE)->findOne())) {
         throw new \InvalidArgumentException("Module with code '{$moduleCode}' does not exists.");
     }
     $configValue = ModuleConfigQuery::create()->getConfigValue($module->getId(), $this->getVariable(), $this->getDefaultValue(), $this->getLocale());
     $loopResultRow = new LoopResultRow();
     $loopResultRow->set("VARIABLE", $this->getVariable())->set("VALUE", $configValue);
     $loopResult->addRow($loopResultRow);
     return $loopResult;
 }
 public function manageAcl(ModuleToggleActivationEvent $event)
 {
     if (null === ($module = ModuleQuery::create()->findPk($event->getModuleId()))) {
         return;
     }
     //In case of deactivation do nothing
     if ($module->getActivate() == BaseModule::IS_ACTIVATED) {
         return;
     }
     //In case of activation update acls
     $this->aclXmlFileloader->load($module);
 }
 /**
  * @covers ModuleListener::load()
  */
 public function testModuleConfigurationIsNotLoadedOnDeactivation()
 {
     // use this module for testing
     $testModule = ModuleQuery::create()->findOneByCode(CustomerGroupAcl::getModuleCode());
     // activate it
     $testModule->reload();
     $testModule->setActivate(true)->save();
     // we expect the ACL configuration for our module to NOT be loaded
     $this->aclXmlFileloader->expects($this->never())->method("load")->with($this->equalTo($testModule));
     // toggle the module
     $activationEvent = new ModuleToggleActivationEvent($testModule->getId());
     $this->dispatcher->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $activationEvent);
 }
Exemple #24
0
 public function checkValidDeliveryFunction($params, &$smarty)
 {
     $order = $this->request->getSession()->getOrder();
     /* Does address and module still exists ? We assume address owner can't change neither module type */
     if ($order !== null) {
         $checkAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress());
         $checkModule = ModuleQuery::create()->findPk($order->getDeliveryModuleId());
     }
     if (null === $order || null == $checkAddress || null === $checkModule) {
         throw new OrderException('Delivery must be defined', OrderException::UNDEFINED_DELIVERY, array('missing' => 1));
     }
     return "";
 }
 protected function getModuleChoices()
 {
     $choices = array();
     $modules = ModuleQuery::getActivated();
     /** @var Module $module */
     foreach ($modules as $module) {
         // Check if module defines a hook ID
         if (ModuleHookQuery::create()->filterByModuleId($module->getId())->count() > 0 || IgnoredModuleHookQuery::create()->filterByModuleId($module->getId())->count() > 0) {
             $choices[$module->getId()] = $module->getTitle();
         }
     }
     asort($choices);
     return $choices;
 }
 /**
  * Reorder modules positions (without holes)
  *
  * @return array Maximum position by type
  */
 protected function cleanPosition()
 {
     $modulesType = [];
     $this->moduleQuery->clear();
     $modules = $this->moduleQuery->orderByPosition(Criteria::ASC);
     /** @var \Thelia\Model\Module $module */
     foreach ($modules as $module) {
         if (!isset($modulesType[$module->getType()])) {
             $modulesType[$module->getType()] = 0;
         }
         $module->setPosition(++$modulesType[$module->getType()])->save();
     }
     return $modulesType;
 }
Exemple #27
0
 /**
  * @param ProfileEvent $event
  */
 public function updateModuleAccess(ProfileEvent $event)
 {
     if (null !== ($profile = ProfileQuery::create()->findPk($event->getId()))) {
         ProfileModuleQuery::create()->filterByProfileId($event->getId())->delete();
         foreach ($event->getModuleAccess() as $moduleCode => $accesses) {
             $manager = new AccessManager(0);
             $manager->build($accesses);
             $profileModule = new ProfileModule();
             $profileModule->setProfileId($event->getId())->setModule(ModuleQuery::create()->findOneByCode($moduleCode))->setAccess($manager->getAccessValue());
             $profileModule->save();
         }
         $event->setProfile($profile);
     }
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage module Letshopethismoduledoesnotexists not found
  */
 public function testModuleActivateCommandUnknownModule()
 {
     $testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists');
     if (null == $testedModule) {
         $application = new Application($this->getKernel());
         $moduleActivate = new ModuleActivateCommand();
         $moduleActivate->setContainer($this->getContainer());
         $application->add($moduleActivate);
         $command = $application->find("module:activate");
         $commandTester = new CommandTester($command);
         $commandTester->execute(array("command" => $command->getName(), "module" => "letshopethismoduledoesnotexists"));
         $out = true;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $moduleCode = $this->formatModuleName($input->getArgument("module"));
     $module = ModuleQuery::create()->findOneByCode($moduleCode);
     if (null === $module) {
         throw new \RuntimeException(sprintf("module %s not found", $moduleCode));
     }
     try {
         $moduleInstance = $module->createInstance();
         $moduleInstance->activate();
     } catch (\Exception $e) {
         throw new \RuntimeException(sprintf("Activation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()));
     }
     //impossible to change output class in CommandTester...
     if (method_exists($output, "renderBlock")) {
         $output->renderBlock(array('', sprintf("Activation succeed for module %s", $moduleCode), ''), "bg=green;fg=black");
     }
 }
 protected function getModulesData()
 {
     $moduleData = ModuleQuery::create()->orderByType()->addAsColumn("code", ModuleTableMap::CODE)->addAsColumn("active", "IF(" . ModuleTableMap::ACTIVATE . ", \"Yes\", \"No\")")->addAsColumn("type", ModuleTableMap::TYPE)->addAsColumn("version", ModuleTableMap::VERSION)->select(["code", "active", "type", "version"])->find()->toArray();
     foreach ($moduleData as &$row) {
         switch ($row["type"]) {
             case BaseModule::CLASSIC_MODULE_TYPE:
                 $row["type"] = "classic";
                 break;
             case BaseModule::DELIVERY_MODULE_TYPE:
                 $row["type"] = "delivery";
                 break;
             case BaseModule::PAYMENT_MODULE_TYPE:
                 $row["type"] = "payment";
                 break;
         }
     }
     return $moduleData;
 }