typo3-rector
typo3-rector copied to clipboard
Breaking: #102875 - Changed Connection method signatures and behaviour
Breaking: #102875 - Changed Connection method signatures and behaviour
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102875-ChangedConnectionMethodSignaturesAndBehaviour.html
Breaking: #102875 - Changed Connection method signatures and behaviour
See 102875
Description
Signature and behaviour of following methods has been changed:
-
lastInsertId()
no longer accepts the sequence and field name. -
quote()
no longer has a type argument and the value must be a string.
Public Connection::PARAM_*
class constants has been replaced with the
Doctrine DBAL 4 ParameterType
and ArrayParameterType
enum
definitions.
[!NOTE] Doctrine DBAL dropped the support for using the
\PDO::PARAM_*
constants in favour of the enum types on several methods. Be aware of this and use the\TYPO3\CMS\Core\Database\Connection::PARAM_*
constants to reduce required work on upgrading.
Impact
Calling quote()
with a non-string as first argument will result in a
PHP error. Still providing the second argument will not emit an error,
but may be detected by static code analysers.
Calling lastInsertId()
not directly after the record insert or
inserting records in another table in between will return the incorrect
value.
Affected installations
Only installations calling quote()
with a non-string as first argument
or not using lastInsertId()
directly after the record insert.
Migration
lastInsertId()
Returns the last inserted ID (auto-created) on the connection.
[!NOTE] That means, that the last inserted id needs to be retrieved directly before inserting a record to another table. That should be the usual workflow used in the wild - but be aware of this.
BEFORE
use TYPO3\CMS\Core\Database\Connection as Typo3Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/** @var Typo3Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_myextension_mytable');
$connection->insert(
'tx_myextension_mytable',
[
'pid' => $pid,
'some_string' => $someString,
],
[
Typo3Connection::PARAM_INT,
Typo3Connection::PARAM_STR,
]
);
$uid = $connection->lastInsertId('tx_myextension_mytable');
AFTER
use TYPO3\CMS\Core\Database\Connection as Typo3Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/** @var Typo3Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_myextension_mytable');
$connection->insert(
'tx_myextension_mytable',
[
'pid' => $pid,
'some_string' => $someString,
],
[
Typo3Connection::PARAM_INT,
Typo3Connection::PARAM_STR,
]
);
$uid = $connection->lastInsertId();
Database, PHP-API, NotScanned, ext:core
https://github.com/rectorphp/rector-doctrine/blob/main/config/sets/doctrine-dbal-40.php