| Conditions | 33 |
| Paths | 26 |
| Total Lines | 117 |
| Code Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 63 | public function upgrade($oldversion) |
||
| 64 | { |
||
| 65 | // Upgrade dependent on old version number |
||
| 66 | switch ($oldversion) { |
||
| 67 | case '3.8.1': |
||
|
|
|||
| 68 | $this->hookApi->installSubscriberHooks($this->bundle->getMetaData()); |
||
| 69 | case '3.8.2': |
||
| 70 | case '3.9.0': |
||
| 71 | $sql = "SELECT * FROM blocks"; |
||
| 72 | $blocks = $this->entityManager->getConnection()->fetchAll($sql); |
||
| 73 | foreach ($blocks as $block) { |
||
| 74 | $content = $block['content']; |
||
| 75 | if ($this->isSerialized($content)) { |
||
| 76 | $content = unserialize($content); |
||
| 77 | foreach ($content as $k => $item) { |
||
| 78 | if (is_string($item)) { |
||
| 79 | if (strpos($item, 'blocks_block_extmenu_topnav.tpl') !== false) { |
||
| 80 | $content[$k] = str_replace('blocks_block_extmenu_topnav.tpl', 'Block/Extmenu/topnav.tpl', $item); |
||
| 81 | } elseif (strpos($item, 'blocks_block_extmenu.tpl') !== false) { |
||
| 82 | $content[$k] = str_replace('blocks_block_extmenu.tpl', 'Block/Extmenu/extmenu.tpl', $item); |
||
| 83 | } elseif (strpos($item, 'menutree/blocks_block_menutree_') !== false) { |
||
| 84 | $content[$k] = str_replace('menutree/blocks_block_menutree_', 'Block/Menutree/', $item); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | $this->entityManager->getConnection()->executeUpdate("UPDATE blocks SET content=? WHERE bid=?", [serialize($content), $block['bid']]); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | // check if request is available (#2073) |
||
| 93 | $templateWarning = $this->__('Warning: Block template locations modified, you may need to fix your template overrides if you have any.'); |
||
| 94 | if (is_object($this->container->get('request')) && method_exists($this->container->get('request'), 'getSession') && is_object($this->container->get('request')->getSession())) { |
||
| 95 | $this->addFlash('warning', $templateWarning); |
||
| 96 | } |
||
| 97 | case '3.9.1': |
||
| 98 | // make all content fields of blocks serialized. |
||
| 99 | $sql = "SELECT * FROM blocks"; |
||
| 100 | $blocks = $this->entityManager->getConnection()->fetchAll($sql); |
||
| 101 | $oldContent = []; |
||
| 102 | foreach ($blocks as $block) { |
||
| 103 | $block['content'] = !empty($block['content']) ? $block['content'] : ''; |
||
| 104 | $oldContent[$block['bid']] = $this->isSerialized($block['content']) ? unserialize($block['content']) : ['content' => $block['content']]; |
||
| 105 | } |
||
| 106 | $this->schemaTool->update($this->entities); |
||
| 107 | $this->entityManager->getConnection()->executeQuery("UPDATE blocks SET properties='a:0:{}'"); |
||
| 108 | |||
| 109 | $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll(); |
||
| 110 | $installerHelper = new InstallerHelper(); |
||
| 111 | /** @var \Zikula\BlocksModule\Entity\BlockEntity $block */ |
||
| 112 | foreach ($blocks as $block) { |
||
| 113 | $block->setProperties($oldContent[$block->getBid()]); |
||
| 114 | $block->setFilters($installerHelper->upgradeFilterArray($block->getFilters())); |
||
| 115 | $block->setBlocktype(preg_match('/.*Block$/', $block->getBkey()) ? substr($block->getBkey(), 0, -5) : $block->getBkey()); |
||
| 116 | $block->setBkey($installerHelper->upgradeBkeyToFqClassname($this->container->get('kernel'), $block)); |
||
| 117 | } |
||
| 118 | $this->entityManager->flush(); |
||
| 119 | |||
| 120 | $collapseable = $this->getVar('collapseable'); |
||
| 121 | $this->setVar('collapseable', (bool) $collapseable); |
||
| 122 | |||
| 123 | case '3.9.2': |
||
| 124 | // convert Text and Html block types so properties is proper array |
||
| 125 | $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findBy(['blocktype' => ['Html', 'Text']]); |
||
| 126 | foreach ($blocks as $block) { |
||
| 127 | $properties = $block->getProperties(); |
||
| 128 | if (!is_array($properties)) { |
||
| 129 | $block->setProperties(['content' => $properties]); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | $this->entityManager->flush(); |
||
| 133 | case '3.9.3': |
||
| 134 | $this->schemaTool->drop(['Zikula\BlocksModule\Entity\UserBlockEntity']); |
||
| 135 | case '3.9.4': |
||
| 136 | // convert integer values to boolean for search block settings |
||
| 137 | $searchBlocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findBy(['blocktype' => 'Search']); |
||
| 138 | foreach ($searchBlocks as $searchBlock) { |
||
| 139 | $properties = $searchBlock->getProperties(); |
||
| 140 | $properties['displaySearchBtn'] = (bool) $properties['displaySearchBtn']; |
||
| 141 | if (isset($properties['active'])) { |
||
| 142 | foreach ($properties['active'] as $module => $active) { |
||
|
1 ignored issue
–
show
|
|||
| 143 | $properties['active'][$module] = (bool) $active; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | $searchBlock->setProperties($properties); |
||
| 147 | } |
||
| 148 | $this->entityManager->flush(); |
||
| 149 | case '3.9.5': |
||
| 150 | $loginBlocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findBy(['blocktype' => 'Login']); |
||
| 151 | foreach ($loginBlocks as $loginBlock) { |
||
| 152 | $filters = $loginBlock->getFilters(); |
||
| 153 | $filters[] = [ |
||
| 154 | 'attribute' => '_route', |
||
| 155 | 'queryParameter' => null, |
||
| 156 | 'comparator' => '!=', |
||
| 157 | 'value' => 'zikulausersmodule_access_login' |
||
| 158 | ]; |
||
| 159 | $loginBlock->setFilters($filters); |
||
| 160 | } |
||
| 161 | $this->entityManager->flush(); |
||
| 162 | case '3.9.6': |
||
| 163 | $blocks = $this->entityManager->getConnection()->executeQuery("SELECT * FROM blocks WHERE blocktype = 'Lang'"); |
||
| 164 | if (count($blocks) > 0) { |
||
| 165 | $this->entityManager->getConnection()->executeQuery("UPDATE blocks set bkey=?, blocktype=?, properties=? WHERE blocktype = 'Lang'", [ |
||
| 166 | 'ZikulaSettingsModule:Zikula\SettingsModule\Block\LocaleBlock', |
||
| 167 | 'Locale', |
||
| 168 | 'a:0:{}' |
||
| 169 | ]); |
||
| 170 | $this->addFlash('success', $this->__('All instances of LangBlock have been converted to LocaleBlock.')); |
||
| 171 | } |
||
| 172 | $this->entityManager->getConnection()->executeQuery("UPDATE group_perms SET component = REPLACE(component, 'Languageblock', 'LocaleBlock') WHERE component LIKE 'Languageblock%'"); |
||
| 173 | case '3.9.7': |
||
| 174 | // future upgrade routines |
||
| 175 | } |
||
| 176 | |||
| 177 | // Update successful |
||
| 178 | return true; |
||
| 179 | } |
||
| 180 | |||
| 290 |