[CLEANUP] CGL issues and missing sql_free_result() 55/42555/4
authorStephan Großberndt <stephan@grossberndt.de>
Thu, 13 Aug 2015 07:01:01 +0000 (09:01 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 13 Aug 2015 15:08:13 +0000 (17:08 +0200)
Fix CGL issues and missing sql_free_result()-statements introduced by
https://review.typo3.org/#/c/8719/19

Resolves: #69006
Related: #33436
Releases: master
Change-Id: I6cfb5c2aa33c896ed6b813bfbe160de55d82a291
Reviewed-on: http://review.typo3.org/42555
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php
typo3/sysext/frontend/Classes/Page/PageRepository.php

index 73c0458..4bc545c 100644 (file)
@@ -688,6 +688,7 @@ abstract class AbstractMenuContentObject {
         */
        protected function prepareMenuItemsForDirectoryMenu($specialValue, $sortingField) {
                $tsfe = $this->getTypoScriptFrontendController();
+               $databaseConnection = $this->getDatabaseConnection();
                $menuItems = array();
                if ($specialValue == '') {
                        $specialValue = $tsfe->page['uid'];
@@ -708,8 +709,8 @@ abstract class AbstractMenuContentObject {
                                $id = $mount_info['mount_pid'];
                        }
                        // Get sub-pages:
-                       $res = $this->getDatabaseConnection()->exec_SELECTquery('uid', 'pages', 'pid=' . intval($id) . $this->sys_page->where_hid_del, '', $sortingField);
-                       while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
+                       $res = $databaseConnection->exec_SELECTquery('uid', 'pages', 'pid=' . intval($id) . $this->sys_page->where_hid_del, '', $sortingField);
+                       while ($row = $databaseConnection->sql_fetch_assoc($res)) {
                                $row = $this->sys_page->getPage($row['uid']);
                                $tsfe->sys_page->versionOL('pages', $row, TRUE);
                                if (!empty($row)) {
@@ -738,6 +739,7 @@ abstract class AbstractMenuContentObject {
                                        }
                                }
                        }
+                       $databaseConnection->sql_free_result($res);
                }
                return $menuItems;
        }
index bce86e0..c7fb2b9 100644 (file)
@@ -542,22 +542,24 @@ class PageRepository {
         * @see \TYPO3\CMS\WizardCrpages\Controller\CreatePagesWizardModuleFunctionController, \TYPO3\CMS\WizardSortpages\View\SortPagesWizardModuleFunction
         */
        public function getMenu($uid, $fields = '*', $sortField = 'sorting', $addWhere = '', $checkShortcuts = TRUE) {
+               $databaseConnection = $this->getDatabaseConnection();
                $output = array();
-               $query = 'pid IN (' . implode(',', $this->getDatabaseConnection()->cleanIntArray((array)$uid)) .
+               $query = 'pid IN (' . implode(',', $databaseConnection->cleanIntArray((array)$uid)) .
                        ')' . $this->where_hid_del . $this->where_groupAccess . ' ' . $addWhere;
-               if ($this->versioningWorkspaceId != 0) {
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+               if ((int)$this->versioningWorkspaceId !== 0) {
+                       $res = $databaseConnection->exec_SELECTquery(
                                'uid',
                                'pages',
-                               'pid IN (' . implode(',', $this->getDatabaseConnection()->cleanIntArray((array)$uid)) .
+                               'pid IN (' . implode(',', $databaseConnection->cleanIntArray((array)$uid)) .
                                ')' . $this->where_hid_del . ' ' . $addWhere,
                                '',
                                $sortField
                        );
-                       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                       $workspaceRow = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, 'pages', $row['uid']);
-                       $realUid = is_array($workspaceRow) ? $workspaceRow['uid'] : $row['uid'];
-                               $result = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
+                       $recordArray = array();
+                       while ($row = $databaseConnection->sql_fetch_assoc($res)) {
+                               $workspaceRow = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, 'pages', $row['uid']);
+                               $realUid = is_array($workspaceRow) ? $workspaceRow['uid'] : $row['uid'];
+                               $result = $databaseConnection->exec_SELECTgetSingleRow(
                                        'uid',
                                        'pages',
                                        'uid=' . intval($realUid) . $this->where_hid_del . $this->where_groupAccess . ' ' . $addWhere,
@@ -568,12 +570,13 @@ class PageRepository {
                                        $recordArray[] = $row['uid'];
                                }
                        }
-                       if (is_array($recordArray)) {
+                       $databaseConnection->sql_free_result($res);
+                       if (!empty($recordArray)) {
                                $query = 'uid IN (' . implode(',', $recordArray) . ')';
                        }
                };
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'pages', $query, '', $sortField);
-               while (($row = $this->getDatabaseConnection()->sql_fetch_assoc($res))) {
+               $res = $databaseConnection->exec_SELECTquery($fields, 'pages', $query, '', $sortField);
+               while ($row = $databaseConnection->sql_fetch_assoc($res)) {
                        $this->versionOL('pages', $row, TRUE);
                        if (is_array($row)) {
                                // Keep mount point:
@@ -612,7 +615,7 @@ class PageRepository {
                                                $searchField = 'uid';
                                                $searchUid = $row['pid'];
                                        }
-                                       $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'pages', $searchField . '=' . $searchUid . $this->where_hid_del . $this->where_groupAccess . ' ' . $addWhere);
+                                       $count = $databaseConnection->exec_SELECTcountRows('uid', 'pages', $searchField . '=' . $searchUid . $this->where_hid_del . $this->where_groupAccess . ' ' . $addWhere);
                                        if (!$count) {
                                                unset($row);
                                        }
@@ -625,7 +628,7 @@ class PageRepository {
                                }
                        }
                }
-               $this->getDatabaseConnection()->sql_free_result($res);
+               $databaseConnection->sql_free_result($res);
         // Finally load language overlays
                return $this->getPagesOverlay($output);
        }