From cd3b7788be68860dfda452be18874c805b2c527e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 25 Oct 2024 17:19:46 +0200 Subject: [PATCH] Ensure compatibility with ext-mongodb v2 --- src/Symfony/Component/Lock/Store/MongoDbStore.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Lock/Store/MongoDbStore.php b/src/Symfony/Component/Lock/Store/MongoDbStore.php index c4a20e800776f..22c9bb63350f1 100644 --- a/src/Symfony/Component/Lock/Store/MongoDbStore.php +++ b/src/Symfony/Component/Lock/Store/MongoDbStore.php @@ -17,7 +17,7 @@ use MongoDB\Database; use MongoDB\Driver\BulkWrite; use MongoDB\Driver\Command; -use MongoDB\Driver\Exception\WriteException; +use MongoDB\Driver\Exception\BulkWriteException; use MongoDB\Driver\Manager; use MongoDB\Driver\Query; use MongoDB\Exception\DriverRuntimeException; @@ -236,7 +236,7 @@ public function save(Key $key) try { $this->upsert($key, $this->initialTtl); - } catch (WriteException $e) { + } catch (BulkWriteException $e) { if ($this->isDuplicateKeyException($e)) { throw new LockConflictedException('Lock was acquired by someone else.', 0, $e); } @@ -262,7 +262,7 @@ public function putOffExpiration(Key $key, float $ttl) try { $this->upsert($key, $ttl); - } catch (WriteException $e) { + } catch (BulkWriteException $e) { if ($this->isDuplicateKeyException($e)) { throw new LockConflictedException('Failed to put off the expiration of the lock.', 0, $e); } @@ -348,7 +348,7 @@ private function upsert(Key $key, float $ttl): void $this->getManager()->executeBulkWrite($this->namespace, $write); } - private function isDuplicateKeyException(WriteException $e): bool + private function isDuplicateKeyException(BulkWriteException $e): bool { $code = $e->getCode(); @@ -371,7 +371,7 @@ private function getManager(): Manager */ private function createMongoDateTime(float $seconds): UTCDateTime { - return new UTCDateTime($seconds * 1000); + return new UTCDateTime((int) ($seconds * 1000)); } /**