コード例 #1
0
 /**
  * @covers       InstallerHelper::upgradeBkeyToFqClassname
  * @dataProvider bKeyProvider
  * @param $moduleName
  * @param $oldBkey
  * @param $expected
  */
 public function testUpgradeBkeyToFqClassname($moduleName, $oldBkey, $expected)
 {
     $kernel = $this->getMockBuilder('\\Zikula\\Bundle\\CoreBundle\\HttpKernel\\ZikulaKernel')->disableOriginalConstructor()->getMock();
     $kernel->method('getModule')->will($this->returnCallback(function ($moduleName) {
         if ($moduleName == 'ExceptionModule') {
             // mocks situation where module is not namespaced.
             throw new \Exception();
         }
         $module = $this->getMockBuilder('Zikula\\Core\\AbstractModule')->disableOriginalConstructor()->getMock();
         $module->method('getNamespace')->willReturn('Zikula\\BlocksModule\\Tests\\Helper\\' . $moduleName);
         return $module;
     }));
     $moduleEntity = $this->getMockBuilder('\\Zikula\\ExtensionsModule\\Entity\\ExtensionEntity')->disableOriginalConstructor()->getMock();
     $moduleEntity->method('getName')->willReturn($moduleName);
     $blockEntity = $this->getMockBuilder('\\Zikula\\BlocksModule\\Entity\\BlockEntity')->disableOriginalConstructor()->getMock();
     $blockEntity->method('getModule')->willReturn($moduleEntity);
     $blockEntity->method('getBkey')->willReturn($oldBkey);
     $FqClassName = $this->helper->upgradeBkeyToFqClassname($kernel, $blockEntity);
     $this->assertEquals($expected, $FqClassName);
 }
コード例 #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':
             $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;
 }