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"); } }
/** * Get modules having current module in dependence and deactivate it if needed * * @param ModuleToggleActivationEvent $event * */ public function recursiveDeactivation(ModuleToggleActivationEvent $event) { if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) { $moduleValidator = new ModuleValidator($module->getAbsoluteBaseDir()); $dependencies = $moduleValidator->getModulesDependOf(true); foreach ($dependencies as $defMod) { $submodule = ModuleQuery::create()->findOneByCode($defMod["code"]); if ($submodule && $submodule->getActivate() == BaseModule::IS_ACTIVATED) { $subevent = new ModuleToggleActivationEvent($submodule->getId()); $subevent->setRecursive(true); $event->getDispatcher()->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $subevent); } } } }