Esempio n. 1
0
 public function updatePlugin(\Eccube\Entity\Plugin $plugin, $meta, $event_yml)
 {
     $em = $this->app['orm.em'];
     $em->getConnection()->beginTransaction();
     $plugin->setVersion($meta['version'])->setName($meta['name']);
     if (isset($meta['event'])) {
         $plugin->setClassName($meta['event']);
     }
     $rep = $this->app['eccube.repository.plugin_event_handler'];
     if (is_array($event_yml)) {
         foreach ($event_yml as $event => $handlers) {
             foreach ($handlers as $handler) {
                 if (!$this->checkSymbolName($handler[0])) {
                     throw new PluginException('Handler name format error');
                 }
                 // updateで追加されたハンドラかどうか調べる
                 $peh = $rep->findBy(array('del_flg' => Constant::DISABLED, 'plugin_id' => $plugin->getId(), 'event' => $event, 'handler' => $handler[0], 'handler_type' => $handler[1]));
                 if (!$peh) {
                     // 新規にevent.ymlに定義されたハンドラなのでinsertする
                     $peh = new \Eccube\Entity\PluginEventHandler();
                     $peh->setPlugin($plugin)->setEvent($event)->setdelFlg(Constant::DISABLED)->setHandler($handler[0])->setHandlerType($handler[1])->setPriority($rep->calcNewPriority($event, $handler[1]));
                     $em->persist($peh);
                     $em->flush();
                 }
             }
         }
         # アップデート後のevent.ymlで削除されたハンドラをdtb_plugin_event_handlerから探して削除
         foreach ($rep->findBy(array('del_flg' => Constant::DISABLED, 'plugin_id' => $plugin->getId())) as $peh) {
             if (!isset($event_yml[$peh->getEvent()])) {
                 $em->remove($peh);
                 $em->flush();
             } else {
                 $match = false;
                 foreach ($event_yml[$peh->getEvent()] as $handler) {
                     if ($peh->getHandler() == $handler[0] and $peh->getHandlerType() == $handler[1]) {
                         $match = true;
                     }
                 }
                 if (!$match) {
                     $em->remove($peh);
                     $em->flush();
                 }
             }
         }
     }
     $em->persist($plugin);
     $em->flush();
     $em->getConnection()->commit();
 }
Esempio n. 2
0
 public function registerPlugin($meta, $event_yml, $source = 0)
 {
     $em = $this->app['orm.em'];
     $em->getConnection()->beginTransaction();
     $p = new \Eccube\Entity\Plugin();
     $p->setName($meta['name'])->setEnable(1)->setClassName(isset($meta['event']) ? $meta['event'] : '')->setVersion($meta['version'])->setDelflg(0)->setSource($source)->setCode($meta['code']);
     $em->persist($p);
     $em->flush();
     if (is_array($event_yml)) {
         foreach ($event_yml as $event => $handlers) {
             foreach ($handlers as $handler) {
                 if (!$this->checkSymbolName($handler[0])) {
                     throw new PluginException("Handler name format error");
                 }
                 $peh = new \Eccube\Entity\PluginEventHandler();
                 $peh->setPlugin($p)->setEvent($event)->setdelFlg(0)->setHandler($handler[0])->setHandlerType($handler[1])->setPriority($this->app['eccube.repository.plugin_event_handler']->calcNewPriority($event, $handler[1]));
                 $em->persist($peh);
                 $em->flush();
             }
         }
     }
     $em->persist($p);
     $em->flush();
     $em->getConnection()->commit();
     return $p;
 }