public function testSearchByHookId() { $moduleHook = ModuleHookQuery::create()->findOne(); if (null !== $moduleHook) { $this->baseTestSearchById($moduleHook->getId()); } }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see ModuleHook::setDeleted() * @see ModuleHook::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(ModuleHookTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildModuleHookQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Delete module hooks * * @param Module|null $module if specified it will only delete hooks related to this module. * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ protected function deleteHooks($module) { $query = ModuleHookQuery::create(); if (null !== $module) { $query->filterByModule($module)->delete(); } else { $query->deleteAll(); } $query = IgnoredModuleHookQuery::create(); if (null !== $module) { $query->filterByModule($module)->delete(); } else { $query->deleteAll(); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Hook is new, it will return * an empty collection; or if this Hook has previously * been saved, it will retrieve related ModuleHooks from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Hook. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return Collection|ChildModuleHook[] List of ChildModuleHook objects */ public function getModuleHooksJoinModule($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildModuleHookQuery::create(null, $criteria); $query->joinWith('Module', $joinBehavior); return $this->getModuleHooks($query, $con); }
public function buildModelCriteria() { $search = ModuleHookQuery::create(); $this->configureI18nProcessing($search, []); $id = $this->getId(); if (null !== $id) { $search->filterById($id, Criteria::IN); } $hook = $this->getHook(); if (null !== $hook) { $search->filterByHookId($hook, Criteria::EQUAL); } $module = $this->getModule(); if (null !== $module) { $search->filterByModuleId($module, Criteria::EQUAL); } $exclude = $this->getExclude(); if (!is_null($exclude)) { $search->filterById($exclude, Criteria::NOT_IN); } $active = $this->getActive(); if ($active !== Type\BooleanOrBothType::ANY) { $search->filterByActive($active, Criteria::EQUAL); } $hookActive = $this->getHook_active(); if ($hookActive !== Type\BooleanOrBothType::ANY) { $search->filterByHookActive($hookActive, Criteria::EQUAL); } $moduleActive = $this->getModule_active(); if ($moduleActive !== Type\BooleanOrBothType::ANY) { $search->filterByModuleActive($moduleActive, Criteria::EQUAL); } $orders = $this->getOrder(); foreach ($orders as $order) { switch ($order) { case "id": $search->orderById(Criteria::ASC); break; case "id_reverse": $search->orderById(Criteria::DESC); break; case "hook": $search->orderByHookId(Criteria::ASC); break; case "hook_reverse": $search->orderByHookId(Criteria::DESC); break; case "manual": $search->orderByPosition(Criteria::ASC); break; case "manual_reverse": $search->orderByPosition(Criteria::DESC); break; case "enabled": $search->orderByActive(Criteria::ASC); break; case "enabled_reverse": $search->orderByActive(Criteria::DESC); break; } } return $search; }
public function getModuleHookMethods($moduleId, $className) { if (null !== ($response = $this->checkAuth(AdminResources::MODULE_HOOK, [], AccessManager::VIEW))) { return $response; } $result = []; $moduleHooks = ModuleHookQuery::create()->filterByModuleId($moduleId)->filterByClassname($className)->find(); /** @var ModuleHook $moduleHook */ foreach ($moduleHooks as $moduleHook) { $method = $moduleHook->getMethod(); if (!in_array($method, $result)) { $result[] = $method; } } $ignoredModuleHooks = IgnoredModuleHookQuery::create()->filterByModuleId($moduleId)->filterByClassname($className)->find(); /** @var IgnoredModuleHook $moduleHook */ foreach ($ignoredModuleHooks as $moduleHook) { $method = $moduleHook->getMethod(); if (!in_array($method, $result)) { $result[] = $method; } } sort($result); return new JsonResponse($result); }
/** * Load an existing object from the database */ protected function getExistingObject() { $moduleHook = ModuleHookQuery::create()->findPK($this->getRequest()->get('module_hook_id', 0)); return $moduleHook; }
/** * First the new hooks are positioning next to the last module hook. * Next, if the module, hook and module hook is active, a new listener is * added to the service definition. * * @param Definition $definition The service definition */ protected function addHooksMethodCall(ContainerBuilder $container, Definition $definition) { $moduleHooks = ModuleHookQuery::create()->orderByHookId()->orderByPosition()->orderById()->find(); $modulePosition = 0; $hookId = 0; /** @var ModuleHook $moduleHook */ foreach ($moduleHooks as $moduleHook) { // manage module hook position for new hook if ($hookId !== $moduleHook->getHookId()) { $hookId = $moduleHook->getHookId(); $modulePosition = 1; } else { $modulePosition++; } if ($moduleHook->getPosition() === ModuleHook::MAX_POSITION) { // new module hook, we set it at the end of the queue for this event $moduleHook->setPosition($modulePosition)->save(); } else { $modulePosition = $moduleHook->getPosition(); } // Add the the new listener for active hooks, we have to reverse the priority and the position if ($moduleHook->getActive() && $moduleHook->getModuleActive() && $moduleHook->getHookActive()) { $hook = $moduleHook->getHook(); $eventName = sprintf('hook.%s.%s', $hook->getType(), $hook->getCode()); // we a register an event which is relative to a specific module if ($hook->getByModule()) { $eventName .= '.' . $moduleHook->getModuleId(); } $definition->addMethodCall('addListenerService', array($eventName, array($moduleHook->getClassname(), $moduleHook->getMethod()), ModuleHook::MAX_POSITION - $moduleHook->getPosition())); if ($moduleHook->getTemplates()) { if ($container->hasDefinition($moduleHook->getClassname())) { $moduleHookEventName = 'hook.' . $hook->getType() . '.' . $hook->getCode(); if (true === $moduleHook->getHook()->getByModule()) { $moduleHookEventName .= '.' . $moduleHook->getModuleId(); } $container->getDefinition($moduleHook->getClassname())->addMethodCall('addTemplate', array($moduleHookEventName, $moduleHook->getTemplates())); } } } } }
public function toggleHookActivation(HookToggleActivationEvent $event) { if ($event->hasHook()) { $hook = $event->getHook(); ModuleHookQuery::create()->filterByHookId($hook->getId())->update(array('HookActive' => $hook->getActivate())); $this->cacheClear($event->getDispatcher()); } }
public function parseResults(LoopResult $loopResult) { /** @var \Thelia\Model\Module $module */ foreach ($loopResult->getResultDataCollection() as $module) { try { new \ReflectionClass($module->getFullNamespace()); $exists = true; } catch (\ReflectionException $ex) { $exists = false; } if ($exists || $this->getBackendContext()) { $loopResultRow = new LoopResultRow($module); $loopResultRow->set("ID", $module->getId())->set("IS_TRANSLATED", $module->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $module->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $module->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $module->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $module->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("CODE", $module->getCode())->set("TYPE", $module->getType())->set("CATEGORY", $module->getCategory())->set("ACTIVE", $module->getActivate())->set("VERSION", $module->getVersion())->set("CLASS", $module->getFullNamespace())->set("POSITION", $module->getPosition())->set("EXISTS", $exists); $hasConfigurationInterface = false; /* first test if module defines it's own config route */ if ($module->getActivate()) { // test if a hook $hookConfiguration = ModuleHookQuery::create()->filterByModuleId($module->getId())->filterByActive(true)->useHookQuery()->filterByCode('module.configuration')->filterByType(TemplateDefinition::BACK_OFFICE)->endUse()->findOne(); $hasConfigurationInterface = null !== $hookConfiguration; if (false === $hasConfigurationInterface) { // Works only fo activated modules - see Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass $routerId = "router." . $module->getBaseDir(); if ($this->container->has($routerId)) { try { if ($this->container->get($routerId)->match('/admin/module/' . $module->getCode())) { $hasConfigurationInterface = true; } } catch (ResourceNotFoundException $e) { /* $hasConfigurationInterface stays false */ } } } /* if not ; test if it uses admin inclusion : module_configuration.html */ if (false === $hasConfigurationInterface) { if (file_exists($module->getAbsoluteAdminIncludesPath() . DS . "module_configuration.html")) { $hasConfigurationInterface = true; } } } else { // Make a quick and dirty test on the module's config.xml file $configContent = @file_get_contents($module->getAbsoluteConfigPath() . DS . "config.xml"); $hasConfigurationInterface = $configContent && preg_match('/event\\s*=\\s*[\'"]module.configuration[\'"]/', $configContent) !== false; if (false === $hasConfigurationInterface) { // Make a quick and dirty test on the module's routing.xml file $routing = @file_get_contents($module->getAbsoluteConfigPath() . DS . "routing.xml"); if ($routing && strpos($routing, '/admin/module/') !== false) { $hasConfigurationInterface = true; } else { if (file_exists($module->getAbsoluteAdminIncludesPath() . DS . "module_configuration.html")) { $hasConfigurationInterface = true; } } } } $loopResultRow->set("CONFIGURABLE", $hasConfigurationInterface ? 1 : 0); // Does module have hook(s) $hookable = false; $moduleHookCount = ModuleHookQuery::create()->filterByModuleId($module->getId())->count(); $hookable = $moduleHookCount > 0; $loopResultRow->set("HOOKABLE", $hookable ? 1 : 0); if (null !== $this->getProfile()) { $accessValue = $module->getVirtualColumn('access'); $manager = new AccessManager($accessValue); $loopResultRow->set("VIEWABLE", $manager->can(AccessManager::VIEW) ? 1 : 0)->set("CREATABLE", $manager->can(AccessManager::CREATE) ? 1 : 0)->set("UPDATABLE", $manager->can(AccessManager::UPDATE) ? 1 : 0)->set("DELETABLE", $manager->can(AccessManager::DELETE) ? 1 : 0); } $loopResult->addRow($loopResultRow); } } return $loopResult; }
/** * Performs an INSERT on the database, given a ModuleHook or Criteria object. * * @param mixed $criteria Criteria or ModuleHook object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(ModuleHookTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from ModuleHook object } if ($criteria->containsKey(ModuleHookTableMap::ID) && $criteria->keyContainsValue(ModuleHookTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . ModuleHookTableMap::ID . ')'); } // Set the correct dbName $query = ModuleHookQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }