[BUGFIX] Avoid building SQL deleteClause expression if unused 84/50784/2
authorClaus Due <claus@namelesscoder.net>
Sat, 26 Nov 2016 13:43:57 +0000 (14:43 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 26 Nov 2016 19:30:48 +0000 (20:30 +0100)
This patch avoids building an instance of ConnectionPool,
getting a QueryBuilder and building an expression unless
that expression is needed by the function.

Also switches a condition with else clause to an early
return guard clause (cosmetic only).

Change-Id: I804b3ff9e624aa4b8b9c760d2a5e858039b6f9b9
Resolves: #78806
Releases: master
Reviewed-on: https://review.typo3.org/50784
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stephan GroƟberndt <stephan@grossberndt.de>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index d1763e5..029edc7 100644 (file)
@@ -83,18 +83,16 @@ class BackendUtility
      */
     public static function deleteClause($table, $tableAlias = '')
     {
+        if (empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) {
+            return '';
+        }
         $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable($table)
             ->expr();
-
-        if (!empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) {
-            return ' AND ' . $expressionBuilder->eq(
-                ($tableAlias ?: $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'],
-                0
-            );
-        } else {
-            return '';
-        }
+        return ' AND ' . $expressionBuilder->eq(
+            ($tableAlias ?: $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'],
+            0
+        );
     }
 
     /**