예제 #1
0
 public function toggleModuleActivation(ModuleToggleActivationEvent $event)
 {
     if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) {
         ModuleHookQuery::create()->filterByModuleId($module->getId())->update(array('ModuleActive' => $module->getActivate() == BaseModule::IS_ACTIVATED));
     }
     return $event;
 }
 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");
     }
 }
 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);
 }
예제 #4
0
파일: Module.php 프로젝트: alex63530/thelia
 public function toggleActivation(ModuleToggleActivationEvent $event)
 {
     if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) {
         $moduleInstance = $module->createInstance();
         if (method_exists($moduleInstance, 'setContainer')) {
             $moduleInstance->setContainer($this->container);
             if ($module->getActivate() == BaseModule::IS_ACTIVATED) {
                 $moduleInstance->deActivate($module);
             } else {
                 $moduleInstance->activate($module);
             }
         }
         $event->setModule($module);
         $this->cacheClear($event->getDispatcher());
     }
 }
예제 #5
0
파일: Module.php 프로젝트: margery/thelia
 /**
  * @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);
 }