Skip to content

Commit f85ebc5

Browse files
committed
Ensure compatibility with mongodb v2
1 parent 579b514 commit f85ebc5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Store/MongoDbStore.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use MongoDB\BSON\UTCDateTime;
1515
use MongoDB\Client;
1616
use MongoDB\Collection;
17-
use MongoDB\Driver\Exception\WriteException;
17+
use MongoDB\Driver\Exception\BulkWriteException;
1818
use MongoDB\Driver\ReadPreference;
1919
use MongoDB\Exception\DriverRuntimeException;
2020
use MongoDB\Exception\InvalidArgumentException as MongoInvalidArgumentException;
@@ -209,7 +209,7 @@ public function save(Key $key)
209209

210210
try {
211211
$this->upsert($key, $this->initialTtl);
212-
} catch (WriteException $e) {
212+
} catch (BulkWriteException $e) {
213213
if ($this->isDuplicateKeyException($e)) {
214214
throw new LockConflictedException('Lock was acquired by someone else.', 0, $e);
215215
}
@@ -235,7 +235,7 @@ public function putOffExpiration(Key $key, float $ttl)
235235

236236
try {
237237
$this->upsert($key, $ttl);
238-
} catch (WriteException $e) {
238+
} catch (BulkWriteException $e) {
239239
if ($this->isDuplicateKeyException($e)) {
240240
throw new LockConflictedException('Failed to put off the expiration of the lock.', 0, $e);
241241
}
@@ -268,7 +268,7 @@ public function exists(Key $key): bool
268268
'$gt' => $this->createMongoDateTime(microtime(true)),
269269
],
270270
], [
271-
'readPreference' => new ReadPreference(\defined(ReadPreference::PRIMARY) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY),
271+
'readPreference' => new ReadPreference(\defined(ReadPreference::class.'::PRIMARY') ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY),
272272
]);
273273
}
274274

@@ -309,7 +309,7 @@ private function upsert(Key $key, float $ttl)
309309
);
310310
}
311311

312-
private function isDuplicateKeyException(WriteException $e): bool
312+
private function isDuplicateKeyException(BulkWriteException $e): bool
313313
{
314314
$code = $e->getCode();
315315

@@ -345,7 +345,7 @@ private function getCollection(): Collection
345345
*/
346346
private function createMongoDateTime(float $seconds): UTCDateTime
347347
{
348-
return new UTCDateTime($seconds * 1000);
348+
return new UTCDateTime((int) ($seconds * 1000));
349349
}
350350

351351
/**

0 commit comments

Comments
 (0)