| Conditions | 18 |
| Paths | 113 |
| Total Lines | 116 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 162 | protected function fetchAllPages($dbMounts): array |
||
| 163 | { |
||
| 164 | if (!empty($this->fullPageTree)) { |
||
| 165 | return $this->fullPageTree; |
||
| 166 | } |
||
| 167 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 168 | ->getQueryBuilderForTable('pages'); |
||
| 169 | $queryBuilder->getRestrictions() |
||
| 170 | ->removeAll() |
||
| 171 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
| 172 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->currentWorkspace)); |
||
| 173 | |||
| 174 | if (!empty($this->additionalQueryRestrictions)) { |
||
| 175 | foreach ($this->additionalQueryRestrictions as $additionalQueryRestriction) { |
||
| 176 | $queryBuilder->getRestrictions()->add($additionalQueryRestriction); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | $pageRecords = $queryBuilder |
||
| 181 | ->select(...$this->fields) |
||
| 182 | ->from('pages') |
||
| 183 | ->where( |
||
| 184 | // Only show records in default language |
||
| 185 | $queryBuilder->expr()->eq('sys_language_uid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)) |
||
| 186 | ) |
||
| 187 | ->execute() |
||
| 188 | ->fetchAll(); |
||
| 189 | |||
| 190 | $ids = array_column($pageRecords, 'uid'); |
||
| 191 | foreach ($dbMounts as $mount) { |
||
| 192 | $entryPointRootLine = BackendUtility::BEgetRootLine($mount, '', false, $this->fields); |
||
| 193 | foreach ($entryPointRootLine as $page) { |
||
| 194 | $pageId = (int)$page['uid']; |
||
| 195 | if (in_array($pageId, $ids) || $pageId === 0) { |
||
| 196 | continue; |
||
| 197 | } |
||
| 198 | $pageRecords[] = $page; |
||
| 199 | $ids[] = $pageId; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | $livePagePids = []; |
||
| 204 | $movePlaceholderData = []; |
||
| 205 | // This is necessary to resolve all IDs in a workspace |
||
| 206 | if ($this->currentWorkspace !== 0 && !empty($pageRecords)) { |
||
| 207 | $livePageIds = []; |
||
| 208 | foreach ($pageRecords as $pageRecord) { |
||
| 209 | $livePageIds[] = (int)$pageRecord['uid']; |
||
| 210 | $livePagePids[(int)$pageRecord['uid']] = (int)$pageRecord['pid']; |
||
| 211 | if ((int)$pageRecord['t3ver_state'] === VersionState::MOVE_PLACEHOLDER) { |
||
| 212 | $movePlaceholderData[$pageRecord['t3ver_move_id']] = [ |
||
| 213 | 'pid' => (int)$pageRecord['pid'], |
||
| 214 | 'sorting' => (int)$pageRecord['sorting'] |
||
| 215 | ]; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | // Resolve placeholders of workspace versions |
||
| 219 | $resolver = GeneralUtility::makeInstance( |
||
| 220 | PlainDataResolver::class, |
||
| 221 | 'pages', |
||
| 222 | $livePageIds |
||
| 223 | ); |
||
| 224 | $resolver->setWorkspaceId($this->currentWorkspace); |
||
| 225 | $resolver->setKeepDeletePlaceholder(false); |
||
| 226 | $resolver->setKeepMovePlaceholder(false); |
||
| 227 | $resolver->setKeepLiveIds(false); |
||
| 228 | $recordIds = $resolver->get(); |
||
| 229 | |||
| 230 | $queryBuilder->getRestrictions()->removeAll(); |
||
| 231 | $pageRecords = $queryBuilder |
||
| 232 | ->select(...$this->fields) |
||
| 233 | ->from('pages') |
||
| 234 | ->where( |
||
| 235 | $queryBuilder->expr()->in('uid', $recordIds) |
||
| 236 | ) |
||
| 237 | ->execute() |
||
| 238 | ->fetchAll(); |
||
| 239 | } |
||
| 240 | |||
| 241 | // Now set up sorting, nesting (tree-structure) for all pages based on pid+sorting fields |
||
| 242 | $groupedAndSortedPagesByPid = []; |
||
| 243 | foreach ($pageRecords as $pageRecord) { |
||
| 244 | $parentPageId = (int)$pageRecord['pid']; |
||
| 245 | // In case this is a record from a workspace |
||
| 246 | // The uid+pid of the live-version record is fetched |
||
| 247 | // This is done in order to avoid fetching records again (e.g. via BackendUtility::workspaceOL() |
||
| 248 | if ((int)$pageRecord['t3ver_oid'] > 0) { |
||
| 249 | // When a move pointer is found, the pid+sorting of the MOVE_PLACEHOLDER should be used (this is the |
||
| 250 | // workspace record holding this information), also the t3ver_state is set to the MOVE_PLACEHOLDER |
||
| 251 | // because the record is then added |
||
| 252 | if ((int)$pageRecord['t3ver_state'] === VersionState::MOVE_POINTER && !empty($movePlaceholderData[$pageRecord['t3ver_oid']])) { |
||
| 253 | $parentPageId = (int)$movePlaceholderData[$pageRecord['t3ver_oid']]['pid']; |
||
| 254 | $pageRecord['sorting'] = (int)$movePlaceholderData[$pageRecord['t3ver_oid']]['sorting']; |
||
| 255 | $pageRecord['t3ver_state'] = VersionState::MOVE_PLACEHOLDER; |
||
| 256 | } else { |
||
| 257 | // Just a record in a workspace (not moved etc) |
||
| 258 | $parentPageId = (int)$livePagePids[$pageRecord['t3ver_oid']]; |
||
| 259 | } |
||
| 260 | // this is necessary so the links to the modules are still pointing to the live IDs |
||
| 261 | $pageRecord['uid'] = (int)$pageRecord['t3ver_oid']; |
||
| 262 | $pageRecord['pid'] = $parentPageId; |
||
| 263 | } |
||
| 264 | |||
| 265 | $sorting = (int)$pageRecord['sorting']; |
||
| 266 | while (isset($groupedAndSortedPagesByPid[$parentPageId][$sorting])) { |
||
| 267 | $sorting++; |
||
| 268 | } |
||
| 269 | $groupedAndSortedPagesByPid[$parentPageId][$sorting] = $pageRecord; |
||
| 270 | } |
||
| 271 | |||
| 272 | $this->fullPageTree = [ |
||
| 273 | 'uid' => 0, |
||
| 274 | 'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?: 'TYPO3' |
||
| 275 | ]; |
||
| 276 | $this->addChildrenToPage($this->fullPageTree, $groupedAndSortedPagesByPid); |
||
| 277 | return $this->fullPageTree; |
||
| 278 | } |
||
| 316 |