/** * 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.'); } }
protected function execute(InputInterface $input, OutputInterface $output) { try { $moduleManagement = new ModuleManagement(); $moduleManagement->updateModules(); } catch (\Exception $e) { throw new \RuntimeException(sprintf('Refresh modules list fail with Exception : [%d] %s', $e->getCode(), $e->getMessage())); } if (method_exists($output, 'renderBlock')) { $output->renderBlock(['', 'Modules list successfully refreshed', ''], 'bg=green;fg=black'); } }
protected function execute(InputInterface $input, OutputInterface $output) { try { $moduleManagement = new ModuleManagement(); $moduleManagement->updateModules($this->getContainer()); } catch (InvalidModuleException $ime) { throw new \RuntimeException(sprintf('One or more modules could not be refreshed : %s', $ime->getErrorsAsString("\n"))); } catch (\Exception $e) { throw new \RuntimeException(sprintf('Refresh modules list fail with Exception : [%d] %s', $e->getCode(), $e->getMessage())); } if (method_exists($output, 'renderBlock')) { $output->renderBlock(['', 'Modules list successfully refreshed', ''], 'bg=green;fg=black'); } }
/** * @param \Thelia\Core\Event\Module\ModuleInstallEvent $event * * @throws \Exception * @throws \Symfony\Component\Filesystem\Exception\IOException * @throws \Exception */ public function install(ModuleInstallEvent $event) { $moduleDefinition = $event->getModuleDefinition(); $oldModule = ModuleQuery::create()->findOneByFullNamespace($moduleDefinition->getNamespace()); $dispatcher = $event->getDispatcher(); $fs = new Filesystem(); $activated = false; // check existing module if (null !== $oldModule) { $activated = $oldModule->getActivate(); if ($activated) { // deactivate $toggleEvent = new ModuleToggleActivationEvent($oldModule); // disable the check of the module because it's already done $toggleEvent->setNoCheck(true); $toggleEvent->setDispatcher($dispatcher); $dispatcher->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $toggleEvent); } // delete $modulePath = $oldModule->getAbsoluteBaseDir(); $deleteEvent = new ModuleDeleteEvent($oldModule); $deleteEvent->setDispatcher($dispatcher); try { $dispatcher->dispatch(TheliaEvents::MODULE_DELETE, $deleteEvent); } catch (Exception $ex) { // if module has not been deleted if ($fs->exists($modulePath)) { throw $ex; } } } // move new module $modulePath = sprintf('%s%s', THELIA_MODULE_DIR, $event->getModuleDefinition()->getCode()); try { $fs->mirror($event->getModulePath(), $modulePath); } catch (IOException $ex) { if (!$fs->exists($modulePath)) { throw $ex; } } // Update the module $moduleDescriptorFile = sprintf('%s%s%s%s%s', $modulePath, DS, 'Config', DS, 'module.xml'); $moduleManagement = new ModuleManagement(); $file = new SplFileInfo($moduleDescriptorFile); $module = $moduleManagement->updateModule($file, $this->container); // activate if old was activated if ($activated) { $toggleEvent = new ModuleToggleActivationEvent($module->getId()); $toggleEvent->setNoCheck(true); $toggleEvent->setDispatcher($dispatcher); $dispatcher->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $toggleEvent); } $event->setModule($module); }
public function indexAction() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, array(), AccessManager::VIEW))) { return $response; } try { $moduleManagement = new ModuleManagement(); $moduleManagement->updateModules($this->getContainer()); } catch (InvalidModuleException $ex) { $this->moduleErrors = $ex->getErrors(); } catch (Exception $ex) { Tlog::getInstance()->addError("Failed to get modules list:", $ex); } return $this->renderList(); }
public function indexAction() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, array(), AccessManager::VIEW))) { return $response; } $moduleManagement = new ModuleManagement(); $moduleManagement->updateModules(); return $this->renderList(); }