#104561Use TYPO3 Connection in transactional
Description
Hello,
I just found method Connection::transactional(). You can use it like that:
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
$queryResult = $connection->transactional(function (\Doctrine\DBAL\Connection $transactionalConnection) use ($sql): ?Result {
try {
$transactionalConnection->executeStatement('SET profiling=1;');
$transactionalConnection->executeQuery($sql);
return $transactionalConnection->executeQuery('SHOW profile;');
} catch (Exception $e) {
}
return null;
});
As you see you have to use the Doctrine Connection object within the Callable. Else phpstan will fail.
What do you think? Can we implement our own interpretation of transactional into TYPO3 Connection where the Callables argument is of type TYPO3 Connection?
Nice greeting
Stefan