Skip to content

Commit 9f36faf

Browse files
committed
PHPLIB-363: Remove support for server versions < 3.0
Since ext-mongodb 1.5.0 drops support for server 2.6, we can remove wire version checks and legacy code for servers before 3.0 (i.e. wire version 3).
1 parent aecfe92 commit 9f36faf

File tree

7 files changed

+2
-198
lines changed

7 files changed

+2
-198
lines changed

docs/includes/apiargs-MongoDBDatabase-method-listCollections-option.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ description: |
66
77
You can specify a query expression for collection fields (e.g. ``name``,
88
``options``).
9-
10-
For server versions < 3.0, the filter can only be used to match the ``name``
11-
field with a string value. More complex filters will result in an exception at
12-
execution time if used.
139
interface: phpmethod
1410
operation: ~
1511
optional: true

src/Model/CollectionInfoLegacyIterator.php

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/Operation/Explain.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class Explain implements Executable
3838
const VERBOSITY_EXEC_STATS = 'executionStats';
3939
const VERBOSITY_QUERY = 'queryPlanner';
4040

41-
private static $wireVersionForExplain = 2;
4241
private static $wireVersionForDistinct = 4;
4342
private static $wireVersionForFindAndModify = 4;
4443

@@ -90,10 +89,6 @@ public function __construct($databaseName, Explainable $explainable, array $opti
9089

9190
public function execute(Server $server)
9291
{
93-
if (! \MongoDB\server_supports_feature($server, self::$wireVersionForExplain)) {
94-
throw UnsupportedException::explainNotSupported();
95-
}
96-
9792
if ($this->explainable instanceof Distinct && ! \MongoDB\server_supports_feature($server, self::$wireVersionForDistinct)) {
9893
throw UnsupportedException::explainNotSupported();
9994
}

src/Operation/ListCollections.php

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
*/
3838
class ListCollections implements Executable
3939
{
40-
private static $wireVersionForCommand = 3;
41-
4240
private $databaseName;
4341
private $options;
4442

@@ -49,10 +47,6 @@ class ListCollections implements Executable
4947
*
5048
* * filter (document): Query by which to filter collections.
5149
*
52-
* For server versions < 3.0, the filter can only be used to match the
53-
* "name" field with a string value. More complex filters will result in
54-
* an exception at execution time if used.
55-
*
5650
* * maxTimeMS (integer): The maximum amount of time to allow the query to
5751
* run.
5852
*
@@ -88,14 +82,11 @@ public function __construct($databaseName, array $options = [])
8882
* @see Executable::execute()
8983
* @param Server $server
9084
* @return CollectionInfoIterator
91-
* @throws InvalidArgumentException if filter.name is not a string for legacy execution
9285
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
9386
*/
9487
public function execute(Server $server)
9588
{
96-
return \MongoDB\server_supports_feature($server, self::$wireVersionForCommand)
97-
? $this->executeCommand($server)
98-
: $this->executeLegacy($server);
89+
return $this->executeCommand($server);
9990
}
10091

10192
/**
@@ -143,35 +134,4 @@ private function executeCommand(Server $server)
143134

144135
return new CollectionInfoCommandIterator(new CachingIterator($cursor));
145136
}
146-
147-
/**
148-
* Returns information for all collections in this database by querying the
149-
* "system.namespaces" collection (MongoDB <3.0).
150-
*
151-
* @param Server $server
152-
* @return CollectionInfoLegacyIterator
153-
* @throws InvalidArgumentException if filter.name is not a string
154-
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
155-
*/
156-
private function executeLegacy(Server $server)
157-
{
158-
$filter = empty($this->options['filter']) ? [] : (array) $this->options['filter'];
159-
160-
if (array_key_exists('name', $filter)) {
161-
if ( ! is_string($filter['name'])) {
162-
throw InvalidArgumentException::invalidType('filter name for MongoDB <3.0', $filter['name'], 'string');
163-
}
164-
165-
$filter['name'] = $this->databaseName . '.' . $filter['name'];
166-
}
167-
168-
$options = isset($this->options['maxTimeMS'])
169-
? ['modifiers' => ['$maxTimeMS' => $this->options['maxTimeMS']]]
170-
: [];
171-
172-
$cursor = $server->executeQuery($this->databaseName . '.system.namespaces', new Query($filter, $options));
173-
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
174-
175-
return new CollectionInfoLegacyIterator(new CachingIterator($cursor));
176-
}
177137
}

src/Operation/ListIndexes.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class ListIndexes implements Executable
3939
{
4040
private static $errorCodeDatabaseNotFound = 60;
4141
private static $errorCodeNamespaceNotFound = 26;
42-
private static $wireVersionForCommand = 3;
4342

4443
private $databaseName;
4544
private $collectionName;
@@ -87,9 +86,7 @@ public function __construct($databaseName, $collectionName, array $options = [])
8786
*/
8887
public function execute(Server $server)
8988
{
90-
return \MongoDB\server_supports_feature($server, self::$wireVersionForCommand)
91-
? $this->executeCommand($server)
92-
: $this->executeLegacy($server);
89+
return $this->executeCommand($server);
9390
}
9491

9592
/**
@@ -146,26 +143,4 @@ private function executeCommand(Server $server)
146143

147144
return new IndexInfoIteratorIterator(new CachingIterator($cursor));
148145
}
149-
150-
/**
151-
* Returns information for all indexes for this collection by querying the
152-
* "system.indexes" collection (MongoDB <3.0).
153-
*
154-
* @param Server $server
155-
* @return IndexInfoIteratorIterator
156-
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
157-
*/
158-
private function executeLegacy(Server $server)
159-
{
160-
$filter = ['ns' => $this->databaseName . '.' . $this->collectionName];
161-
162-
$options = isset($this->options['maxTimeMS'])
163-
? ['modifiers' => ['$maxTimeMS' => $this->options['maxTimeMS']]]
164-
: [];
165-
166-
$cursor = $server->executeQuery($this->databaseName . '.system.indexes', new Query($filter, $options));
167-
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
168-
169-
return new IndexInfoIteratorIterator(new CachingIterator($cursor));
170-
}
171146
}

tests/Collection/CollectionFunctionalTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ public function testDropIndexShouldNotAllowWildcardCharacter()
155155

156156
public function testExplain()
157157
{
158-
if (version_compare($this->getServerVersion(), '3.0.0', '<')) {
159-
$this->markTestSkipped('Explain command is not supported');
160-
}
161-
162158
$this->createFixtures(3);
163159

164160
$operation = new Count($this->getDatabaseName(), $this->getCollectionName(), ['x' => ['$gte' => 1]], []);

tests/Operation/ExplainFunctionalTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525

2626
class ExplainFunctionalTest extends FunctionalTestCase
2727
{
28-
public function setUp()
29-
{
30-
parent::setUp();
31-
if (version_compare($this->getServerVersion(), '3.0.0', '<')) {
32-
$this->markTestSkipped('Explain command is not supported');
33-
}
34-
}
35-
3628
/**
3729
* @dataProvider provideVerbosityInformation
3830
*/

0 commit comments

Comments
 (0)