Skip to content

Remove deprecated functionality #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ UPGRADE FROM 1.x to 2.0

* Classes in the namespace `MongoDB\Operation\` are `final`.
* All methods in interfaces and classes now define a return type.
* The `MongoDB\ChangeStream::CURSOR_NOT_FOUND` constant is now private.
* The `MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT` constant has been
removed.
* The `getNamespace` and `isGeoHaystack` methods have been removed from the
`MongoDB\Model\IndexInfo` class.
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
and `findOne` operations have been removed.
* The `MongoDB\Collection::mapReduce` method has been removed. Use
[aggregation pipeline](https://www.mongodb.com/docs/manual/reference/map-reduce-to-aggregation-pipeline/)
instead.
* The following classes and interfaces have been removed without replacement:
* `MongoDB\MapReduceResult`
* `MongoDB\Model\CollectionInfoCommandIterator`
* `MongoDB\Model\CollectionInfoIterator`
* `MongoDB\Model\DatabaseInfoIterator`
* `MongoDB\Model\DatabaseInfoLegacyIterator`
* `MongoDB\Model\IndexInfoIterator`
* `MongoDB\Model\IndexInfoIteratorIterator`
* `MongoDB\Operation\Executable`

GridFS
------
Expand Down
117 changes: 0 additions & 117 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,14 @@
count($queriesOrArrayOfQueries[0]) > 0]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/ChangeStream.php">
<DeprecatedConstant>
<code><![CDATA[self::CURSOR_NOT_FOUND]]></code>
</DeprecatedConstant>
</file>
<file src="src/Client.php">
<DeprecatedInterface>
<code><![CDATA[DatabaseInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedArgument>
<code><![CDATA[$driverOptions['driver'] ?? []]]></code>
<code><![CDATA[$pipeline]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$mergedDriver['platform']]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$driverOptions['builderEncoder'] ?? new BuilderEncoder()]]></code>
</MixedPropertyTypeCoercion>
Expand Down Expand Up @@ -232,19 +218,10 @@
</MixedArgumentTypeCoercion>
</file>
<file src="src/Collection.php">
<DeprecatedInterface>
<code><![CDATA[IndexInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedArgument>
<code><![CDATA[$pipeline]]></code>
<code><![CDATA[$pipeline]]></code>
</MixedArgument>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
</MixedPropertyTypeCoercion>
Expand All @@ -271,19 +248,10 @@
</MixedAssignment>
</file>
<file src="src/Database.php">
<DeprecatedInterface>
<code><![CDATA[CollectionInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedArgument>
<code><![CDATA[$pipeline]]></code>
<code><![CDATA[$pipeline]]></code>
</MixedArgument>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
</MixedPropertyTypeCoercion>
Expand Down Expand Up @@ -388,34 +356,6 @@
<code><![CDATA[$this->current()]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Model/CollectionInfoCommandIterator.php">
<DeprecatedInterface>
<code><![CDATA[CollectionInfoCommandIterator]]></code>
</DeprecatedInterface>
<MixedArrayAssignment>
<code><![CDATA[$info['idIndex']['ns']]]></code>
</MixedArrayAssignment>
<MixedOperand>
<code><![CDATA[$info['name']]]></code>
</MixedOperand>
</file>
<file src="src/Model/DatabaseInfoLegacyIterator.php">
<DeprecatedInterface>
<code><![CDATA[DatabaseInfoLegacyIterator]]></code>
</DeprecatedInterface>
<MixedArgument>
<code><![CDATA[current($this->databases)]]></code>
</MixedArgument>
<MixedReturnTypeCoercion>
<code><![CDATA[int]]></code>
<code><![CDATA[key($this->databases)]]></code>
</MixedReturnTypeCoercion>
</file>
<file src="src/Model/IndexInfoIteratorIterator.php">
<DeprecatedInterface>
<code><![CDATA[IndexInfoIteratorIterator]]></code>
</DeprecatedInterface>
</file>
<file src="src/Model/IndexInput.php">
<LessSpecificReturnStatement>
<code><![CDATA[(object) $this->index]]></code>
Expand Down Expand Up @@ -713,11 +653,7 @@
<code><![CDATA[$this->options['codec']]]></code>
<code><![CDATA[$this->options['typeMap']]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$options['modifiers'][$modifier[1]]]]></code>
</MixedArrayAccess>
<MixedAssignment>
<code><![CDATA[$options[$modifier[0]]]]></code>
<code><![CDATA[$options[$option]]]></code>
<code><![CDATA[$options['readPreference']]]></code>
<code><![CDATA[$options['session']]]></code>
Expand Down Expand Up @@ -802,64 +738,11 @@
<code><![CDATA[$document]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/ListCollections.php">
<DeprecatedInterface>
<code><![CDATA[CollectionInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MixedInferredReturnType>
</file>
<file src="src/Operation/ListDatabases.php">
<DeprecatedInterface>
<code><![CDATA[DatabaseInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MixedInferredReturnType>
</file>
<file src="src/Operation/ListIndexes.php">
<DeprecatedClass>
<code><![CDATA[IndexInfoIteratorIterator]]></code>
<code><![CDATA[new IndexInfoIteratorIterator($iterator, $this->databaseName . '.' . $this->collectionName)]]></code>
<code><![CDATA[new IndexInfoIteratorIterator(new EmptyIterator())]]></code>
</DeprecatedClass>
<DeprecatedInterface>
<code><![CDATA[IndexInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedAssignment>
<code><![CDATA[$cmd[$option]]]></code>
<code><![CDATA[$options['session']]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MixedInferredReturnType>
</file>
<file src="src/Operation/MapReduce.php">
<MixedArgument>
<code><![CDATA[$result->result->collection]]></code>
<code><![CDATA[$result->result->db]]></code>
<code><![CDATA[$this->options['typeMap']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$cmd[$option]]]></code>
<code><![CDATA[$options['readConcern']]]></code>
<code><![CDATA[$options['readPreference']]]></code>
<code><![CDATA[$options['session']]]></code>
<code><![CDATA[$options['writeConcern']]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[isInTransaction]]></code>
</MixedMethodCall>
</file>
<file src="src/Operation/ModifyCollection.php">
<MixedArgument>
Expand Down
6 changes: 1 addition & 5 deletions src/ChangeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
*/
class ChangeStream implements Iterator
{
/**
* @deprecated 1.4
* @todo make this constant private in 2.0 (see: PHPLIB-360)
*/
public const CURSOR_NOT_FOUND = 43;
private const CURSOR_NOT_FOUND = 43;

private const RESUMABLE_ERROR_CODES = [
6, // HostUnreachable
Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\DatabaseInfo;
use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabaseNames;
use MongoDB\Operation\ListDatabases;
Expand Down Expand Up @@ -284,6 +283,7 @@ public function getWriteConcern(): WriteConcern
* List database names.
*
* @see ListDatabaseNames::__construct() for supported options
* @return Iterator<int, string>
* @throws UnexpectedValueException if the command response was malformed
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
Expand All @@ -305,7 +305,7 @@ public function listDatabaseNames(array $options = []): Iterator
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function listDatabases(array $options = []): DatabaseInfoIterator
public function listDatabases(array $options = []): Iterator
{
$operation = new ListDatabases($options);
$server = select_server($this->manager, $options);
Expand Down
51 changes: 1 addition & 50 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Countable;
use Iterator;
use MongoDB\BSON\Document;
use MongoDB\BSON\JavascriptInterface;
use MongoDB\BSON\PackedArray;
use MongoDB\Builder\BuilderEncoder;
use MongoDB\Builder\Pipeline;
Expand All @@ -38,7 +37,6 @@
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\IndexInfo;
use MongoDB\Model\IndexInfoIterator;
use MongoDB\Operation\Aggregate;
use MongoDB\Operation\BulkWrite;
use MongoDB\Operation\Count;
Expand All @@ -64,7 +62,6 @@
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListIndexes;
use MongoDB\Operation\ListSearchIndexes;
use MongoDB\Operation\MapReduce;
use MongoDB\Operation\RenameCollection;
use MongoDB\Operation\ReplaceOne;
use MongoDB\Operation\UpdateMany;
Expand All @@ -78,11 +75,7 @@
use function array_key_exists;
use function current;
use function is_array;
use function sprintf;
use function strlen;
use function trigger_error;

use const E_USER_DEPRECATED;

class Collection
{
Expand Down Expand Up @@ -884,7 +877,7 @@ public function insertOne(array|object $document, array $options = []): InsertOn
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function listIndexes(array $options = []): IndexInfoIterator
public function listIndexes(array $options = []): Iterator
{
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);

Expand All @@ -909,48 +902,6 @@ public function listSearchIndexes(array $options = []): Iterator
return $operation->execute($server);
}

/**
* Executes a map-reduce aggregation on the collection.
*
* @see MapReduce::__construct() for supported options
* @see https://mongodb.com/docs/manual/reference/command/mapReduce/
* @param JavascriptInterface $map Map function
* @param JavascriptInterface $reduce Reduce function
* @param string|array|object $out Output specification
* @param array $options Command options
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
* @throws UnexpectedValueException if the command response was malformed
*/
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = []): MapReduceResult
{
@trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED);

$hasOutputCollection = ! is_mapreduce_output_inline($out);

// Check if the out option is inline because we will want to coerce a primary read preference if not
if ($hasOutputCollection) {
$options['readPreference'] = new ReadPreference(ReadPreference::PRIMARY);
} else {
$options = $this->inheritReadPreference($options);
}

/* A "majority" read concern is not compatible with inline output, so
* avoid providing the Collection's read concern if it would conflict.
*/
if (! $hasOutputCollection || $this->readConcern->getLevel() !== ReadConcern::MAJORITY) {
$options = $this->inheritReadConcern($options);
}

$options = $this->inheritWriteOptions($options);
$options = $this->inheritTypeMap($options);

$operation = new MapReduce($this->databaseName, $this->collectionName, $map, $reduce, $out, $options);

return $operation->execute(select_server_for_write($this->manager, $options));
}

/**
* Renames the collection.
*
Expand Down
15 changes: 6 additions & 9 deletions src/Command/ListCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
namespace MongoDB\Command;

use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\CursorInterface;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\CachingIterator;
use MongoDB\Operation\Executable;

use function is_bool;
use function is_integer;
Expand All @@ -36,7 +34,7 @@
* @internal
* @see https://mongodb.com/docs/manual/reference/command/listCollections/
*/
final class ListCollections implements Executable
final class ListCollections
{
/**
* Constructs a listCollections command.
Expand Down Expand Up @@ -93,17 +91,16 @@ public function __construct(private string $databaseName, private array $options
/**
* Execute the operation.
*
* @return CachingIterator<int, array>
* @see Executable::execute()
* @return CursorInterface<array>
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server): CachingIterator
public function execute(Server $server): CursorInterface
{
/** @var Cursor<array> $cursor */
/** @var CursorInterface<array> $cursor */
$cursor = $server->executeReadCommand($this->databaseName, $this->createCommand(), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);

return new CachingIterator($cursor);
return $cursor;
}

/**
Expand Down
Loading