Пример #1
0
 protected function createOrUpdateHook(array $hook, EventDispatcherInterface $dispatcher, $defaultLocale)
 {
     $hookModel = HookQuery::create()->filterByCode($hook["code"])->findOne();
     if ($hookModel === null) {
         $event = new HookCreateAllEvent();
     } else {
         $event = new HookUpdateEvent($hookModel->getId());
     }
     /**
      * Get used I18n variables
      */
     $locale = $defaultLocale;
     list($titles, $descriptions, $chapos) = $this->getHookI18nInfo($hook, $defaultLocale);
     /**
      * If the default locale exists
      * extract it to save it in create action
      *
      * otherwise take the first
      */
     if (isset($titles[$defaultLocale])) {
         $title = $titles[$defaultLocale];
         unset($titles[$defaultLocale]);
     } else {
         reset($titles);
         $locale = key($titles);
         $title = array_shift($titles);
     }
     $description = $this->arrayKeyPop($locale, $descriptions);
     $chapo = $this->arrayKeyPop($locale, $chapos);
     /**
      * Set data
      */
     $event->setBlock(isset($hook["block"]) && (bool) $hook["block"])->setLocale($locale)->setTitle($title)->setDescription($description)->setChapo($chapo)->setType($hook["type"])->setCode($hook["code"])->setNative(false)->setByModule(true)->setActive(isset($hook["active"]) && (bool) $hook["active"]);
     /**
      * Dispatch the event
      */
     $dispatcher->dispatch($hookModel === null ? TheliaEvents::HOOK_CREATE_ALL : TheliaEvents::HOOK_UPDATE, $event);
     return [$event->getHook(), $this->formatHookDataForI18n($titles, $descriptions, $chapos)];
 }
Пример #2
0
 public function update(HookUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (null !== ($hook = HookQuery::create()->findPk($event->getHookId()))) {
         $hook->setLocale($event->getLocale())->setCode($event->getCode())->setType($event->getType())->setNative($event->getNative())->setActivate($event->getActive())->setBlock($event->getBlock())->setByModule($event->getByModule())->setTitle($event->getTitle())->setChapo($event->getChapo())->setDescription($event->getDescription())->save();
         $event->setHook($hook);
         $this->cacheClear($dispatcher);
     }
 }
Пример #3
0
 /**
  * @param HookModel $hook
  * @depends testToggleActivation
  * @return HookModel
  */
 public function testUpdate(HookModel $hook)
 {
     $event = new HookUpdateEvent($hook->getId());
     $event->setCode('test.hook.' . uniqid())->setType(TemplateDefinition::FRONT_OFFICE)->setLocale($this->locale)->setActive(false)->setNative(false)->setTitle("Updated Hook Test")->setDescription("Updated Hook Description")->setChapo("Updated Hook Chapo")->setBlock(false)->setByModule(false);
     $this->action->update($event, null, $this->getMockEventDispatcher());
     $updatedHook = $event->getHook();
     $this->assertEquals($event->getCode(), $updatedHook->getCode());
     $this->assertEquals($event->getType(), $updatedHook->getType());
     $this->assertEquals($event->getLocale(), $updatedHook->getLocale());
     $this->assertEquals($event->getActive(), $updatedHook->getActivate());
     $this->assertEquals($event->getNative(), $updatedHook->getNative());
     $this->assertEquals($event->getTitle(), $updatedHook->getTitle());
     $this->assertEquals($event->getDescription(), $updatedHook->getDescription());
     $this->assertEquals($event->getChapo(), $updatedHook->getChapo());
     $this->assertEquals($event->getBlock(), $updatedHook->getBlock());
     $this->assertEquals($event->getByModule(), $updatedHook->getByModule());
     return $updatedHook;
 }
Пример #4
0
 public function updateHook(HookUpdateEvent $event)
 {
     if ($event->hasHook()) {
         $hook = $event->getHook();
         ModuleHookQuery::create()->filterByHookId($hook->getId())->update(array('HookActive' => $hook->getActivate()));
         $this->cacheClear($event->getDispatcher());
     }
 }