Skip to content

Commit c4894f2

Browse files
minor symfony#58668 [Lock] Ensure compatibility with ext-mongodb v2 (GromNaN)
This PR was merged into the 6.4 branch. Discussion ---------- [Lock] Ensure compatibility with ext-mongodb v2 | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Same as symfony#58619 for branch 6.4 that was reworked by symfony#52336 Commits ------- cd3b778 Ensure compatibility with ext-mongodb v2
2 parents 948f55e + cd3b778 commit c4894f2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use MongoDB\Database;
1818
use MongoDB\Driver\BulkWrite;
1919
use MongoDB\Driver\Command;
20-
use MongoDB\Driver\Exception\WriteException;
20+
use MongoDB\Driver\Exception\BulkWriteException;
2121
use MongoDB\Driver\Manager;
2222
use MongoDB\Driver\Query;
2323
use MongoDB\Exception\DriverRuntimeException;
@@ -236,7 +236,7 @@ public function save(Key $key)
236236

237237
try {
238238
$this->upsert($key, $this->initialTtl);
239-
} catch (WriteException $e) {
239+
} catch (BulkWriteException $e) {
240240
if ($this->isDuplicateKeyException($e)) {
241241
throw new LockConflictedException('Lock was acquired by someone else.', 0, $e);
242242
}
@@ -262,7 +262,7 @@ public function putOffExpiration(Key $key, float $ttl)
262262

263263
try {
264264
$this->upsert($key, $ttl);
265-
} catch (WriteException $e) {
265+
} catch (BulkWriteException $e) {
266266
if ($this->isDuplicateKeyException($e)) {
267267
throw new LockConflictedException('Failed to put off the expiration of the lock.', 0, $e);
268268
}
@@ -348,7 +348,7 @@ private function upsert(Key $key, float $ttl): void
348348
$this->getManager()->executeBulkWrite($this->namespace, $write);
349349
}
350350

351-
private function isDuplicateKeyException(WriteException $e): bool
351+
private function isDuplicateKeyException(BulkWriteException $e): bool
352352
{
353353
$code = $e->getCode();
354354

@@ -371,7 +371,7 @@ private function getManager(): Manager
371371
*/
372372
private function createMongoDateTime(float $seconds): UTCDateTime
373373
{
374-
return new UTCDateTime($seconds * 1000);
374+
return new UTCDateTime((int) ($seconds * 1000));
375375
}
376376

377377
/**

0 commit comments

Comments
 (0)