示例#1
0
 /**
  * Register a Zikula_AbstractEventHandler as a persistent handler.
  *
  * @param string $moduleName Module name.
  * @param string $className  Class name (subclass of Zikula_AbstractEventHandler).
  *
  * @throws InvalidArgumentException If class is not available or not a subclass of Zikula_AbstractEventHandler.
  *
  * @return void
  *
  * Note: If the exact same handler is already registered, this function does nothing.
  */
 public static function registerPersistentEventHandlerClass($moduleName, $className)
 {
     if (!class_exists($className)) {
         throw new InvalidArgumentException(sprintf('Class %s does not exist or cannot be found', $className));
     }
     $reflection = new ReflectionClass($className);
     if (!$reflection->isSubclassOf('Zikula_AbstractEventHandler')) {
         throw new InvalidArgumentException(sprintf('%s is not a subclass of Zikula_AbstractEventHandler', $className));
     }
     $handlers = ModUtil::getVar(self::HANDLERS, $moduleName, array());
     $newHandler = array('classname' => $className);
     foreach ($handlers as $handler) {
         if ($handler == $newHandler) {
             // The exact same handler exists already. Do nothing but display a warning.
             if (System::isDevelopmentMode()) {
                 LogUtil::registerWarning(__f('The eventhandler class "%1$s" for "%2$s" could not be registered because it is registered already.', array($className, $moduleName)));
             } else {
                 $warns = LogUtil::getWarningMessages(false);
                 $msg = __f('The eventhandlers for "%1$s" could not be registered because they are registered already.', array($moduleName));
                 if (!in_array(DataUtil::formatForDisplayHTML($msg), $warns)) {
                     LogUtil::registerWarning($msg);
                 }
             }
             return;
         }
     }
     $handlers[] = $newHandler;
     ModUtil::setVar(self::HANDLERS, $moduleName, $handlers);
 }
示例#2
0
 /**
  * upgrade the blocks module
  *
  * @param string $oldversion version being upgraded
  *
  * @return bool true if successful, false otherwise
  */
 public function upgrade($oldversion)
 {
     // Upgrade dependent on old version number
     switch ($oldversion) {
         case '3.8.1':
             HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
         case '3.8.2':
         case '3.9.0':
             $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll();
             /** @var \Zikula\Module\BlocksModule\Entity\BlockEntity $block */
             foreach ($blocks as $block) {
                 $content = $block->getContent();
                 if (\DataUtil::is_serialized($content)) {
                     $content = unserialize($content);
                     foreach ($content as $k => $item) {
                         if (is_string($item)) {
                             if (strpos($item, 'blocks_block_extmenu_topnav.tpl') !== false) {
                                 $content[$k] = str_replace('blocks_block_extmenu_topnav.tpl', 'Block/Extmenu/topnav.tpl', $item);
                             } elseif (strpos($item, 'blocks_block_extmenu.tpl') !== false) {
                                 $content[$k] = str_replace('blocks_block_extmenu.tpl', 'Block/Extmenu/extmenu.tpl', $item);
                             } elseif (strpos($item, 'menutree/blocks_block_menutree_') !== false) {
                                 $content[$k] = str_replace('menutree/blocks_block_menutree_', 'Block/Menutree/', $item);
                             }
                         }
                     }
                     $block->setContent(serialize($content));
                 }
             }
             $this->entityManager->flush();
             // check if request is available (#2073)
             $templateWarning = $this->__('Warning: Block template locations modified, you may need to fix your template overrides if you have any.');
             if (is_object($this->request) && method_exists($this->request, 'getSession') && is_object($this->request->getSession())) {
                 $this->request->getSession()->getFlashBag()->add(\Zikula_Session::MESSAGE_WARNING, $templateWarning);
             } else {
                 \LogUtil::registerWarning($templateWarning);
             }
         case '3.9.1':
             // future upgrade routines
     }
     // Update successful
     return true;
 }
示例#3
0
 /**
  * upgrade the blocks module
  *
  * @param string $oldversion version being upgraded
  *
  * @return bool true if successful, false otherwise
  */
 public function upgrade($oldversion)
 {
     // Upgrade dependent on old version number
     switch ($oldversion) {
         case '3.8.1':
             $HookContainer = new HookContainer($this->getTranslator());
             HookUtil::registerSubscriberBundles($HookContainer->getHookSubscriberBundles());
         case '3.8.2':
         case '3.9.0':
             $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll();
             /** @var \Zikula\BlocksModule\Entity\BlockEntity $block */
             foreach ($blocks as $block) {
                 $content = $block->getContent();
                 if (\DataUtil::is_serialized($content)) {
                     $content = unserialize($content);
                     foreach ($content as $k => $item) {
                         if (is_string($item)) {
                             if (strpos($item, 'blocks_block_extmenu_topnav.tpl') !== false) {
                                 $content[$k] = str_replace('blocks_block_extmenu_topnav.tpl', 'Block/Extmenu/topnav.tpl', $item);
                             } elseif (strpos($item, 'blocks_block_extmenu.tpl') !== false) {
                                 $content[$k] = str_replace('blocks_block_extmenu.tpl', 'Block/Extmenu/extmenu.tpl', $item);
                             } elseif (strpos($item, 'menutree/blocks_block_menutree_') !== false) {
                                 $content[$k] = str_replace('menutree/blocks_block_menutree_', 'Block/Menutree/', $item);
                             }
                         }
                     }
                     $block->setContent(serialize($content));
                 }
             }
             $this->entityManager->flush();
             // check if request is available (#2073)
             $templateWarning = $this->__('Warning: Block template locations modified, you may need to fix your template overrides if you have any.');
             if (is_object($this->container->get('request')) && method_exists($this->container->get('request'), 'getSession') && is_object($this->container->get('request')->getSession())) {
                 $this->addFlash(\Zikula_Session::MESSAGE_WARNING, $templateWarning);
             } else {
                 \LogUtil::registerWarning($templateWarning);
             }
         case '3.9.1':
             // make all content fields of blocks serialized.
             $sql = "SELECT * FROM blocks";
             $blocks = $this->entityManager->getConnection()->fetchAll($sql);
             foreach ($blocks as $block) {
                 if (!\DataUtil::is_serialized($block['content'])) {
                     $serializedContent = addslashes(serialize($block['content']));
                     $this->entityManager->getConnection()->executeQuery("UPDATE blocks SET content = '{$serializedContent}' WHERE bid = {$block['bid']}");
                 }
             }
             $this->schemaTool->update($this->entities);
             $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll();
             $installerHelper = new InstallerHelper();
             /** @var \Zikula\BlocksModule\Entity\BlockEntity $block */
             foreach ($blocks as $block) {
                 $block->setFilters($installerHelper->upgradeFilterArray($block->getFilters()));
                 $block->setBlocktype(preg_match('/.*Block$/', $block->getBkey()) ? substr($block->getBkey(), 0, -5) : $block->getBkey());
                 $block->setBkey($installerHelper->upgradeBkeyToFqClassname($this->container->get('kernel'), $block));
             }
             $this->entityManager->flush();
             $collapseable = $this->getVar('collapseable');
             $this->setVar('collapseable', (bool) $collapseable);
         case '3.9.2':
             // future upgrade routines
     }
     // Update successful
     return true;
 }