@@ -175,7 +175,8 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
175
175
$ resetTimestamp = min (max (0 , $ resetTimestamp * 1000 ), self ::MONGO_INT32_MAX );
176
176
177
177
$ update = ['$set ' => ['earliestGet ' => new UTCDateTime ($ resetTimestamp )]];
178
- $ options = ['sort ' => ['priority ' => 1 , 'created ' => 1 ]];
178
+ $ findOneAndUpdateOptions = ['sort ' => ['priority ' => 1 , 'created ' => 1 ]];
179
+ $ findOneOptions = ['typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' , 'array ' => 'array ' ]];
179
180
180
181
//ints overflow to floats, should be fine
181
182
$ end = microtime (true ) + ($ waitDurationInMillis / 1000.0 );
@@ -189,14 +190,14 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
189
190
} //@codeCoverageIgnoreEnd
190
191
191
192
while (true ) {
192
- $ message = $ this ->collection -> findOneAndUpdate ( $ completeQuery , $ update , $ options );
193
- //checking if _id exist because findAndModify doesnt seem to return null when it can't match the query on
194
- //older mongo extension
195
- if ($ message !== null && array_key_exists ( ' _id ' , $ message ) ) {
193
+ $ id = $ this ->getIdFromMessage (
194
+ $ this -> collection -> findOneAndUpdate ( $ completeQuery , $ update , $ findOneAndUpdateOptions )
195
+ );
196
+ if ($ id !== null ) {
196
197
// findOneAndUpdate does not correctly return result according to typeMap options so just refetch.
197
- $ message = $ this ->collection ->findOne (['_id ' => $ message -> _id ] );
198
+ $ message = $ this ->collection ->findOne (['_id ' => $ id ], $ findOneOptions );
198
199
//id on left of union operator so a possible id in payload doesnt wipe it out the generated one
199
- return ['id ' => $ message [ ' _id ' ]] + ( array ) $ message ['payload ' ];
200
+ return ['id ' => $ id ] + $ message ['payload ' ];
200
201
}
201
202
202
203
if (microtime (true ) >= $ end ) {
@@ -211,6 +212,19 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
211
212
}
212
213
//@codeCoverageIgnoreEnd
213
214
215
+ private function getIdFromMessage ($ message )
216
+ {
217
+ if (is_array ($ message )) {
218
+ return array_key_exists ('_id ' , $ message ) ? $ message ['_id ' ] : null ;
219
+ }
220
+
221
+ if (is_object ($ message )) {
222
+ return isset ($ message ->_id ) ? $ message ->_id : null ;
223
+ }
224
+
225
+ return null ;
226
+ }
227
+
214
228
/**
215
229
* Count queue messages.
216
230
*
0 commit comments