Skip to content

Commit d448e58

Browse files
authored
Merge pull request #4234 from morozov/remove-deprecated
Remove deprecated APIs
2 parents 1761e8d + bd29d17 commit d448e58

14 files changed

+8
-404
lines changed

UPGRADE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: change in the behavior of `SchemaManager::dropDatabase()`
4+
5+
When dropping a database, the DBAL no longer attempts to kill the client sessions that use the database.
6+
It's the responsibility of the operator to make sure that the database is not being used.
7+
38
## BC BREAK: removed `Synchronizer` package
49

510
The `Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer` interface and all its implementations have been removed.
@@ -156,6 +161,8 @@ The `Doctrine\DBAL\Driver::getName()` has been removed.
156161
* Removed `json_array` type and all associated hacks.
157162
* Removed `Connection::TRANSACTION_*` constants.
158163
* Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants.
164+
* Removed `AbstractPlatform::getSQLResultCasing()`, `::prefersSequences()` and `::supportsForeignKeyOnUpdate()` methods.
165+
* Removed `PostgreSqlPlatform::getDisallowDatabaseConnectionsSQL()` and `::getCloseActiveDatabaseConnectionsSQL()` methods.
159166
* Removed `MysqlSessionInit` listener.
160167
* Removed `MysqlPlatform::getCollationFieldDeclaration()`.
161168
* Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`.

src/Platforms/AbstractPlatform.php

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
24542454
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
24552455
{
24562456
$query = '';
2457-
if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
2457+
if ($foreignKey->hasOption('onUpdate')) {
24582458
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate'));
24592459
}
24602460

@@ -2565,19 +2565,6 @@ public function getColumnCollationDeclarationSQL($collation)
25652565
return $this->supportsColumnCollation() ? 'COLLATE ' . $collation : '';
25662566
}
25672567

2568-
/**
2569-
* Whether the platform prefers sequences for ID generation.
2570-
* Subclasses should override this method to return TRUE if they prefer sequences.
2571-
*
2572-
* @deprecated
2573-
*
2574-
* @return bool
2575-
*/
2576-
public function prefersSequences()
2577-
{
2578-
return false;
2579-
}
2580-
25812568
/**
25822569
* Whether the platform prefers identity columns (eg. autoincrement) for ID generation.
25832570
* Subclasses should override this method to return TRUE if they prefer identity columns.
@@ -3147,18 +3134,6 @@ public function supportsCreateDropForeignKeyConstraints(): bool
31473134
return true;
31483135
}
31493136

3150-
/**
3151-
* Whether this platform supports onUpdate in foreign key constraints.
3152-
*
3153-
* @deprecated
3154-
*
3155-
* @return bool
3156-
*/
3157-
public function supportsForeignKeyOnUpdate()
3158-
{
3159-
return $this->supportsForeignKeyConstraints();
3160-
}
3161-
31623137
/**
31633138
* Whether the platform supports database schemas.
31643139
*
@@ -3388,20 +3363,6 @@ public function supportsLimitOffset()
33883363
return true;
33893364
}
33903365

3391-
/**
3392-
* Gets the character casing of a column in an SQL result set of this platform.
3393-
*
3394-
* @deprecated
3395-
*
3396-
* @param string $column The column name for which to get the correct character casing.
3397-
*
3398-
* @return string The column name in the character casing used in SQL result sets.
3399-
*/
3400-
public function getSQLResultCasing($column)
3401-
{
3402-
return $column;
3403-
}
3404-
34053366
/**
34063367
* Maximum length of any given database identifier, like tables or column names.
34073368
*

src/Platforms/DB2Platform.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use function implode;
2020
use function sprintf;
2121
use function strpos;
22-
use function strtoupper;
2322

2423
class DB2Platform extends AbstractPlatform
2524
{
@@ -865,18 +864,6 @@ public function prefersIdentityColumns()
865864
return true;
866865
}
867866

868-
/**
869-
* {@inheritDoc}
870-
*
871-
* DB2 returns all column names in SQL result sets in uppercase.
872-
*
873-
* @deprecated
874-
*/
875-
public function getSQLResultCasing($column)
876-
{
877-
return strtoupper($column);
878-
}
879-
880867
/**
881868
* {@inheritDoc}
882869
*/

src/Platforms/OraclePlatform.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -965,16 +965,6 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
965965
return ['ALTER INDEX ' . $oldIndexName . ' RENAME TO ' . $index->getQuotedName($this)];
966966
}
967967

968-
/**
969-
* {@inheritDoc}
970-
*
971-
* @deprecated
972-
*/
973-
public function prefersSequences()
974-
{
975-
return true;
976-
}
977-
978968
/**
979969
* {@inheritdoc}
980970
*/
@@ -1052,18 +1042,6 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
10521042
return $query;
10531043
}
10541044

1055-
/**
1056-
* {@inheritDoc}
1057-
*
1058-
* Oracle returns all column names in SQL result sets in uppercase.
1059-
*
1060-
* @deprecated
1061-
*/
1062-
public function getSQLResultCasing($column)
1063-
{
1064-
return strtoupper($column);
1065-
}
1066-
10671045
/**
10681046
* {@inheritDoc}
10691047
*/
@@ -1112,16 +1090,6 @@ public function supportsSequences()
11121090
return true;
11131091
}
11141092

1115-
/**
1116-
* {@inheritDoc}
1117-
*
1118-
* @deprecated
1119-
*/
1120-
public function supportsForeignKeyOnUpdate()
1121-
{
1122-
return false;
1123-
}
1124-
11251093
/**
11261094
* {@inheritDoc}
11271095
*/

src/Platforms/PostgreSQL94Platform.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,6 @@ public function supportsCommentOnStatement()
209209
return true;
210210
}
211211

212-
/**
213-
* {@inheritDoc}
214-
*
215-
* @deprecated
216-
*/
217-
public function prefersSequences()
218-
{
219-
return true;
220-
}
221-
222212
/**
223213
* {@inheritDoc}
224214
*/
@@ -441,39 +431,6 @@ public function getCreateDatabaseSQL($name)
441431
return 'CREATE DATABASE ' . $name;
442432
}
443433

444-
/**
445-
* Returns the SQL statement for disallowing new connections on the given database.
446-
*
447-
* This is useful to force DROP DATABASE operations which could fail because of active connections.
448-
*
449-
* @deprecated
450-
*
451-
* @param string $database The name of the database to disallow new connections for.
452-
*
453-
* @return string
454-
*/
455-
public function getDisallowDatabaseConnectionsSQL($database)
456-
{
457-
return "UPDATE pg_database SET datallowconn = 'false' WHERE datname = " . $this->quoteStringLiteral($database);
458-
}
459-
460-
/**
461-
* Returns the SQL statement for closing currently active connections on the given database.
462-
*
463-
* This is useful to force DROP DATABASE operations which could fail because of active connections.
464-
*
465-
* @deprecated
466-
*
467-
* @param string $database The name of the database to close currently active connections for.
468-
*
469-
* @return string
470-
*/
471-
public function getCloseActiveDatabaseConnectionsSQL($database)
472-
{
473-
return 'SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '
474-
. $this->quoteStringLiteral($database);
475-
}
476-
477434
/**
478435
* {@inheritDoc}
479436
*/
@@ -1088,18 +1045,6 @@ public function getName()
10881045
return 'postgresql';
10891046
}
10901047

1091-
/**
1092-
* {@inheritDoc}
1093-
*
1094-
* PostgreSQL returns all column names in SQL result sets in lowercase.
1095-
*
1096-
* @deprecated
1097-
*/
1098-
public function getSQLResultCasing($column)
1099-
{
1100-
return strtolower($column);
1101-
}
1102-
11031048
/**
11041049
* {@inheritDoc}
11051050
*/

src/Schema/OracleSchemaManager.php

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
namespace Doctrine\DBAL\Schema;
44

55
use Doctrine\DBAL\DBALException;
6-
use Doctrine\DBAL\Driver\Exception;
76
use Doctrine\DBAL\Platforms\OraclePlatform;
87
use Doctrine\DBAL\Types\Type;
9-
use Throwable;
108

119
use function array_change_key_case;
1210
use function array_values;
1311
use function assert;
1412
use function preg_match;
15-
use function sprintf;
1613
use function str_replace;
1714
use function strpos;
1815
use function strtolower;
19-
use function strtoupper;
2016
use function trim;
2117

2218
use const CASE_LOWER;
@@ -26,35 +22,6 @@
2622
*/
2723
class OracleSchemaManager extends AbstractSchemaManager
2824
{
29-
/**
30-
* {@inheritdoc}
31-
*/
32-
public function dropDatabase($database)
33-
{
34-
try {
35-
parent::dropDatabase($database);
36-
} catch (DBALException $exception) {
37-
$exception = $exception->getPrevious();
38-
assert($exception instanceof Throwable);
39-
40-
if (! $exception instanceof Exception) {
41-
throw $exception;
42-
}
43-
44-
// If we have a error code 1940 (ORA-01940), the drop database operation failed
45-
// because of active connections on the database.
46-
// To force dropping the database, we first have to close all active connections
47-
// on that database and issue the drop database operation again.
48-
if ($exception->getCode() !== 1940) {
49-
throw $exception;
50-
}
51-
52-
$this->killUserSessions($database);
53-
54-
parent::dropDatabase($database);
55-
}
56-
}
57-
5825
/**
5926
* {@inheritdoc}
6027
*/
@@ -341,46 +308,6 @@ private function getQuotedIdentifierName($identifier)
341308
return $identifier;
342309
}
343310

344-
/**
345-
* Kills sessions connected with the given user.
346-
*
347-
* This is useful to force DROP USER operations which could fail because of active user sessions.
348-
*
349-
* @param string $user The name of the user to kill sessions for.
350-
*
351-
* @return void
352-
*
353-
* @throws DBALException
354-
*/
355-
private function killUserSessions($user)
356-
{
357-
$sql = <<<SQL
358-
SELECT
359-
s.sid,
360-
s.serial#
361-
FROM
362-
gv\$session s,
363-
gv\$process p
364-
WHERE
365-
s.username = ?
366-
AND p.addr(+) = s.paddr
367-
SQL;
368-
369-
$activeUserSessions = $this->_conn->fetchAllAssociative($sql, [strtoupper($user)]);
370-
371-
foreach ($activeUserSessions as $activeUserSession) {
372-
$activeUserSession = array_change_key_case($activeUserSession, CASE_LOWER);
373-
374-
$this->_execSql(
375-
sprintf(
376-
"ALTER SYSTEM KILL SESSION '%s, %s' IMMEDIATE",
377-
$activeUserSession['sid'],
378-
$activeUserSession['serial#']
379-
)
380-
);
381-
}
382-
}
383-
384311
/**
385312
* {@inheritdoc}
386313
*/

src/Schema/PostgreSqlSchemaManager.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Doctrine\DBAL\Schema;
44

55
use Doctrine\DBAL\DBALException;
6-
use Doctrine\DBAL\Exception\DriverException;
76
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
87
use Doctrine\DBAL\Types\Type;
98
use Doctrine\DBAL\Types\Types;
@@ -98,35 +97,6 @@ public function determineExistingSchemaSearchPaths()
9897
});
9998
}
10099

101-
/**
102-
* {@inheritdoc}
103-
*/
104-
public function dropDatabase($database)
105-
{
106-
try {
107-
parent::dropDatabase($database);
108-
} catch (DriverException $exception) {
109-
// If we have a SQLSTATE 55006, the drop database operation failed
110-
// because of active connections on the database.
111-
// To force dropping the database, we first have to close all active connections
112-
// on that database and issue the drop database operation again.
113-
if ($exception->getSQLState() !== '55006') {
114-
throw $exception;
115-
}
116-
117-
assert($this->_platform instanceof PostgreSQL94Platform);
118-
119-
$this->_execSql(
120-
[
121-
$this->_platform->getDisallowDatabaseConnectionsSQL($database),
122-
$this->_platform->getCloseActiveDatabaseConnectionsSQL($database),
123-
]
124-
);
125-
126-
parent::dropDatabase($database);
127-
}
128-
}
129-
130100
/**
131101
* {@inheritdoc}
132102
*/

0 commit comments

Comments
 (0)