diff --git a/src/Symfony/Component/Lock/CHANGELOG.md b/src/Symfony/Component/Lock/CHANGELOG.md index 2ffc9aefd72aa..45d08d29f36ba 100644 --- a/src/Symfony/Component/Lock/CHANGELOG.md +++ b/src/Symfony/Component/Lock/CHANGELOG.md @@ -6,7 +6,7 @@ CHANGELOG * Remove the `NotSupportedException`. It shouldn't be thrown anymore * Remove the `RetryTillSaveStore`. Logic has been moved in `Lock` and is not needed anymore -* Remove support of Doctrine DBAL in `PdoStore` +* Remove support of Doctrine DBAL in `PdoStore` and `PostgreSqlStore` 5.4 --- diff --git a/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php b/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php index b0c74a9b6de5d..8f3249177af26 100644 --- a/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php +++ b/src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php @@ -29,31 +29,27 @@ */ class DoctrineDbalPostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStoreInterface { - private $conn; + private Connection $conn; private static $storeRegistry = []; /** * You can either pass an existing database connection a Doctrine DBAL Connection * or a URL that will be used to connect to the database. * - * @param Connection|string $connOrUrl A Connection instance or Doctrine URL - * * @throws InvalidArgumentException When first argument is not Connection nor string */ - public function __construct($connOrUrl) + public function __construct(Connection|string $connOrUrl) { if ($connOrUrl instanceof Connection) { if (!$connOrUrl->getDatabasePlatform() instanceof PostgreSQLPlatform) { throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" platform.', __CLASS__, \get_class($connOrUrl->getDatabasePlatform()))); } $this->conn = $connOrUrl; - } elseif (\is_string($connOrUrl)) { + } else { if (!class_exists(DriverManager::class)) { throw new InvalidArgumentException(sprintf('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal".', $connOrUrl)); } $this->conn = DriverManager::getConnection(['url' => $this->filterDsn($connOrUrl)]); - } else { - throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be "%s" or string, "%s" given.', Connection::class, __METHOD__, get_debug_type($connOrUrl))); } } diff --git a/src/Symfony/Component/Lock/Store/PostgreSqlStore.php b/src/Symfony/Component/Lock/Store/PostgreSqlStore.php index 7310fde72c281..a7059d591f1b0 100644 --- a/src/Symfony/Component/Lock/Store/PostgreSqlStore.php +++ b/src/Symfony/Component/Lock/Store/PostgreSqlStore.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Lock\Store; -use Doctrine\DBAL\Connection; use Symfony\Component\Lock\BlockingSharedLockStoreInterface; use Symfony\Component\Lock\BlockingStoreInterface; use Symfony\Component\Lock\Exception\InvalidArgumentException; @@ -27,15 +26,13 @@ */ class PostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStoreInterface { - private \PDO|Connection $conn; + private \PDO $conn; private string $dsn; private string $username = ''; private string $password = ''; private array $connectionOptions = []; private static array $storeRegistry = []; - private $dbalStore; - /** * You can either pass an existing database connection as PDO instance or * a DSN string that will be used to lazy-connect to the database when the @@ -52,23 +49,13 @@ class PostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStore * @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION * @throws InvalidArgumentException When namespace contains invalid characters */ - public function __construct(\PDO|Connection|string $connOrDsn, array $options = []) + public function __construct(\PDO|string $connOrDsn, array $options = []) { - if ($connOrDsn instanceof Connection || (\is_string($connOrDsn) && str_contains($connOrDsn, '://'))) { - 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); - $this->dbalStore = new DoctrineDbalPostgreSqlStore($connOrDsn); - - return; - } - if ($connOrDsn instanceof \PDO) { if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) { 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__)); } - $this->conn = $connOrDsn; - $this->checkDriver(); - } elseif ($connOrDsn instanceof Connection) { $this->conn = $connOrDsn; $this->checkDriver(); } else { @@ -82,12 +69,6 @@ public function __construct(\PDO|Connection|string $connOrDsn, array $options = public function save(Key $key) { - if (isset($this->dbalStore)) { - $this->dbalStore->save($key); - - return; - } - // prevent concurrency within the same connection $this->getInternalStore()->save($key); @@ -110,12 +91,6 @@ public function save(Key $key) public function saveRead(Key $key) { - if (isset($this->dbalStore)) { - $this->dbalStore->saveRead($key); - - return; - } - // prevent concurrency within the same connection $this->getInternalStore()->saveRead($key); @@ -139,12 +114,6 @@ public function saveRead(Key $key) public function putOffExpiration(Key $key, float $ttl) { - if (isset($this->dbalStore)) { - $this->dbalStore->putOffExpiration($key); - - return; - } - // postgresql locks forever. // check if lock still exists if (!$this->exists($key)) { @@ -154,12 +123,6 @@ public function putOffExpiration(Key $key, float $ttl) public function delete(Key $key) { - if (isset($this->dbalStore)) { - $this->dbalStore->delete($key); - - return; - } - // Prevent deleting locks own by an other key in the same connection if (!$this->exists($key)) { return; @@ -182,10 +145,6 @@ public function delete(Key $key) public function exists(Key $key): bool { - if (isset($this->dbalStore)) { - return $this->dbalStore->exists($key); - } - $sql = "SELECT count(*) FROM pg_locks WHERE locktype='advisory' AND objid=:key AND pid=pg_backend_pid()"; $stmt = $this->getConnection()->prepare($sql); @@ -202,12 +161,6 @@ public function exists(Key $key): bool public function waitAndSave(Key $key) { - if (isset($this->dbalStore)) { - $this->dbalStore->waitAndSave($key); - - return; - } - // prevent concurrency within the same connection // Internal store does not allow blocking mode, because there is no way to acquire one in a single process $this->getInternalStore()->save($key); @@ -224,12 +177,6 @@ public function waitAndSave(Key $key) public function waitAndSaveRead(Key $key) { - if (isset($this->dbalStore)) { - $this->dbalStore->waitAndSaveRead($key); - - return; - } - // prevent concurrency within the same connection // Internal store does not allow blocking mode, because there is no way to acquire one in a single process $this->getInternalStore()->saveRead($key); diff --git a/src/Symfony/Component/Lock/Tests/Store/PostgreSqlDbalStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/PostgreSqlDbalStoreTest.php deleted file mode 100644 index b5b1194dd2109..0000000000000 --- a/src/Symfony/Component/Lock/Tests/Store/PostgreSqlDbalStoreTest.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Lock\Tests\Store; - -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; -use Symfony\Component\Lock\PersistingStoreInterface; -use Symfony\Component\Lock\Store\PostgreSqlStore; - -/** - * @author Jérémy Derussé - * - * @requires extension pdo_pgsql - * @group integration - * @group legacy - */ -class PostgreSqlDbalStoreTest extends AbstractStoreTest -{ - use BlockingStoreTestTrait; - use ExpectDeprecationTrait; - use SharedLockStoreTestTrait; - - /** - * {@inheritdoc} - */ - public function getStore(): PersistingStoreInterface - { - if (!getenv('POSTGRES_HOST')) { - $this->markTestSkipped('Missing POSTGRES_HOST env variable'); - } - - $this->expectDeprecation('Since symfony/lock 5.4: Usage of a DBAL Connection with "Symfony\Component\Lock\Store\PostgreSqlStore" is deprecated and will be removed in symfony 6.0. Use "Symfony\Component\Lock\Store\DoctrineDbalPostgreSqlStore" instead.'); - - return new PostgreSqlStore('pgsql://postgres:password@'.getenv('POSTGRES_HOST')); - } -}