diff --git a/Store/MongoDbStore.php b/Store/MongoDbStore.php index acac8bc..e9ce69a 100644 --- a/Store/MongoDbStore.php +++ b/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; @@ -225,7 +225,7 @@ public function save(Key $key): void 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); } @@ -249,7 +249,7 @@ public function putOffExpiration(Key $key, float $ttl): void 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); } @@ -332,7 +332,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(); @@ -355,7 +355,7 @@ private function getManager(): Manager */ private function createMongoDateTime(float $seconds): UTCDateTime { - return new UTCDateTime($seconds * 1000); + return new UTCDateTime((int) ($seconds * 1000)); } /**