Commit b29c18aa authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Andreas Fernandez
Browse files

[BUGFIX] FormEngine: Catch Database errors and log error message

Change-Id: I010ebf2811075e2f92ce790afc45fec3144c4b56
Resolves: #77832
Releases: master
Reviewed-on: https://review.typo3.org/49842

Tested-by: default avatarBamboo TYPO3com <info@typo3.com>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
parent 43fa0a66
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
* The TYPO3 project - inspiring people to share!
*/
use Doctrine\DBAL\DBALException;
use TYPO3\CMS\Backend\Module\ModuleLoader;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
......@@ -432,10 +433,13 @@ abstract class AbstractItemProvider
}
$queryBuilder = $this->buildForeignTableQueryBuilder($result, $fieldName);
$queryResult = $queryBuilder->execute();
try {
$queryResult = $queryBuilder->execute();
} catch (DBALException $e) {
$databaseError = $e->getPrevious()->getMessage();
}
// Early return on error with flash message
$databaseError = $queryResult->errorInfo();
if (!empty($databaseError)) {
$msg = $databaseError . '. ';
$msg .= $languageService->sL('LLL:EXT:lang/locallang_core.xlf:error.database_schema_mismatch');
......@@ -447,7 +451,6 @@ abstract class AbstractItemProvider
/** @var $defaultFlashMessageQueue FlashMessageQueue */
$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
$defaultFlashMessageQueue->enqueue($flashMessage);
$queryResult->closeCursor();
return $items;
}
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
* The TYPO3 project - inspiring people to share!
*/
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Statement;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
......@@ -116,7 +117,6 @@ class TcaSelectItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->errorInfo()->shouldBeCalled();
$statementProphet->fetch()->shouldBeCalled();
$queryBuilderProphet->select('foreignTable.uid')
......@@ -1849,8 +1849,6 @@ class TcaSelectItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->errorInfo()->shouldBeCalled()->willReturn('anError');
$statementProphet->closeCursor()->shouldBeCalled();
$queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
......@@ -1858,7 +1856,11 @@ class TcaSelectItemsTest extends UnitTestCase
$queryBuilderProphet->where('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->andWhere(' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->andWhere('`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
$prevException = new DBALException('Invalid table name', 400);
$exception = new DBALException('Driver error', 500, $prevException);
$queryBuilderProphet->execute()->shouldBeCalled()->willThrow($exception);
// Two instances are needed due to the push/pop behavior of addInstance()
GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
......@@ -1925,7 +1927,6 @@ class TcaSelectItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->errorInfo()->shouldBeCalled();
$queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
......@@ -2023,7 +2024,6 @@ class TcaSelectItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->errorInfo()->shouldBeCalled();
$queryBuilderProphet->select('fTable.uid', 'fTable.icon')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
......
......@@ -80,7 +80,6 @@ class TcaSelectTreeItemsTest extends UnitTestCase
/** @var Statement|ObjectProphecy $statementProphet */
$statementProphet = $this->prophesize(Statement::class);
$statementProphet->errorInfo()->shouldBeCalled();
$statementProphet->fetch()->shouldBeCalled();
$restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment