14
14
use MongoDB \BSON \UTCDateTime ;
15
15
use MongoDB \Client ;
16
16
use MongoDB \Collection ;
17
- use MongoDB \Driver \Exception \WriteException ;
17
+ use MongoDB \Driver \Exception \BulkWriteException ;
18
18
use MongoDB \Driver \ReadPreference ;
19
19
use MongoDB \Exception \DriverRuntimeException ;
20
20
use MongoDB \Exception \InvalidArgumentException as MongoInvalidArgumentException ;
@@ -209,7 +209,7 @@ public function save(Key $key)
209
209
210
210
try {
211
211
$ this ->upsert ($ key , $ this ->initialTtl );
212
- } catch (WriteException $ e ) {
212
+ } catch (BulkWriteException $ e ) {
213
213
if ($ this ->isDuplicateKeyException ($ e )) {
214
214
throw new LockConflictedException ('Lock was acquired by someone else. ' , 0 , $ e );
215
215
}
@@ -235,7 +235,7 @@ public function putOffExpiration(Key $key, float $ttl)
235
235
236
236
try {
237
237
$ this ->upsert ($ key , $ ttl );
238
- } catch (WriteException $ e ) {
238
+ } catch (BulkWriteException $ e ) {
239
239
if ($ this ->isDuplicateKeyException ($ e )) {
240
240
throw new LockConflictedException ('Failed to put off the expiration of the lock. ' , 0 , $ e );
241
241
}
@@ -268,7 +268,7 @@ public function exists(Key $key): bool
268
268
'$gt ' => $ this ->createMongoDateTime (microtime (true )),
269
269
],
270
270
], [
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 ),
272
272
]);
273
273
}
274
274
@@ -309,7 +309,7 @@ private function upsert(Key $key, float $ttl)
309
309
);
310
310
}
311
311
312
- private function isDuplicateKeyException (WriteException $ e ): bool
312
+ private function isDuplicateKeyException (BulkWriteException $ e ): bool
313
313
{
314
314
$ code = $ e ->getCode ();
315
315
@@ -345,7 +345,7 @@ private function getCollection(): Collection
345
345
*/
346
346
private function createMongoDateTime (float $ seconds ): UTCDateTime
347
347
{
348
- return new UTCDateTime ($ seconds * 1000 );
348
+ return new UTCDateTime (( int ) ( $ seconds * 1000 ) );
349
349
}
350
350
351
351
/**
0 commit comments