[BUGFIX] Fix functional tests for EXT:workspaces on PostgreSQL 31/51731/4
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 17 Feb 2017 07:07:24 +0000 (23:07 -0800)
committerMarkus Klein <markus.klein@typo3.org>
Sun, 19 Feb 2017 23:10:58 +0000 (00:10 +0100)
Detect errors during execution of SQL statements using the
exceptions thrown by Doctrine DBAL instead of trying to use
Connection::errorCode().

The previous code doesn't work on MySQL if an actual error
occurs since an exception would be thrown earlier in the
process and the relevant code path would not be reached.

The happy path worked before because MySQL returns 0 as the
code when a statement executed successfully while PostgreSQL
returns '00000' which PHP does not consider to be empty.

Resolves: #79801
Releases: master
Change-Id: I508966b6731d256d1edff2267669d158a8d647bf
Reviewed-on: https://review.typo3.org/51731
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
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/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts
typo3/sysext/version/Classes/Hook/DataHandlerHook.php

index 78c9606..10d9852 100644 (file)
@@ -239,6 +239,7 @@ page {
 }
 
 [globalVar = LIT:postgresql = {$databasePlatform}]
+page.10.15.select.where.wrap = "parenttable" = 'pages' AND parentid=|
 page.10.20.select.where = "colPos" = 0
 page.10.20.renderObj.20.select.where.wrap = "parenttable" = 'tt_content' AND "parentid" = |
 page.10.20.renderObj.20.renderObj.10.select.where.wrap = "parenttable" = 'tx_irretutorial_1nff_hotel' AND "parentid" = |
index 2aabae3..6d328b3 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Version\Hook;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Doctrine\DBAL\DBALException;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -917,27 +918,29 @@ class DataHandlerHook
         // Execute swapping:
         $sqlErrors = [];
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
-        $connection->update(
-            $table,
-            $swapVersion,
-            ['uid' => (int)$id]
-        );
-
-        if ($connection->errorCode()) {
-            $sqlErrors[] = $connection->errorInfo();
-        } else {
+        try {
             $connection->update(
                 $table,
-                $curVersion,
-                ['uid' => (int)$swapWith]
+                $swapVersion,
+                ['uid' => (int)$id]
             );
+        } catch (DBALException $e) {
+            $sqlErrors[] = $e->getPrevious()->getMessage();
+        }
 
-            if ($connection->errorCode()) {
-                $sqlErrors[] = $connection->errorInfo();
-            } else {
+        if (empty($sqlErrors)) {
+            try {
+                $connection->update(
+                    $table,
+                    $curVersion,
+                    ['uid' => (int)$swapWith]
+                );
                 unlink($lockFileName);
+            } catch (DBALException $e) {
+                $sqlErrors[] = $e->getPrevious()->getMessage();
             }
         }
+
         if (!empty($sqlErrors)) {
             $dataHandler->newlog('During Swapping: SQL errors happened: ' . implode('; ', $sqlErrors), 2);
         } else {