[BUGFIX] Fix exception in QuickEdit mode for empty pages 10/50910/3
authorManuel Selbach <manuel_selbach@yahoo.de>
Thu, 8 Dec 2016 22:22:15 +0000 (23:22 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 13 Dec 2016 04:21:20 +0000 (05:21 +0100)
If there is no content on a page the parameter $this->eRParts[1] will be
set to e.g. /new/1 which is not an integer value and it will throw an
exception here on certain dbms, thus let's check that before as there could
not be a history on a new record and skip the query to prevent the error.

Change-Id: If33c5de067b7685e5723ceb7aa1586640abc99d8
Resolves: #78925
Releases: master, 7.6, 6.2
Reviewed-on: https://review.typo3.org/50910
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Alexander Stehlik <alexander.stehlik@gmail.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Classes/Controller/PageLayoutController.php

index 4ae3177..63dffed 100644 (file)
@@ -915,24 +915,32 @@ class PageLayoutController
         $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($tableName !== 'pages' && $this->EDIT_CONTENT || $tableName === 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
         // If undo-button should be rendered (depends on available items in sys_history)
         $this->undoButton = false;
-        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_history');
-        $queryBuilder->getRestrictions()->removeAll();
-        $this->undoButtonR = $queryBuilder->select('tstamp')
-            ->from('sys_history')
-            ->where(
-                $queryBuilder->expr()->eq(
-                    'tablename',
-                    $queryBuilder->createNamedParameter($tableName, \PDO::PARAM_STR)
-                ),
-                $queryBuilder->expr()->eq(
-                    'recuid',
-                    $queryBuilder->createNamedParameter($this->eRParts[1], \PDO::PARAM_INT)
+
+        // if there is no content on a page
+        // the parameter $this->eRParts[1] will be set to e.g. /new/1
+        // which is not an integer value and it will throw an exception here on certain dbms
+        // thus let's check that before as there cannot be a history for a new record
+        $this->undoButtonR = false;
+        if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
+            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_history');
+            $queryBuilder->getRestrictions()->removeAll();
+            $this->undoButtonR = $queryBuilder->select('tstamp')
+                ->from('sys_history')
+                ->where(
+                    $queryBuilder->expr()->eq(
+                        'tablename',
+                        $queryBuilder->createNamedParameter($tableName, \PDO::PARAM_STR)
+                    ),
+                    $queryBuilder->expr()->eq(
+                        'recuid',
+                        $queryBuilder->createNamedParameter($this->eRParts[1], \PDO::PARAM_INT)
+                    )
                 )
-            )
-            ->orderBy('tstamp', 'DESC')
-            ->setMaxResults(1)
-            ->execute()
-            ->fetch();
+                ->orderBy('tstamp', 'DESC')
+                ->setMaxResults(1)
+                ->execute()
+                ->fetch();
+        }
         if ($this->undoButtonR) {
             $this->undoButton = true;
         }