From 3f2e3f2da04a15efcebd4368d252f742648af2e1 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:00:44 +0100 Subject: [PATCH 01/27] [GH-4019] Trigger deprecations for fetch mode deprecation to fetch* APIs. --- composer.json | 1 + lib/Doctrine/DBAL/Connection.php | 25 ++++++++++++++++++++++++ lib/Doctrine/DBAL/Statement.php | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/composer.json b/composer.json index 31ac0dda470..a4ce5a97755 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "php": "^7.3 || ^8", "ext-pdo": "*", "doctrine/cache": "^1.0", + "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0" }, "require-dev": { diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index c41e5ba90dc..5962ab273a9 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use Throwable; use Traversable; @@ -542,6 +543,12 @@ public function setAutoCommit($autoCommit) */ public function setFetchMode($fetchMode) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Default Fetch Mode configuration is deprecated, use explicit Connection::fetch*() APIs instead.' + ); + $this->defaultFetchMode = $fetchMode; } @@ -561,6 +568,12 @@ public function setFetchMode($fetchMode) */ public function fetchAssoc($sql, array $params = [], array $types = []) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Connection::fetchAssoc() is deprecated, use Connection::fetchAssociative() API instead.' + ); + return $this->executeQuery($sql, $params, $types)->fetch(FetchMode::ASSOCIATIVE); } @@ -578,6 +591,12 @@ public function fetchAssoc($sql, array $params = [], array $types = []) */ public function fetchArray($sql, array $params = [], array $types = []) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Connection::fetchArray() is deprecated, use Connection::fetchNumeric() API instead.' + ); + return $this->executeQuery($sql, $params, $types)->fetch(FetchMode::NUMERIC); } @@ -598,6 +617,12 @@ public function fetchArray($sql, array $params = [], array $types = []) */ public function fetchColumn($sql, array $params = [], $column = 0, array $types = []) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Connection::fetchColumn() is deprecated, use Connection::fetchOne() API instead.' + ); + return $this->executeQuery($sql, $params, $types)->fetchColumn($column); } diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 57843031eea..58365a927aa 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Exception\NoKeyValue; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use IteratorAggregate; use PDO; use PDOStatement; @@ -231,6 +232,12 @@ public function errorInfo() */ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Statement::setFetchMode() is deprecated, use explicit Statement::fetch*() APIs instead.' + ); + if ($arg2 === null) { return $this->stmt->setFetchMode($fetchMode); } @@ -251,6 +258,13 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) */ public function getIterator() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Statement::getIterator() is deprecated, use Statement::iterateNumeric(), iterateAssociative() ' . + 'or iterateColumn() instead.' + ); + return $this->stmt; } @@ -261,6 +275,12 @@ public function getIterator() */ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Statement::fetch() is deprecated, use Statement::fetchNumeric(), fetchAssociative() or fetchOne() instead.' + ); + return $this->stmt->fetch($fetchMode); } @@ -271,6 +291,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Statement::fetchAll() is deprecated, use Statement::fetchAllNumeric(), fetchAllAssociative() or ' . + 'fetchFirstColumn() instead.' + ); + if ($ctorArgs !== null) { return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs); } @@ -289,6 +316,12 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Statement::fetchColumn() is deprecated, use Statement::fetchOne() instead.' + ); + return $this->stmt->fetchColumn($columnIndex); } From 59148f49a9ba9cd1a63c9343a9d0981c02a7d8af Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:21:41 +0100 Subject: [PATCH 02/27] [GH-4054] Convert MasterSlaveConnection to Doctrine deprecations API. --- .../Connections/MasterSlaveConnection.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 0d5994e39ac..ccbcff31892 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -5,13 +5,9 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Driver; +use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; -use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; - /** * @deprecated Use PrimaryReadReplicaConnection instead * @@ -94,13 +90,12 @@ public function connect($connectionName = null) private function deprecated(string $thing, string $instead): void { - @trigger_error( - sprintf( - '%s is deprecated since doctrine/dbal 2.11 and will be removed in 3.0, use %s instead.', - $thing, - $instead - ), - E_USER_DEPRECATED + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4054', + '%s is deprecated since doctrine/dbal 2.11 and will be removed in 3.0, use %s instead.', + $thing, + $instead ); } } From f4773bda73e71d64618f00855b6066a90a967a90 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:43:58 +0100 Subject: [PATCH 03/27] [GH-3187] Convert binary column maxlength deprecation to Doctrine API. --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 8a56c91aac6..4e7d0a61eb0 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -26,6 +26,7 @@ use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; use UnexpectedValueException; @@ -54,9 +55,6 @@ use function strpos; use function strtolower; use function strtoupper; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Base class for all DatabasePlatforms. The DatabasePlatforms are the central @@ -301,12 +299,14 @@ public function getBinaryTypeDeclarationSQL(array $column) if ($column['length'] > $maxLength) { if ($maxLength > 0) { - @trigger_error(sprintf( + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3187', 'Binary column length %d is greater than supported by the platform (%d).' . ' Reduce the column length or use a BLOB column instead.', $column['length'], $maxLength - ), E_USER_DEPRECATED); + ); } return $this->getBlobTypeDeclarationSQL($column); From 0e1dfa628804b860edf08f3d156f97ca67e0ebb7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:48:14 +0100 Subject: [PATCH 04/27] [GH-3956] Convert CLI HelperSet deprecations to Doctrine API. --- .../Tools/Console/Command/ReservedWordsCommand.php | 11 +++++------ .../DBAL/Tools/Console/Command/RunSqlCommand.php | 11 +++++------ lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php | 10 +++++----- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index bd819af0e6a..4553a0a701e 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -23,6 +23,7 @@ use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords; use Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords; use Doctrine\DBAL\Tools\Console\ConnectionProvider; +use Doctrine\Deprecations\Deprecation; use Exception; use InvalidArgumentException; use Symfony\Component\Console\Command\Command; @@ -36,9 +37,6 @@ use function implode; use function is_array; use function is_string; -use function trigger_error; - -use const E_USER_DEPRECATED; class ReservedWordsCommand extends Command { @@ -74,9 +72,10 @@ public function __construct(?ConnectionProvider $connectionProvider = null) return; } - @trigger_error( - 'Not passing a connection provider as the first constructor argument is deprecated', - E_USER_DEPRECATED + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3956', + 'Not passing a connection provider as the first constructor argument is deprecated' ); } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index f7253866403..9a63696b6ff 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\DBAL\Tools\Dumper; +use Doctrine\Deprecations\Deprecation; use Exception; use LogicException; use RuntimeException; @@ -18,9 +19,6 @@ use function is_numeric; use function is_string; use function stripos; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Task for executing arbitrary SQL that can come from a file or directly from @@ -39,9 +37,10 @@ public function __construct(?ConnectionProvider $connectionProvider = null) return; } - @trigger_error( - 'Not passing a connection provider as the first constructor argument is deprecated', - E_USER_DEPRECATED + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3956', + 'Not passing a connection provider as the first constructor argument is deprecated' ); } diff --git a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php index 3d73388c73b..7fc14c340ae 100644 --- a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php @@ -8,15 +8,13 @@ use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\DBAL\Version; +use Doctrine\Deprecations\Deprecation; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\HelperSet; use TypeError; use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Handles running the Console Tools inside Symfony Console context. @@ -53,11 +51,13 @@ public static function run($helperSetOrConnectionProvider, $commands = []) $connectionProvider = null; if ($helperSetOrConnectionProvider instanceof HelperSet) { - @trigger_error(sprintf( + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3956', 'Passing an instance of "%s" as the first argument is deprecated. Pass an instance of "%s" instead.', HelperSet::class, ConnectionProvider::class - ), E_USER_DEPRECATED); + ); $connectionProvider = null; $cli->setHelperSet($helperSetOrConnectionProvider); } elseif ($helperSetOrConnectionProvider instanceof ConnectionProvider) { From c98bccbeaac23d2c3e8b71b60d9d3499cbdccb63 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:33:13 +0100 Subject: [PATCH 05/27] [GH-2846] Convert unknown Column options deprecation to Doctrine API. --- lib/Doctrine/DBAL/Schema/Column.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index f63bcc9226b..b2392d41bd9 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -3,14 +3,11 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function is_numeric; use function method_exists; -use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Object representation of a database column. @@ -80,11 +77,13 @@ public function setOptions(array $options) $method = 'set' . $name; if (! method_exists($this, $method)) { // next major: throw an exception - @trigger_error(sprintf( + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/2846', 'The "%s" column option is not supported,' . - ' setting it is deprecated and will cause an error in Doctrine DBAL 3.0', + ' setting unknown options is deprecated and will cause an error in Doctrine DBAL 3.0', $name - ), E_USER_DEPRECATED); + ); continue; } From 2f747374385aa90331e063059c392c8855264e72 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 19:05:38 +0100 Subject: [PATCH 06/27] [GH-4213] Add deprecation to SchemaSynchronizer API. --- .../Schema/Synchronizer/AbstractSchemaSynchronizer.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 7cfd1f2c00f..85f4ae6d3d0 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Schema\Synchronizer; use Doctrine\DBAL\Connection; +use Doctrine\Deprecations\Deprecation; use Throwable; /** @@ -18,6 +19,12 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer public function __construct(Connection $conn) { $this->conn = $conn; + + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4213', + 'SchemaSynchronizer API is deprecated without a replacement and will be removed in DBAL 3.0' + ); } /** From 705d3a2f8805c129f9ef9bf542ca68211c9ec966 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:59:49 +0100 Subject: [PATCH 07/27] [GH-4163] Add deprecation for Connection::exec, executeUpdate, query APIs. --- lib/Doctrine/DBAL/Connection.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 5962ab273a9..017cb5a0c9d 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1399,6 +1399,12 @@ public function project($sql, array $params, Closure $function) */ public function query() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4163', + 'Connection::query() is deprecated, use Connection::executeQuery() instead.' + ); + $connection = $this->getWrappedConnection(); $args = func_get_args(); @@ -1441,6 +1447,12 @@ public function query() */ public function executeUpdate($sql, array $params = [], array $types = []) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4163', + 'Connection::executeUpdate() is deprecated, use Connection::executeStatement() instead.' + ); + return $this->executeStatement($sql, $params, $types); } @@ -1519,6 +1531,12 @@ public function executeStatement($sql, array $params = [], array $types = []) */ public function exec($sql) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4163', + 'Connection::exec() is deprecated, use Connection::executeStatement() instead.' + ); + $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); From f33960fead4e282e497d7579da331b32c5c75abe Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 18:14:44 +0100 Subject: [PATCH 08/27] [GH-3088] Deprecate usage of PDO Fetch Mode and Param constants. --- lib/Doctrine/DBAL/Driver/PDOStatement.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 86d6a15d49e..d0539103566 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use PDO; use PDOException; @@ -13,10 +14,6 @@ use function assert; use function func_get_args; use function is_array; -use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * The PDO implementation of the Statement interface. @@ -274,10 +271,13 @@ private function convertParamType(int $type): int { if (! isset(self::PARAM_TYPE_MAP[$type])) { // TODO: next major: throw an exception - @trigger_error(sprintf( - 'Using a PDO parameter type (%d given) is deprecated and will cause an error in Doctrine DBAL 3.0', + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3088', + 'Using a PDO parameter type (%d given) is deprecated, ' . + 'use \Doctrine\DBAL\Types\Types constants instead.', $type - ), E_USER_DEPRECATED); + ); return $type; } @@ -293,12 +293,13 @@ private function convertParamType(int $type): int private function convertFetchMode(int $fetchMode): int { if (! isset(self::FETCH_MODE_MAP[$fetchMode])) { - // TODO: next major: throw an exception - @trigger_error(sprintf( - 'Using a PDO fetch mode or their combination (%d given)' . + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3088', + 'Using an unsupported PDO fetch mode or a bitmask of fetch modes (%d given)' . ' is deprecated and will cause an error in Doctrine DBAL 3.0', $fetchMode - ), E_USER_DEPRECATED); + ); return $fetchMode; } From 7b6554eb8bc92453b50967b520a012b0405c22a9 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 19:16:09 +0100 Subject: [PATCH 09/27] [GH-4132] Add deprecation for AbstractPlatform::fixSchemaElementName --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 6 ++++++ lib/Doctrine/DBAL/Platforms/OraclePlatform.php | 7 +++++++ lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 4e7d0a61eb0..a900cad025e 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -3511,6 +3511,12 @@ public function getSQLResultCasing($column) */ public function fixSchemaElementName($schemaElementName) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4132', + 'AbstractPlatform::fixSchemaElementName is deprecated with no replacement and removed in DBAL 3.0' + ); + return $schemaElementName; } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 9d2e44cbb8d..bfb6270c1c4 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\BinaryType; +use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; use function array_merge; @@ -1104,6 +1105,12 @@ public function getTimeFormatString() */ public function fixSchemaElementName($schemaElementName) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4132', + 'AbstractPlatform::fixSchemaElementName is deprecated with no replacement and removed in DBAL 3.0' + ); + if (strlen($schemaElementName) > 30) { // Trim it return substr($schemaElementName, 0, 30); diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 67dff2c6b10..48a36a77692 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; +use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; use function array_merge; @@ -72,6 +73,12 @@ public function appendLockHint($fromClause, $lockMode) */ public function fixSchemaElementName($schemaElementName) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4132', + 'AbstractPlatform::fixSchemaElementName is deprecated with no replacement and removed in DBAL 3.0' + ); + $maxIdentifierLength = $this->getMaxIdentifierLength(); if (strlen($schemaElementName) > $maxIdentifierLength) { From 8021e49950e5bbe13cbfd57b0859463333dfcd80 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 19:29:14 +0100 Subject: [PATCH 10/27] [GH-4229] Trigger deprecation for more AbstractPlatform deprecations. --- .../DBAL/Platforms/AbstractPlatform.php | 19 +++++++++++++++++++ .../DBAL/Platforms/OraclePlatform.php | 12 ++++++++++++ .../DBAL/Platforms/PostgreSqlPlatform.php | 7 +++++++ 3 files changed, 38 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index a900cad025e..bc9ce694be0 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2670,6 +2670,12 @@ public function getColumnCollationDeclarationSQL($collation) */ public function prefersSequences() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4229', + 'AbstractPlatform::prefersSequences() is deprecated without replacement and removed in DBAL 3.0' + ); + return false; } @@ -3241,6 +3247,12 @@ public function supportsForeignKeyConstraints() */ public function supportsForeignKeyOnUpdate() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4229', + 'AbstractPlatform::supportsForeignKeyOnUpdate() is deprecated without replacement and removed in DBAL 3.0' + ); + return $this->supportsForeignKeyConstraints(); } @@ -3496,6 +3508,13 @@ public function supportsLimitOffset() */ public function getSQLResultCasing($column) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4229', + 'AbstractPlatform::getSQLResultCasing is deprecated without replacement and removed in DBAL 3.' . + 'Use Portability\Connection with PORTABILITY_FIX_CASE to get portable result cases.' + ); + return $column; } diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index bfb6270c1c4..88b4325b7ce 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -974,6 +974,12 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) */ public function prefersSequences() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4229', + 'AbstractPlatform::prefersSequences() is deprecated without replacement and removed in DBAL 3.0' + ); + return true; } @@ -1142,6 +1148,12 @@ public function supportsSequences() */ public function supportsForeignKeyOnUpdate() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4229', + 'AbstractPlatform::supportsForeignKeyOnUpdate() is deprecated without replacement and removed in DBAL 3.0' + ); + return false; } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 9c1121cd985..3503d54d51f 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\IntegerType; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use UnexpectedValueException; use function array_diff; @@ -215,6 +216,12 @@ public function supportsCommentOnStatement() */ public function prefersSequences() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4229', + 'AbstractPlatform::prefersSequences() is deprecated without replacement and removed in DBAL 3.0' + ); + return true; } From 19120c9aadb09486c0ab4aab53f0e0460f49d317 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 19:40:30 +0100 Subject: [PATCH 11/27] [GH-4114] Add deprecation for ServerInfoAwareConnection::requiresQueryForServerVersion --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 7 +++++++ lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php | 7 +++++++ lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php | 7 +++++++ lib/Doctrine/DBAL/Driver/PDOConnection.php | 7 +++++++ .../DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php | 7 +++++++ lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php | 7 +++++++ 6 files changed, 42 insertions(+) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index bdc52551f52..419567a3a4e 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use stdClass; use function assert; @@ -82,6 +83,12 @@ public function getServerVersion() */ public function requiresQueryForServerVersion() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4114', + 'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.' + ); + return false; } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index a5a6da1a9f1..ec9c6a1b39c 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use mysqli; use function assert; @@ -135,6 +136,12 @@ public function getServerVersion() */ public function requiresQueryForServerVersion() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4114', + 'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.' + ); + return false; } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 02895a359e6..fd8de2901ef 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\OCI8\Exception\SequenceDoesNotExist; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use UnexpectedValueException; use function addcslashes; @@ -103,6 +104,12 @@ public function getServerVersion() */ public function requiresQueryForServerVersion() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4114', + 'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.' + ); + return false; } diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index 9b532a36383..5f8ccbeeb7d 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\PDO\Exception; use Doctrine\DBAL\Driver\PDO\Statement; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use PDO; use PDOException; use PDOStatement; @@ -113,6 +114,12 @@ public function lastInsertId($name = null) */ public function requiresQueryForServerVersion() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4114', + 'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.' + ); + return false; } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index ae5b13f4f58..29f0ba31544 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use function assert; use function func_get_args; @@ -198,6 +199,12 @@ public function quote($value, $type = ParameterType::STRING) */ public function requiresQueryForServerVersion() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4114', + 'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.' + ); + return true; } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 0bc7b68cb58..f1974ee6133 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\SQLSrv\Exception\Error; use Doctrine\DBAL\ParameterType; +use Doctrine\Deprecations\Deprecation; use function func_get_args; use function is_float; @@ -77,6 +78,12 @@ public function getServerVersion() */ public function requiresQueryForServerVersion() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4114', + 'ServerInfoAwareConnection::requiresQueryForServerVersion() is deprecated and removed in DBAL 3.' + ); + return false; } From 70b05528c1f78b6501dc2ee9bdea491f1fa9c0ab Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 19:44:53 +0100 Subject: [PATCH 12/27] [GH-4119] Add deprecation to Connection::ping. --- lib/Doctrine/DBAL/Connection.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 017cb5a0c9d..12d9a8f6af9 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -2142,6 +2142,12 @@ public function createQueryBuilder() */ public function ping() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4119', + 'Retry and reconnecting lost connections now happens automatically, ping() will be removed in DBAL 3.' + ); + $connection = $this->getWrappedConnection(); if ($connection instanceof PingableConnection) { From d1c94b0e3e3579db7df5c700f064925bdb871eb2 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 19:48:55 +0100 Subject: [PATCH 13/27] [GH-4112] Add deprecation for Driver\AbstractException::getErrorCode. --- lib/Doctrine/DBAL/Driver/AbstractException.php | 8 ++++++++ lib/Doctrine/DBAL/Driver/PDOException.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Doctrine/DBAL/Driver/AbstractException.php b/lib/Doctrine/DBAL/Driver/AbstractException.php index 65a9708ad65..22718783e36 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractException.php +++ b/lib/Doctrine/DBAL/Driver/AbstractException.php @@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\Deprecations\Deprecation; use Exception as BaseException; /** @@ -47,6 +48,13 @@ public function __construct($message, $sqlState = null, $errorCode = null) */ public function getErrorCode() { + /** @psalm-suppress ImpureMethodCall */ + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4112', + 'Driver\AbstractException::getErrorCode() is deprecated, use getSQLState() or getCode() instead.' + ); + return $this->errorCode; } diff --git a/lib/Doctrine/DBAL/Driver/PDOException.php b/lib/Doctrine/DBAL/Driver/PDOException.php index b2c01eb4430..8c0d05d2ab7 100644 --- a/lib/Doctrine/DBAL/Driver/PDOException.php +++ b/lib/Doctrine/DBAL/Driver/PDOException.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\PDO\Exception; +use Doctrine\Deprecations\Deprecation; /** * @deprecated Use {@link Exception} instead @@ -43,6 +44,13 @@ public function __construct(\PDOException $exception) */ public function getErrorCode() { + /** @psalm-suppress ImpureMethodCall */ + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4112', + 'Driver\AbstractException::getErrorCode() is deprecated, use getSQLState() or getCode() instead.' + ); + return $this->errorCode; } From 07972ceba76610100743d6918642e88229b72bc0 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 23:48:32 +0100 Subject: [PATCH 14/27] [GH-3823] Deprecate Connection::project --- lib/Doctrine/DBAL/Connection.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 12d9a8f6af9..bc3ba87833f 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1376,6 +1376,12 @@ public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp) */ public function project($sql, array $params, Closure $function) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3823', + 'Connection::project() is deprecated without replacement, implement data projections in your own code.' + ); + $result = []; $stmt = $this->executeQuery($sql, $params); From ec232ef09916c9545c78c2bc16947ea1377df175 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 23:51:49 +0100 Subject: [PATCH 15/27] [GH-3507] Add deprecation triggers to errorInfo/errorCode APIs. --- lib/Doctrine/DBAL/Connection.php | 12 ++++++++++++ lib/Doctrine/DBAL/Statement.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index bc3ba87833f..e0159a3e65c 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1582,6 +1582,12 @@ public function getTransactionNestingLevel() */ public function errorCode() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3507', + 'Connection::errorCode() is deprecated, use getCode() or getSQLState() on Exception instead.' + ); + return $this->getWrappedConnection()->errorCode(); } @@ -1592,6 +1598,12 @@ public function errorCode() */ public function errorInfo() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3507', + 'Connection::errorInfo() is deprecated, use getCode() or getSQLState() on Exception instead.' + ); + return $this->getWrappedConnection()->errorInfo(); } diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 58365a927aa..c11adbd280d 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -212,6 +212,12 @@ public function columnCount() */ public function errorCode() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3507', + 'Connection::errorCode() is deprecated, use getCode() or getSQLState() on Exception instead.' + ); + return $this->stmt->errorCode(); } @@ -222,6 +228,12 @@ public function errorCode() */ public function errorInfo() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3507', + 'Connection::errorInfo() is deprecated, use getCode() or getSQLState() on Exception instead.' + ); + return $this->stmt->errorInfo(); } From 74f4a287d5f00db673b3ca19206404a03f41012b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 6 Mar 2021 23:56:34 +0100 Subject: [PATCH 16/27] [GH-3935] Add deprecation trigger for EchoSQLLogger. --- lib/Doctrine/DBAL/Logging/EchoSQLLogger.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php index 9499d2ce643..1acd4e3b79f 100644 --- a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Logging; +use Doctrine\Deprecations\Deprecation; + use function var_dump; use const PHP_EOL; @@ -13,6 +15,15 @@ */ class EchoSQLLogger implements SQLLogger { + public function __construct() + { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3935', + 'EchoSQLLogger is deprecated without replacement, move the code into your project if you rely on it.' + ); + } + /** * {@inheritdoc} */ From 69a67af2777cca5d41e7f69fbc5334b3015ae886 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:00:57 +0100 Subject: [PATCH 17/27] [GH-3595] Trigger deprecation messages for Sharding APIs. --- lib/Doctrine/DBAL/Sharding/PoolingShardManager.php | 7 +++++++ .../DBAL/Sharding/SQLAzure/SQLAzureShardManager.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php index 81a197ee117..739cfaba6e1 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Sharding; use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; +use Doctrine\Deprecations\Deprecation; use RuntimeException; /** @@ -23,6 +24,12 @@ class PoolingShardManager implements ShardManager public function __construct(PoolingShardConnection $conn) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3595', + 'Native Sharding support in DBAL is removed without replacement.' + ); + $params = $conn->getParams(); $this->conn = $conn; $this->choser = $params['shardChoser']; diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php index d511553c155..83ad879f293 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Sharding\ShardingException; use Doctrine\DBAL\Sharding\ShardManager; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use RuntimeException; use function sprintf; @@ -40,6 +41,12 @@ class SQLAzureShardManager implements ShardManager */ public function __construct(Connection $conn) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3595', + 'Native Sharding support in DBAL is removed without replacement.' + ); + $this->conn = $conn; $params = $conn->getParams(); From d0b88d5910ad2c0044fb148703703399ec7acb34 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:04:36 +0100 Subject: [PATCH 18/27] [GH-3851] Trigger deprecation for ExpressionBuilder::andX/orX --- .../DBAL/Query/Expression/ExpressionBuilder.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php index f12ef0fa5f1..c86cfc32492 100644 --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Query\Expression; use Doctrine\DBAL\Connection; +use Doctrine\Deprecations\Deprecation; use function func_get_arg; use function func_get_args; @@ -71,6 +72,12 @@ public function or($expression, ...$expressions): CompositeExpression */ public function andX($x = null) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3851', + 'ExpressionBuilder::andX() is deprecated, use ExpressionBuilder::and() instead.' + ); + return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args()); } @@ -84,6 +91,12 @@ public function andX($x = null) */ public function orX($x = null) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3851', + 'ExpressionBuilder::orX() is deprecated, use ExpressionBuilder::or() instead.' + ); + return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args()); } From 7bcd6ebcc2d30ba96cf00d3dca2345d6ae779cf9 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:10:35 +0100 Subject: [PATCH 19/27] [GH-3844] Add deprecation message for CompositeExpression::add/addMultiple --- .../Query/Expression/CompositeExpression.php | 19 +++++++++++++++++++ .../Expression/CompositeExpressionTest.php | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php index 596e9fb3afc..463f321db68 100644 --- a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php +++ b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Query\Expression; use Countable; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function count; @@ -48,6 +49,12 @@ public function __construct($type, array $parts = []) $this->type = $type; $this->addMultiple($parts); + + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3864', + 'Do not use CompositeExpression constructor directly, use static and() and or() factory methods.' + ); } /** @@ -79,6 +86,12 @@ public static function or($part, ...$parts): self */ public function addMultiple(array $parts = []) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3844', + 'CompositeExpression::addMultiple() is deprecated, use CompositeExpression::with() instead.' + ); + foreach ($parts as $part) { $this->add($part); } @@ -97,6 +110,12 @@ public function addMultiple(array $parts = []) */ public function add($part) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3844', + 'CompositeExpression::add() is deprecated, use CompositeExpression::with() instead.' + ); + if (empty($part)) { return $this; } diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php index c1daefa4d35..40ef4742fcf 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php @@ -3,12 +3,18 @@ namespace Doctrine\Tests\DBAL\Query\Expression; use Doctrine\DBAL\Query\Expression\CompositeExpression; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\Tests\DbalTestCase; class CompositeExpressionTest extends DbalTestCase { + use VerifyDeprecations; + public function testCount(): void { + $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/issues/3844'); + $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/3864'); + $expr = CompositeExpression::or('u.group_id = 1'); self::assertCount(1, $expr); @@ -20,6 +26,9 @@ public function testCount(): void public function testAdd(): void { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/3864'); + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/issues/3844'); + $expr = CompositeExpression::or('u.group_id = 1'); self::assertCount(1, $expr); @@ -68,6 +77,8 @@ public function testWith(): void */ public function testCompositeUsageAndGeneration(string $type, array $parts, string $expects): void { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/3864'); + $expr = new CompositeExpression($type, $parts); self::assertEquals($expects, (string) $expr); From 6b909629642dd8e8b36fe3c298ef5cb53123718b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:24:17 +0100 Subject: [PATCH 20/27] [GH-3837] Trigger deprecation for QueryBuilder::select/addSelect/groupBy/addGroupBy with array argument. --- lib/Doctrine/DBAL/Query/QueryBuilder.php | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index c9637f8349a..1d9dc2d212e 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Types\Type; +use Doctrine\Deprecations\Deprecation; use function array_filter; use function array_key_exists; @@ -483,6 +484,15 @@ public function select($select = null/*, string ...$selects*/) return $this; } + if (is_array($select)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::select is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $selects = is_array($select) ? $select : func_get_args(); return $this->add('select', $selects); @@ -533,6 +543,15 @@ public function addSelect($select = null/*, string ...$selects*/) return $this; } + if (is_array($select)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::addSelect is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $selects = is_array($select) ? $select : func_get_args(); return $this->add('select', $selects, true); @@ -911,6 +930,15 @@ public function groupBy($groupBy/*, string ...$groupBys*/) return $this; } + if (is_array($groupBy)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::groupBy is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $groupBy = is_array($groupBy) ? $groupBy : func_get_args(); return $this->add('groupBy', $groupBy, false); @@ -940,6 +968,15 @@ public function addGroupBy($groupBy/*, string ...$groupBys*/) return $this; } + if (is_array($groupBy)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3837', + 'Passing an array for the first argument to QueryBuilder::addGroupBy is deprecated, ' . + 'pass each value as an individual variadic argument instead.' + ); + } + $groupBy = is_array($groupBy) ? $groupBy : func_get_args(); return $this->add('groupBy', $groupBy, true); From d314a78cbc20241bdbe37872171585655c74c084 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:43:21 +0100 Subject: [PATCH 21/27] [GH-3580] Several deprecation triggers. --- lib/Doctrine/DBAL/Connection.php | 28 +++++++++++++++++++ lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/Mysqli/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 7 +++++ .../DBAL/Driver/SQLAnywhere/Driver.php | 7 +++++ lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 7 +++++ .../DBAL/Event/ConnectionEventArgs.php | 22 +++++++++++++++ .../SchemaAlterTableAddColumnEventArgs.php | 10 +++++++ .../Event/SchemaColumnDefinitionEventArgs.php | 8 ++++++ .../Event/SchemaIndexDefinitionEventArgs.php | 10 +++++++ .../DBAL/Schema/AbstractSchemaManager.php | 11 ++++++++ 17 files changed, 166 insertions(+) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index e0159a3e65c..86d66046eaa 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -258,6 +258,13 @@ public function getDatabase() */ public function getHost() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Connection::getHost() is deprecated, get the database server host from application config ' . + 'or as a last resort from internal Connection::getParams() API.' + ); + return $this->params['host'] ?? null; } @@ -270,6 +277,13 @@ public function getHost() */ public function getPort() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Connection::getPort() is deprecated, get the database server port from application config ' . + 'or as a last resort from internal Connection::getParams() API.' + ); + return $this->params['port'] ?? null; } @@ -282,6 +296,13 @@ public function getPort() */ public function getUsername() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Connection::getUsername() is deprecated, get the username from application config ' . + 'or as a last resort from internal Connection::getParams() API.' + ); + return $this->params['user'] ?? null; } @@ -294,6 +315,13 @@ public function getUsername() */ public function getPassword() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Connection::getPassword() is deprecated, get the password from application config ' . + 'or as a last resort from internal Connection::getParams() API.' + ); + return $this->params['password'] ?? null; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index 056dbacd983..f4e50c9d4c6 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Driver\IBMDB2; use Doctrine\DBAL\Driver\AbstractDB2Driver; +use Doctrine\Deprecations\Deprecation; /** * IBM DB2 Driver. @@ -35,6 +36,12 @@ public function connect(array $params, $username = null, $password = null, array */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'ibm_db2'; } } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php index 9ac74f27d07..ca2df928902 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\AbstractMySQLDriver; use Doctrine\DBAL\Exception; +use Doctrine\Deprecations\Deprecation; class Driver extends AbstractMySQLDriver { @@ -24,6 +25,12 @@ public function connect(array $params, $username = null, $password = null, array */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'mysqli'; } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 5f7e3c0a9e8..c58ceaf8b54 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\AbstractOracleDriver; use Doctrine\DBAL\Exception; +use Doctrine\Deprecations\Deprecation; use const OCI_NO_AUTO_COMMIT; @@ -50,6 +51,12 @@ protected function _constructDsn(array $params) */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'oci8'; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index 0543d8786e7..875310ee848 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\AbstractDB2Driver; use Doctrine\DBAL\Driver\PDO\Connection; +use Doctrine\Deprecations\Deprecation; /** * Driver for the PDO IBM extension. @@ -58,6 +59,12 @@ private function _constructPdoDsn(array $params) */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'pdo_ibm'; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index 25eb2fbdb6f..70d56778d22 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Driver\AbstractMySQLDriver; use Doctrine\DBAL\Driver\PDO; use Doctrine\DBAL\Exception; +use Doctrine\Deprecations\Deprecation; use PDOException; /** @@ -73,6 +74,12 @@ protected function constructPdoDsn(array $params) */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'pdo_mysql'; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index b8e0a96f44e..a84c67fb618 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Driver\AbstractOracleDriver; use Doctrine\DBAL\Driver\PDO; use Doctrine\DBAL\Exception; +use Doctrine\Deprecations\Deprecation; use PDOException; /** @@ -54,6 +55,12 @@ private function constructPdoDsn(array $params) */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'pdo_oracle'; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index 83076aa8c06..bbdf23fdc2f 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; use Doctrine\DBAL\Driver\PDO; use Doctrine\DBAL\Exception; +use Doctrine\Deprecations\Deprecation; use PDOException; use function defined; @@ -116,6 +117,12 @@ private function _constructPdoDsn(array $params) */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'pdo_pgsql'; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index fc2b881ffce..efced0c0093 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\PDO; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\Deprecations\Deprecation; use PDOException; use function array_merge; @@ -81,6 +82,12 @@ protected function _constructPdoDsn(array $params) */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'pdo_sqlite'; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index d8f22505561..8784582eb37 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Driver\AbstractSQLServerDriver; use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost; use Doctrine\DBAL\Driver\PDO; +use Doctrine\Deprecations\Deprecation; use function is_int; use function sprintf; @@ -95,6 +96,12 @@ private function getConnectionOptionsDsn(array $connectionOptions): string */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'pdo_sqlsrv'; } } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 81d88232dca..98d5f3f302f 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver; use Doctrine\DBAL\Exception; +use Doctrine\Deprecations\Deprecation; use function array_keys; use function array_map; @@ -46,6 +47,12 @@ public function connect(array $params, $username = null, $password = null, array */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'sqlanywhere'; } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index a57128d9dd8..959dbcae1bd 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\AbstractSQLServerDriver; use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost; +use Doctrine\Deprecations\Deprecation; /** * Driver for ext/sqlsrv. @@ -57,6 +58,12 @@ public function connect(array $params, $username = null, $password = null, array */ public function getName() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Driver::getName() is deprecated' + ); + return 'sqlsrv'; } } diff --git a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php index 0b6ffbb9ded..35fadc40b54 100644 --- a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\Deprecations\Deprecation; /** * Event Arguments used when a Driver connection is established inside {@link Connection}. @@ -36,6 +37,13 @@ public function getConnection() */ public function getDriver() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'ConnectionEventArgs::getDriver() is deprecated, ' . + 'use ConnectionEventArgs::getConnection()->getDriver() instead.' + ); + return $this->connection->getDriver(); } @@ -46,6 +54,13 @@ public function getDriver() */ public function getDatabasePlatform() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'ConnectionEventArgs::getDatabasePlatform() is deprecated, ' . + 'use ConnectionEventArgs::getConnection()->getDatabasePlatform() instead.' + ); + return $this->connection->getDatabasePlatform(); } @@ -56,6 +71,13 @@ public function getDatabasePlatform() */ public function getSchemaManager() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'ConnectionEventArgs::getSchemaManager() is deprecated, ' . + 'use ConnectionEventArgs::getConnection()->getSchemaManager() instead.' + ); + return $this->connection->getSchemaManager(); } } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index 30a1a9ca78a..e61a48d064c 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\Deprecations\Deprecation; use function array_merge; use function func_get_args; @@ -67,6 +68,15 @@ public function getPlatform() */ public function addSql($sql) { + if (is_array($sql)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'Passing multiple SQL statements as an array to SchemaAlterTableAddColumnEventaArrgs::addSql() ' . + 'is deprecated. Pass each statement as an individual argument instead.' + ); + } + $this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args()); return $this; diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 7c962a928f4..4264e4b972e 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; +use Doctrine\Deprecations\Deprecation; /** * Event Arguments used when the portable column definition is generated inside {@link AbstractPlatform}. @@ -103,6 +104,13 @@ public function getConnection() */ public function getDatabasePlatform() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'SchemaColumnDefinitionEventArgs::getDatabasePlatform() is deprecated, ' . + 'use SchemaColumnDefinitionEventArgs::getConnection()->getDatabasePlatform() instead.' + ); + return $this->connection->getDatabasePlatform(); } } diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index 055a19a7c27..868243c8069 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Index; +use Doctrine\Deprecations\Deprecation; /** * Event Arguments used when the portable index definition is generated inside {@link AbstractSchemaManager}. @@ -83,10 +84,19 @@ public function getConnection() } /** + * @deprecated Use SchemaIndexDefinitionEventArgs::getConnection() and Connection::getDatabasePlatform() instead. + * * @return AbstractPlatform */ public function getDatabasePlatform() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'SchemaIndexDefinitionEventArgs::getDatabasePlatform() is deprecated, ' . + 'use SchemaIndexDefinitionEventArgs::getConnection()->getDatabasePlatform() instead.' + ); + return $this->connection->getDatabasePlatform(); } } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index df037f070e4..2cad11a86e5 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\Deprecations\Deprecation; use Throwable; use function array_filter; @@ -20,6 +21,7 @@ use function count; use function func_get_args; use function is_callable; +use function is_string; use function preg_match; use function str_replace; use function strtolower; @@ -197,6 +199,15 @@ public function listTableIndexes($table) */ public function tablesExist($names) { + if (is_string($names)) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/issues/3580', + 'The usage of a string $tableNames in AbstractSchemaManager::tablesExist is deprecated. ' . + 'Pass a one-element array instead.' + ); + } + $names = array_map('strtolower', (array) $names); return count($names) === count(array_intersect($names, array_map('strtolower', $this->listTableNames()))); From f3e971acb51b1cf74fa096667aa1d75d8098f56c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:49:38 +0100 Subject: [PATCH 22/27] [GH-3554] Trigger deprecation for passing user provided PDO instance. --- lib/Doctrine/DBAL/DriverManager.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index d4f90af796f..95a526b7faa 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Driver\PDO; use Doctrine\DBAL\Driver\SQLAnywhere; use Doctrine\DBAL\Driver\SQLSrv; +use Doctrine\Deprecations\Deprecation; use function array_keys; use function array_merge; @@ -217,6 +218,12 @@ public static function getConnection( } if (isset($params['pdo'])) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3554', + 'Passing a user provided PDO instance directly to Doctrine is deprecated.' + ); + $params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME); } From 7f777ae72fecc30c54e24a70110ce04279a35126 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:53:07 +0100 Subject: [PATCH 23/27] [GH-3572] Deprecation trigger for LoggerChain::addLogger --- lib/Doctrine/DBAL/Logging/LoggerChain.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Doctrine/DBAL/Logging/LoggerChain.php b/lib/Doctrine/DBAL/Logging/LoggerChain.php index 024afae283a..44d1db33665 100644 --- a/lib/Doctrine/DBAL/Logging/LoggerChain.php +++ b/lib/Doctrine/DBAL/Logging/LoggerChain.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Logging; +use Doctrine\Deprecations\Deprecation; + /** * Chains multiple SQLLogger. */ @@ -27,6 +29,12 @@ public function __construct(array $loggers = []) */ public function addLogger(SQLLogger $logger) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3572', + 'LoggerChain::addLogger() is deprecated, use LoggerChain constructor instead.' + ); + $this->loggers[] = $logger; } From b620d180a94add35a92268f2dcac5bbc3d4e3eb2 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 00:59:51 +0100 Subject: [PATCH 24/27] [GH-3316] Deprecate Configuration::get/setFilterSchemaAssetsExpression(). --- lib/Doctrine/DBAL/Configuration.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index f3131695729..ba288f339fe 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -5,6 +5,7 @@ use Doctrine\Common\Cache\Cache; use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\Schema\AbstractAsset; +use Doctrine\Deprecations\Deprecation; use function preg_match; @@ -79,6 +80,12 @@ public function setResultCacheImpl(Cache $cacheImpl) */ public function setFilterSchemaAssetsExpression($filterExpression) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3316', + 'Configuration::setFilterSchemaAssetsExpression() is deprecated, use setSchemaAssetsFilter() instead.' + ); + $this->_attributes['filterSchemaAssetsExpression'] = $filterExpression; if ($filterExpression) { $this->_attributes['filterSchemaAssetsExpressionCallable'] @@ -97,6 +104,12 @@ public function setFilterSchemaAssetsExpression($filterExpression) */ public function getFilterSchemaAssetsExpression() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3316', + 'Configuration::getFilterSchemaAssetsExpression() is deprecated, use getSchemaAssetsFilter() instead.' + ); + return $this->_attributes['filterSchemaAssetsExpression'] ?? null; } From 9ee8278d579cf2b219e85282ad4f49d4f5deb92c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 01:04:39 +0100 Subject: [PATCH 25/27] [GH-3255] Trigger deprecation for Type::getDefaultLength --- lib/Doctrine/DBAL/Types/Type.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 581bf44f66d..9a642b5cd65 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\Deprecations\Deprecation; use function array_map; use function get_class; @@ -173,6 +174,12 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getDefaultLength(AbstractPlatform $platform) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3255', + 'Type::getDefaultLength() is deprecated, use AbstractPlatform directly.' + ); + return null; } From 6a736f1f340689a82165643a8022bc161f956dd7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 01:06:51 +0100 Subject: [PATCH 26/27] [GH-3258] Trigger deprecation for Type::__toString(). --- lib/Doctrine/DBAL/Types/Type.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 9a642b5cd65..64e59fec068 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -315,6 +315,12 @@ static function (Type $type): string { */ public function __toString() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/3258', + 'Type::__toString() is deprecated, use Type::getName() or get_class($type) instead.' + ); + $type = static::class; $position = strrpos($type, '\\'); From 5a8523103ccc123c992473747a8df853165cf7cf Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 7 Mar 2021 10:51:04 +0100 Subject: [PATCH 27/27] [GH-4049] Trigger deprecation message for Statement::closeCursor --- lib/Doctrine/DBAL/Statement.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index c11adbd280d..f6f6ca5e726 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -190,6 +190,12 @@ public function execute($params = null) */ public function closeCursor() { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4049', + 'Statement::closeCursor() is deprecated, use Result::free() instead.' + ); + return $this->stmt->closeCursor(); }