Пример #1
0
 private function saveDescription(Module $module, \SimpleXMLElement $content, ConnectionInterface $con)
 {
     foreach ($content->descriptive as $description) {
         $locale = (string) $description->attributes()->locale;
         $module->setLocale($locale)->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);
     }
 }
Пример #2
0
 protected function getModuleTemplateNames(Module $module, $templateType)
 {
     $templates = $this->getTemplateHelper()->getList($templateType, $module->getAbsoluteTemplateBasePath());
     $names = [];
     foreach ($templates as $template) {
         $names[] = $template->getName();
     }
     return $names;
 }
Пример #3
0
 public function __construct()
 {
     $this->logger = Tlog::getNewInstance();
     $this->logger->setDestinations(static::LOG_CLASS);
     $this->logger->setConfig(self::LOG_CLASS, 0, THELIA_ROOT . "log" . DS . "log-shopping-flux.txt");
     /**
      * Create a fake user ShoppingFlux if it doesn't exist
      */
     $this->shoppingFluxCustomer = ShoppingFluxConfigQuery::createShoppingFluxCustomer();
     $this->shoppingFluxPaymentModule = (new ShoppingFlux())->getModuleModel();
     $this->shoppingFluxPaymentModuleId = $this->shoppingFluxPaymentModule->getId();
 }
Пример #4
0
 public function testCreate()
 {
     $event = new ModuleHookCreateEvent();
     $event->setHookId($this->hook->getId())->setModuleId($this->module->getId())->setDispatcher($this->dispatcher);
     $this->action->createModuleHook($event);
     $createdModuleHook = $event->getModuleHook();
     $this->assertInstanceOf('\\Thelia\\Model\\ModuleHook', $createdModuleHook);
     $this->assertFalse($createdModuleHook->isNew());
     $this->assertTrue($event->hasModuleHook());
     $this->assertEquals($event->getHookId(), $createdModuleHook->getHookId());
     $this->assertEquals($event->getModuleId(), $createdModuleHook->getModuleId());
     return $createdModuleHook;
 }
 /**
  * Parse the acl in acl.xml file
  * @param SimpleXMLElement $xml The xml parsed by parseFile
  * @param Module $module The enabled module
  */
 protected function parseAcls(SimpleXMLElement $xml, Module $module)
 {
     //If there are no acl node continue to parse the xml
     $acls = $xml->xpath('//config:acls/config:acl');
     if (false === $acls) {
         return;
     }
     //Add the acl if they no exists and parse his descriptive
     /** @var SimpleXMLElement $acl */
     foreach ($acls as $acl) {
         $code = $acl->getAttributeAsPHP("code");
         if (AclQuery::create()->findOneByCode($code)) {
             continue;
         }
         $newAcl = new Acl();
         $newAcl->setCode($code)->setModuleId($module->getId());
         $newAcl->save();
         $this->parseDescriptives($acl);
     }
 }
Пример #6
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()));
         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;
             }
         }
     }
 }
Пример #7
0
 /**
  * Check if module can be deactivated safely because other modules
  * could have dependencies to this module
  *
  * @param  \Thelia\Model\Module $module
  * @return bool                 true if the module can be deactivated, otherwise false
  */
 private function checkDeactivation($module)
 {
     $moduleValidator = new ModuleValidator($module->getAbsoluteBaseDir());
     $modules = $moduleValidator->getModulesDependOf();
     if (count($modules) > 0) {
         $moduleList = implode(', ', array_column($modules, 'code'));
         $message = count($modules) == 1 ? Translator::getInstance()->trans('%s has dependency to module %s. You have to deactivate this module before.') : Translator::getInstance()->trans('%s have dependencies to module %s. You have to deactivate these modules before.');
         throw new ModuleException(sprintf($message, $moduleList, $moduleValidator->getModuleDefinition()->getCode()));
     }
     return true;
 }
Пример #8
0
 /**
  * Ensure the proper deployment of the module's images.
  *
  * TODO : this method does not take care of internationalization. This is a bug.
  *
  * @param Module              $module     the module
  * @param string              $folderPath the image folder path
  * @param ConnectionInterface $con
  *
  * @throws \Thelia\Exception\ModuleException
  * @throws \Exception
  * @throws \UnexpectedValueException
  */
 public function deployImageFolder(Module $module, $folderPath, ConnectionInterface $con = null)
 {
     try {
         $directoryBrowser = new \DirectoryIterator($folderPath);
     } catch (\UnexpectedValueException $e) {
         throw $e;
     }
     if (null === $con) {
         $con = Propel::getConnection(ModuleImageTableMap::DATABASE_NAME);
     }
     /* browse the directory */
     $imagePosition = 1;
     /** @var \DirectoryIterator $directoryContent */
     foreach ($directoryBrowser as $directoryContent) {
         /* is it a file ? */
         if ($directoryContent->isFile()) {
             $fileName = $directoryContent->getFilename();
             $filePath = $directoryContent->getPathName();
             /* is it a picture ? */
             if (Image::isImage($filePath)) {
                 $con->beginTransaction();
                 $image = new ModuleImage();
                 $image->setModuleId($module->getId());
                 $image->setPosition($imagePosition);
                 $image->save($con);
                 $imageDirectory = sprintf("%s/../../../../local/media/images/module", __DIR__);
                 $imageFileName = sprintf("%s-%d-%s", $module->getCode(), $image->getId(), $fileName);
                 $increment = 0;
                 while (file_exists($imageDirectory . '/' . $imageFileName)) {
                     $imageFileName = sprintf("%s-%d-%d-%s", $module->getCode(), $image->getId(), $increment, $fileName);
                     $increment++;
                 }
                 $imagePath = sprintf('%s/%s', $imageDirectory, $imageFileName);
                 if (!is_dir($imageDirectory)) {
                     if (!@mkdir($imageDirectory, 0777, true)) {
                         $con->rollBack();
                         throw new ModuleException(sprintf("Cannot create directory : %s", $imageDirectory), ModuleException::CODE_NOT_FOUND);
                     }
                 }
                 if (!@copy($filePath, $imagePath)) {
                     $con->rollBack();
                     throw new ModuleException(sprintf("Cannot copy file : %s to : %s", $filePath, $imagePath), ModuleException::CODE_NOT_FOUND);
                 }
                 $image->setFile($imageFileName);
                 $image->save($con);
                 $con->commit();
                 $imagePosition++;
             }
         }
     }
 }
Пример #9
0
 /**
  * Filter the query by a related \Thelia\Model\Module object
  *
  * @param \Thelia\Model\Module|ObjectCollection $module The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCouponModuleQuery The current query, for fluid interface
  */
 public function filterByModule($module, $comparison = null)
 {
     if ($module instanceof \Thelia\Model\Module) {
         return $this->addUsingAlias(CouponModuleTableMap::MODULE_ID, $module->getId(), $comparison);
     } elseif ($module instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CouponModuleTableMap::MODULE_ID, $module->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByModule() only accepts arguments of type \\Thelia\\Model\\Module or Collection');
     }
 }
Пример #10
0
 /**
  * Declares an association between this object and a ChildModule object.
  *
  * @param                  ChildModule $v
  * @return                 \Thelia\Model\Order The current object (for fluent API support)
  * @throws PropelException
  */
 public function setModuleRelatedByDeliveryModuleId(ChildModule $v = null)
 {
     if ($v === null) {
         $this->setDeliveryModuleId(NULL);
     } else {
         $this->setDeliveryModuleId($v->getId());
     }
     $this->aModuleRelatedByDeliveryModuleId = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildModule object, it will not be re-added.
     if ($v !== null) {
         $v->addOrderRelatedByDeliveryModuleId($this);
     }
     return $this;
 }
Пример #11
0
 private function loadModuleTranslationDirectories(Module $module, array &$translationDirs, $templateHelper)
 {
     // Core module translation
     if (is_dir($dir = $module->getAbsoluteI18nPath())) {
         $translationDirs[$module->getTranslationDomain()] = $dir;
     }
     // Admin includes translation
     if (is_dir($dir = $module->getAbsoluteAdminIncludesI18nPath())) {
         $translationDirs[$module->getAdminIncludesTranslationDomain()] = $dir;
     }
     // Module back-office template, if any
     $templates = $templateHelper->getList(TemplateDefinition::BACK_OFFICE, $module->getAbsoluteTemplateBasePath());
     foreach ($templates as $template) {
         $translationDirs[$module->getBackOfficeTemplateTranslationDomain($template->getName())] = $module->getAbsoluteBackOfficeI18nTemplatePath($template->getName());
     }
     // Module front-office template, if any
     $templates = $templateHelper->getList(TemplateDefinition::FRONT_OFFICE, $module->getAbsoluteTemplateBasePath());
     foreach ($templates as $template) {
         $translationDirs[$module->getFrontOfficeTemplateTranslationDomain($template->getName())] = $module->getAbsoluteFrontOfficeI18nTemplatePath($template->getName());
     }
     // Module pdf template, if any
     $templates = $templateHelper->getList(TemplateDefinition::PDF, $module->getAbsoluteTemplateBasePath());
     foreach ($templates as $template) {
         $translationDirs[$module->getPdfTemplateTranslationDomain($template->getName())] = $module->getAbsolutePdfI18nTemplatePath($template->getName());
     }
     // Module email template, if any
     $templates = $templateHelper->getList(TemplateDefinition::EMAIL, $module->getAbsoluteTemplateBasePath());
     foreach ($templates as $template) {
         $translationDirs[$module->getEmailTemplateTranslationDomain($template->getName())] = $module->getAbsoluteEmailI18nTemplatePath($template->getName());
     }
 }
 /**
  * Create a new hook if the hook definition is valid.
  *
  * @param string               $class  the namespace of the class
  * @param \Thelia\Model\Module $module the module
  * @param string               $id     the service (hook) id
  * @param array                $attributes  the hook attributes
  *
  * @throws \InvalidArgumentException
  */
 protected function registerHook($class, $module, $id, $attributes)
 {
     if (!isset($attributes['event'])) {
         throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "hook.event_listener" tags.', $id));
     }
     $active = isset($attributes['active']) ? intval($attributes['active']) : 1;
     $attributes['active'] = 1 === $active;
     $attributes['templates'] = isset($attributes['templates']) ? strval($attributes['templates']) : '';
     $attributes['type'] = isset($attributes['type']) ? $this->getHookType($attributes['type']) : TemplateDefinition::FRONT_OFFICE;
     if (null === ($hook = $this->getHook($attributes['event'], $attributes['type']))) {
         return;
     }
     $attributes = $this->getMethodName($attributes);
     // test if method exists
     $validMethod = true;
     if (!$this->isValidHookMethod($class, $attributes['method'], $hook->getBlock())) {
         $validMethod = false;
     }
     // test if hook is already registered in ModuleHook
     $moduleHook = ModuleHookQuery::create()->filterByModuleId($module->getId())->filterByHook($hook)->filterByMethod($attributes['method'])->findOne();
     if (null === $moduleHook) {
         if (!$validMethod) {
             Tlog::getInstance()->addAlert(sprintf("Module [%s] could not be registered hook [%s], method [%s] is not reachable.", $module->getCode(), $attributes['event'], $attributes['method']));
             return;
         }
         // Assign the module to the hook only if it has not been "deleted"
         $ignoreCount = IgnoredModuleHookQuery::create()->filterByHook($hook)->filterByModuleId($module->getId())->count();
         if (0 === $ignoreCount) {
             // hook for module doesn't exist, we add it with default registered values
             $moduleHook = new ModuleHook();
             $moduleHook->setHook($hook)->setModuleId($module->getId())->setClassname($id)->setMethod($attributes['method'])->setActive($active)->setHookActive(true)->setModuleActive(true)->setPosition(ModuleHook::MAX_POSITION);
             if (isset($attributes['templates'])) {
                 $moduleHook->setTemplates($attributes['templates']);
             }
             $moduleHook->save();
         }
     } else {
         if (!$validMethod) {
             Tlog::getInstance()->addAlert(sprintf("Module [%s] could not use hook [%s], method [%s] is not reachable anymore.", $module->getCode(), $attributes['event'], $attributes['method']));
             $moduleHook->setHookActive(false)->save();
         } else {
             //$moduleHook->setTemplates($attributes['templates']);
             // Update hook if id was changed in the definition
             if ($moduleHook->getClassname() != $id) {
                 $moduleHook->setClassname($id);
             }
             $moduleHook->save();
         }
     }
 }
Пример #13
0
 /**
  * @param Module $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
Пример #14
0
 /**
  * Add a module template directory to the parser environment
  *
  * @param ParserInterface $parser             the parser
  * @param Module          $module             the Module.
  * @param string          $templateType       the template type (one of the TemplateDefinition type constants)
  * @param string          $templateSubdirName the template subdirectory name (one of the TemplateDefinition::XXX_SUBDIR constants)
  */
 protected function addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName)
 {
     // Get template path
     $templateDirectory = $module->getAbsoluteTemplateDirectoryPath($templateSubdirName);
     try {
         $templateDirBrowser = new \DirectoryIterator($templateDirectory);
         $code = ucfirst($module->getCode());
         /* browse the directory */
         foreach ($templateDirBrowser as $templateDirContent) {
             /* is it a directory which is not . or .. ? */
             if ($templateDirContent->isDir() && !$templateDirContent->isDot()) {
                 $parser->addMethodCall('addTemplateDirectory', array($templateType, $templateDirContent->getFilename(), $templateDirContent->getPathName(), $code));
             }
         }
     } catch (\UnexpectedValueException $ex) {
         // The directory does not exists, ignore it.
     }
 }
Пример #15
0
 /**
  * Exclude object from result
  *
  * @param   ChildModule $module Object to remove from the list of results
  *
  * @return ChildModuleQuery The current query, for fluid interface
  */
 public function prune($module = null)
 {
     if ($module) {
         $this->addUsingAlias(ModuleTableMap::ID, $module->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }