[BUGFIX] Fix DB error handling in FrontendUserImageUpdateWizard 30/53130/2
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Tue, 6 Jun 2017 03:45:19 +0000 (20:45 -0700)
committerFrank Naegler <frank.naegler@typo3.org>
Sat, 17 Jun 2017 16:15:07 +0000 (18:15 +0200)
The errorCode() method returns a string representation of the error that happened.
Comparing this to an integer value to determine is not reliable. In addition Doctrine
throws Exceptions when database statements fail so this part of the code could not be
reached.
Catch the DBALException, extract the error message and let the re-raised extension
bubble up to show the actual error message to the user.

Change-Id: I042b94329e3d52f9520ded812247ee78a73ea402
Resolves: #79870
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/53130
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/install/Classes/Updates/FrontendUserImageUpdateWizard.php

index 3989311..bb4d65a 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Install\Updates;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use Doctrine\DBAL\DBALException;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -191,35 +192,35 @@ class FrontendUserImageUpdateWizard extends AbstractUpdate
             ->removeAll()
             ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
 
-        $stmt = $queryBuilder
-            ->select('uid', 'pid', $this->fieldToMigrate)
-            ->from($this->table)
-            ->where(
-                $queryBuilder->expr()->isNotNull($this->fieldToMigrate),
-                $queryBuilder->expr()->neq(
-                    $this->fieldToMigrate,
-                    $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
-                ),
-                $queryBuilder->expr()->comparison(
-                    'CAST(CAST(' . $queryBuilder->quoteIdentifier($this->fieldToMigrate) . ' AS DECIMAL) AS CHAR)',
-                    ExpressionBuilder::NEQ,
-                    'CAST(' . $queryBuilder->quoteIdentifier($this->fieldToMigrate) . ' AS CHAR)'
+        try {
+            $result = $queryBuilder
+                ->select('uid', 'pid', $this->fieldToMigrate)
+                ->from($this->table)
+                ->where(
+                    $queryBuilder->expr()->isNotNull($this->fieldToMigrate),
+                    $queryBuilder->expr()->neq(
+                        $this->fieldToMigrate,
+                        $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
+                    ),
+                    $queryBuilder->expr()->comparison(
+                        'CAST(CAST(' . $queryBuilder->quoteIdentifier($this->fieldToMigrate) . ' AS DECIMAL) AS CHAR)',
+                        ExpressionBuilder::NEQ,
+                        'CAST(' . $queryBuilder->quoteIdentifier($this->fieldToMigrate) . ' AS CHAR)'
+                    )
                 )
-            )
-            ->orderBy('uid')
-            ->setFirstResult($limit)
-            ->execute();
+                ->orderBy('uid')
+                ->setFirstResult($limit)
+                ->execute();
 
-        $dbQueries[] = $queryBuilder->getSQL();
+            $dbQueries[] = $queryBuilder->getSQL();
 
-        if ($stmt->errorCode() > 0) {
+            return $result->fetchAll();
+        } catch (DBALException $e) {
             throw new \RuntimeException(
-                'Database query failed. Error was: ' . implode(CRLF, $stmt->errorInfo()),
+                'Database query failed. Error was: ' . $e->getPrevious()->getMessage(),
                 1476050084
             );
         }
-
-        return $stmt->fetchAll();
     }
 
     /**