Skip to content

Commit 1cd7d57

Browse files
committed
Remove version checks for pre-3.6 servers
Preserve behavior for only sending bypassDocumentValidation if true. This also removes a reference to an undeclared var in ModifyCollection (PHPLIB-796). f bypass
1 parent f3281af commit 1cd7d57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+149
-715
lines changed

src/Client.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ class Client
5151
'root' => BSONDocument::class,
5252
];
5353

54-
/** @var integer */
55-
private static $wireVersionForReadConcern = 4;
56-
57-
/** @var integer */
58-
private static $wireVersionForWritableCommandWriteConcern = 5;
59-
6054
/** @var string */
6155
private static $handshakeSeparator = ' / ';
6256

@@ -215,7 +209,7 @@ public function dropDatabase($databaseName, array $options = [])
215209

216210
$server = select_server($this->manager, $options);
217211

218-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
212+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
219213
$options['writeConcern'] = $this->writeConcern;
220214
}
221215

@@ -372,7 +366,7 @@ public function watch(array $pipeline = [], array $options = [])
372366

373367
$server = select_server($this->manager, $options);
374368

375-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
369+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
376370
$options['readConcern'] = $this->readConcern;
377371
}
378372

src/Collection.php

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ class Collection
7575
'root' => BSONDocument::class,
7676
];
7777

78-
/** @var integer */
79-
private static $wireVersionForFindAndModifyWriteConcern = 4;
80-
81-
/** @var integer */
82-
private static $wireVersionForReadConcern = 4;
83-
84-
/** @var integer */
85-
private static $wireVersionForWritableCommandWriteConcern = 5;
86-
8778
/** @var integer */
8879
private static $wireVersionForReadConcernWithWriteStage = 8;
8980

@@ -236,7 +227,6 @@ public function aggregate(array $pipeline, array $options = [])
236227
*/
237228
if (
238229
! isset($options['readConcern']) &&
239-
server_supports_feature($server, self::$wireVersionForReadConcern) &&
240230
! is_in_transaction($options) &&
241231
( ! $hasWriteStage || server_supports_feature($server, self::$wireVersionForReadConcernWithWriteStage))
242232
) {
@@ -247,12 +237,7 @@ public function aggregate(array $pipeline, array $options = [])
247237
$options['typeMap'] = $this->typeMap;
248238
}
249239

250-
if (
251-
$hasWriteStage &&
252-
! isset($options['writeConcern']) &&
253-
server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) &&
254-
! is_in_transaction($options)
255-
) {
240+
if ($hasWriteStage && ! isset($options['writeConcern']) && ! is_in_transaction($options)) {
256241
$options['writeConcern'] = $this->writeConcern;
257242
}
258243

@@ -306,7 +291,7 @@ public function count($filter = [], array $options = [])
306291

307292
$server = select_server($this->manager, $options);
308293

309-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
294+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
310295
$options['readConcern'] = $this->readConcern;
311296
}
312297

@@ -335,7 +320,7 @@ public function countDocuments($filter = [], array $options = [])
335320

336321
$server = select_server($this->manager, $options);
337322

338-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
323+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
339324
$options['readConcern'] = $this->readConcern;
340325
}
341326

@@ -397,7 +382,7 @@ public function createIndexes(array $indexes, array $options = [])
397382
{
398383
$server = select_server($this->manager, $options);
399384

400-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
385+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
401386
$options['writeConcern'] = $this->writeConcern;
402387
}
403388

@@ -479,7 +464,7 @@ public function distinct($fieldName, $filter = [], array $options = [])
479464

480465
$server = select_server($this->manager, $options);
481466

482-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
467+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
483468
$options['readConcern'] = $this->readConcern;
484469
}
485470

@@ -506,7 +491,7 @@ public function drop(array $options = [])
506491

507492
$server = select_server($this->manager, $options);
508493

509-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
494+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
510495
$options['writeConcern'] = $this->writeConcern;
511496
}
512497

@@ -540,7 +525,7 @@ public function dropIndex($indexName, array $options = [])
540525

541526
$server = select_server($this->manager, $options);
542527

543-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
528+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
544529
$options['writeConcern'] = $this->writeConcern;
545530
}
546531

@@ -567,7 +552,7 @@ public function dropIndexes(array $options = [])
567552

568553
$server = select_server($this->manager, $options);
569554

570-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
555+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
571556
$options['writeConcern'] = $this->writeConcern;
572557
}
573558

@@ -595,7 +580,7 @@ public function estimatedDocumentCount(array $options = [])
595580

596581
$server = select_server($this->manager, $options);
597582

598-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
583+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
599584
$options['readConcern'] = $this->readConcern;
600585
}
601586

@@ -653,7 +638,7 @@ public function find($filter = [], array $options = [])
653638

654639
$server = select_server($this->manager, $options);
655640

656-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
641+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
657642
$options['readConcern'] = $this->readConcern;
658643
}
659644

@@ -686,7 +671,7 @@ public function findOne($filter = [], array $options = [])
686671

687672
$server = select_server($this->manager, $options);
688673

689-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
674+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
690675
$options['readConcern'] = $this->readConcern;
691676
}
692677

@@ -718,7 +703,7 @@ public function findOneAndDelete($filter, array $options = [])
718703
{
719704
$server = select_server($this->manager, $options);
720705

721-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForFindAndModifyWriteConcern) && ! is_in_transaction($options)) {
706+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
722707
$options['writeConcern'] = $this->writeConcern;
723708
}
724709

@@ -755,7 +740,7 @@ public function findOneAndReplace($filter, $replacement, array $options = [])
755740
{
756741
$server = select_server($this->manager, $options);
757742

758-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForFindAndModifyWriteConcern) && ! is_in_transaction($options)) {
743+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
759744
$options['writeConcern'] = $this->writeConcern;
760745
}
761746

@@ -792,7 +777,7 @@ public function findOneAndUpdate($filter, $update, array $options = [])
792777
{
793778
$server = select_server($this->manager, $options);
794779

795-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForFindAndModifyWriteConcern) && ! is_in_transaction($options)) {
780+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
796781
$options['writeConcern'] = $this->writeConcern;
797782
}
798783

@@ -986,15 +971,15 @@ public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce,
986971
*
987972
* A read concern is also not compatible with transactions.
988973
*/
989-
if (! isset($options['readConcern']) && ! ($hasOutputCollection && $this->readConcern->getLevel() === ReadConcern::MAJORITY) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
974+
if (! isset($options['readConcern']) && ! ($hasOutputCollection && $this->readConcern->getLevel() === ReadConcern::MAJORITY) && ! is_in_transaction($options)) {
990975
$options['readConcern'] = $this->readConcern;
991976
}
992977

993978
if (! isset($options['typeMap'])) {
994979
$options['typeMap'] = $this->typeMap;
995980
}
996981

997-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
982+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
998983
$options['writeConcern'] = $this->writeConcern;
999984
}
1000985

@@ -1027,7 +1012,7 @@ public function rename(string $toCollectionName, ?string $toDatabaseName = null,
10271012

10281013
$server = select_server($this->manager, $options);
10291014

1030-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
1015+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
10311016
$options['writeConcern'] = $this->writeConcern;
10321017
}
10331018

@@ -1135,7 +1120,7 @@ public function watch(array $pipeline = [], array $options = [])
11351120
* related to change streams being unsupported instead of an
11361121
* UnsupportedException regarding use of the "readConcern" option from
11371122
* the Aggregate operation class. */
1138-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
1123+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
11391124
$options['readConcern'] = $this->readConcern;
11401125
}
11411126

src/Command/ListCollections.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class ListCollections implements Executable
6565
*
6666
* * session (MongoDB\Driver\Session): Client session.
6767
*
68-
* Sessions are not supported for server versions < 3.6.
69-
*
7068
* @param string $databaseName Database name
7169
* @param array $options Command options
7270
* @throws InvalidArgumentException for parameter/option parsing errors

src/Command/ListDatabases.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class ListDatabases implements Executable
5454
*
5555
* * filter (document): Query by which to filter databases.
5656
*
57-
* For servers < 3.6, this option is ignored.
58-
*
5957
* * maxTimeMS (integer): The maximum amount of time to allow the query to
6058
* run.
6159
*
@@ -65,8 +63,6 @@ class ListDatabases implements Executable
6563
*
6664
* * session (MongoDB\Driver\Session): Client session.
6765
*
68-
* Sessions are not supported for server versions < 3.6.
69-
*
7066
* @param array $options Command options
7167
* @throws InvalidArgumentException for parameter/option parsing errors
7268
*/

src/Database.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ class Database
5555
'root' => BSONDocument::class,
5656
];
5757

58-
/** @var integer */
59-
private static $wireVersionForReadConcern = 4;
60-
61-
/** @var integer */
62-
private static $wireVersionForWritableCommandWriteConcern = 5;
63-
6458
/** @var integer */
6559
private static $wireVersionForReadConcernWithWriteStage = 8;
6660

@@ -217,7 +211,6 @@ public function aggregate(array $pipeline, array $options = [])
217211
*/
218212
if (
219213
! isset($options['readConcern']) &&
220-
server_supports_feature($server, self::$wireVersionForReadConcern) &&
221214
! is_in_transaction($options) &&
222215
( ! $hasWriteStage || server_supports_feature($server, self::$wireVersionForReadConcernWithWriteStage))
223216
) {
@@ -228,12 +221,7 @@ public function aggregate(array $pipeline, array $options = [])
228221
$options['typeMap'] = $this->typeMap;
229222
}
230223

231-
if (
232-
$hasWriteStage &&
233-
! isset($options['writeConcern']) &&
234-
server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) &&
235-
! is_in_transaction($options)
236-
) {
224+
if ($hasWriteStage && ! isset($options['writeConcern']) && ! is_in_transaction($options)) {
237225
$options['writeConcern'] = $this->writeConcern;
238226
}
239227

@@ -283,7 +271,7 @@ public function createCollection($collectionName, array $options = [])
283271

284272
$server = select_server($this->manager, $options);
285273

286-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
274+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
287275
$options['writeConcern'] = $this->writeConcern;
288276
}
289277

@@ -310,7 +298,7 @@ public function drop(array $options = [])
310298

311299
$server = select_server($this->manager, $options);
312300

313-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
301+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
314302
$options['writeConcern'] = $this->writeConcern;
315303
}
316304

@@ -338,7 +326,7 @@ public function dropCollection($collectionName, array $options = [])
338326

339327
$server = select_server($this->manager, $options);
340328

341-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
329+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
342330
$options['writeConcern'] = $this->writeConcern;
343331
}
344332

@@ -460,7 +448,7 @@ public function modifyCollection($collectionName, array $collectionOptions, arra
460448

461449
$server = select_server($this->manager, $options);
462450

463-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
451+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
464452
$options['writeConcern'] = $this->writeConcern;
465453
}
466454

@@ -494,7 +482,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
494482

495483
$server = select_server($this->manager, $options);
496484

497-
if (! isset($options['writeConcern']) && server_supports_feature($server, self::$wireVersionForWritableCommandWriteConcern) && ! is_in_transaction($options)) {
485+
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
498486
$options['writeConcern'] = $this->writeConcern;
499487
}
500488

@@ -561,7 +549,7 @@ public function watch(array $pipeline = [], array $options = [])
561549

562550
$server = select_server($this->manager, $options);
563551

564-
if (! isset($options['readConcern']) && server_supports_feature($server, self::$wireVersionForReadConcern) && ! is_in_transaction($options)) {
552+
if (! isset($options['readConcern']) && ! is_in_transaction($options)) {
565553
$options['readConcern'] = $this->readConcern;
566554
}
567555

src/Exception/UnsupportedException.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public static function allowDiskUseNotSupported()
3232
/**
3333
* Thrown when array filters are not supported by a server.
3434
*
35+
* @deprecated 1.12
36+
* @todo Remove this in 2.0 (see: PHPLIB-797)
37+
*
3538
* @return self
3639
*/
3740
public static function arrayFiltersNotSupported()
@@ -42,6 +45,9 @@ public static function arrayFiltersNotSupported()
4245
/**
4346
* Thrown when collations are not supported by a server.
4447
*
48+
* @deprecated 1.12
49+
* @todo Remove this in 2.0 (see: PHPLIB-797)
50+
*
4551
* @return self
4652
*/
4753
public static function collationNotSupported()

0 commit comments

Comments
 (0)