Skip to content

Commit 1de1618

Browse files
committed
[Lock] Remove support of Doctrine DBAL in PostgreSqlStore
1 parent 6cef98a commit 1de1618

File tree

4 files changed

+6
-107
lines changed

4 files changed

+6
-107
lines changed

src/Symfony/Component/Lock/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CHANGELOG
66

77
* Remove the `NotSupportedException`. It shouldn't be thrown anymore
88
* Remove the `RetryTillSaveStore`. Logic has been moved in `Lock` and is not needed anymore
9-
* Remove support of Doctrine DBAL in `PdoStore`
9+
* Remove support of Doctrine DBAL in `PdoStore` and `PostgreSqlStore`
1010

1111
5.4
1212
---

src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,27 @@
2929
*/
3030
class DoctrineDbalPostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStoreInterface
3131
{
32-
private $conn;
32+
private Connection $conn;
3333
private static $storeRegistry = [];
3434

3535
/**
3636
* You can either pass an existing database connection a Doctrine DBAL Connection
3737
* or a URL that will be used to connect to the database.
3838
*
39-
* @param Connection|string $connOrUrl A Connection instance or Doctrine URL
40-
*
4139
* @throws InvalidArgumentException When first argument is not Connection nor string
4240
*/
43-
public function __construct($connOrUrl)
41+
public function __construct(Connection|string $connOrUrl)
4442
{
4543
if ($connOrUrl instanceof Connection) {
4644
if (!$connOrUrl->getDatabasePlatform() instanceof PostgreSQLPlatform) {
4745
throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" platform.', __CLASS__, \get_class($connOrUrl->getDatabasePlatform())));
4846
}
4947
$this->conn = $connOrUrl;
50-
} elseif (\is_string($connOrUrl)) {
48+
} else {
5149
if (!class_exists(DriverManager::class)) {
5250
throw new InvalidArgumentException(sprintf('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal".', $connOrUrl));
5351
}
5452
$this->conn = DriverManager::getConnection(['url' => $this->filterDsn($connOrUrl)]);
55-
} else {
56-
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be "%s" or string, "%s" given.', Connection::class, __METHOD__, get_debug_type($connOrUrl)));
5753
}
5854
}
5955

src/Symfony/Component/Lock/Store/PostgreSqlStore.php

+2-55
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Lock\Store;
1313

14-
use Doctrine\DBAL\Connection;
1514
use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
1615
use Symfony\Component\Lock\BlockingStoreInterface;
1716
use Symfony\Component\Lock\Exception\InvalidArgumentException;
@@ -27,15 +26,13 @@
2726
*/
2827
class PostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStoreInterface
2928
{
30-
private \PDO|Connection $conn;
29+
private \PDO $conn;
3130
private string $dsn;
3231
private string $username = '';
3332
private string $password = '';
3433
private array $connectionOptions = [];
3534
private static array $storeRegistry = [];
3635

37-
private $dbalStore;
38-
3936
/**
4037
* You can either pass an existing database connection as PDO instance or
4138
* a DSN string that will be used to lazy-connect to the database when the
@@ -52,23 +49,13 @@ class PostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStore
5249
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
5350
* @throws InvalidArgumentException When namespace contains invalid characters
5451
*/
55-
public function __construct(\PDO|Connection|string $connOrDsn, array $options = [])
52+
public function __construct(\PDO|string $connOrDsn, array $options = [])
5653
{
57-
if ($connOrDsn instanceof Connection || (\is_string($connOrDsn) && str_contains($connOrDsn, '://'))) {
58-
trigger_deprecation('symfony/lock', '5.4', 'Usage of a DBAL Connection with "%s" is deprecated and will be removed in symfony 6.0. Use "%s" instead.', __CLASS__, DoctrineDbalPostgreSqlStore::class);
59-
$this->dbalStore = new DoctrineDbalPostgreSqlStore($connOrDsn);
60-
61-
return;
62-
}
63-
6454
if ($connOrDsn instanceof \PDO) {
6555
if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
6656
throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __METHOD__));
6757
}
6858

69-
$this->conn = $connOrDsn;
70-
$this->checkDriver();
71-
} elseif ($connOrDsn instanceof Connection) {
7259
$this->conn = $connOrDsn;
7360
$this->checkDriver();
7461
} else {
@@ -82,12 +69,6 @@ public function __construct(\PDO|Connection|string $connOrDsn, array $options =
8269

8370
public function save(Key $key)
8471
{
85-
if (isset($this->dbalStore)) {
86-
$this->dbalStore->save($key);
87-
88-
return;
89-
}
90-
9172
// prevent concurrency within the same connection
9273
$this->getInternalStore()->save($key);
9374

@@ -110,12 +91,6 @@ public function save(Key $key)
11091

11192
public function saveRead(Key $key)
11293
{
113-
if (isset($this->dbalStore)) {
114-
$this->dbalStore->saveRead($key);
115-
116-
return;
117-
}
118-
11994
// prevent concurrency within the same connection
12095
$this->getInternalStore()->saveRead($key);
12196

@@ -139,12 +114,6 @@ public function saveRead(Key $key)
139114

140115
public function putOffExpiration(Key $key, float $ttl)
141116
{
142-
if (isset($this->dbalStore)) {
143-
$this->dbalStore->putOffExpiration($key);
144-
145-
return;
146-
}
147-
148117
// postgresql locks forever.
149118
// check if lock still exists
150119
if (!$this->exists($key)) {
@@ -154,12 +123,6 @@ public function putOffExpiration(Key $key, float $ttl)
154123

155124
public function delete(Key $key)
156125
{
157-
if (isset($this->dbalStore)) {
158-
$this->dbalStore->delete($key);
159-
160-
return;
161-
}
162-
163126
// Prevent deleting locks own by an other key in the same connection
164127
if (!$this->exists($key)) {
165128
return;
@@ -182,10 +145,6 @@ public function delete(Key $key)
182145

183146
public function exists(Key $key): bool
184147
{
185-
if (isset($this->dbalStore)) {
186-
return $this->dbalStore->exists($key);
187-
}
188-
189148
$sql = "SELECT count(*) FROM pg_locks WHERE locktype='advisory' AND objid=:key AND pid=pg_backend_pid()";
190149
$stmt = $this->getConnection()->prepare($sql);
191150

@@ -202,12 +161,6 @@ public function exists(Key $key): bool
202161

203162
public function waitAndSave(Key $key)
204163
{
205-
if (isset($this->dbalStore)) {
206-
$this->dbalStore->waitAndSave($key);
207-
208-
return;
209-
}
210-
211164
// prevent concurrency within the same connection
212165
// Internal store does not allow blocking mode, because there is no way to acquire one in a single process
213166
$this->getInternalStore()->save($key);
@@ -224,12 +177,6 @@ public function waitAndSave(Key $key)
224177

225178
public function waitAndSaveRead(Key $key)
226179
{
227-
if (isset($this->dbalStore)) {
228-
$this->dbalStore->waitAndSaveRead($key);
229-
230-
return;
231-
}
232-
233180
// prevent concurrency within the same connection
234181
// Internal store does not allow blocking mode, because there is no way to acquire one in a single process
235182
$this->getInternalStore()->saveRead($key);

src/Symfony/Component/Lock/Tests/Store/PostgreSqlDbalStoreTest.php

-44
This file was deleted.

0 commit comments

Comments
 (0)