Skip to content

PHPLIB-1680: Remove obsolete wire version checks for MongoDB 4.2 #1695

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

Draft
wants to merge 1 commit into
base: v2.x
Choose a base branch
from
Draft
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
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,6 @@
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/Update.php">
<MixedArgument>
<code><![CDATA[$this->options['writeConcern']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$cmd['bypassDocumentValidation']]]></code>
<code><![CDATA[$options[$option]]]></code>
Expand Down
19 changes: 5 additions & 14 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class Collection
'root' => BSONDocument::class,
];

private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;

/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
private readonly Encoder $builderEncoder;

Expand Down Expand Up @@ -227,24 +225,17 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
$hasWriteStage = is_last_pipeline_operator_write($pipeline);

$options = $this->inheritReadPreference($options);

$server = $hasWriteStage
? select_server_for_aggregate_write_stage($this->manager, $options)
: select_server($this->manager, $options);

/* MongoDB 4.2 and later supports a read concern when an $out stage is
* being used, but earlier versions do not.
*/
if (! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE)) {
$options = $this->inheritReadConcern($options);
}

$options = $this->inheritReadConcern($options);
$options = $this->inheritCodecOrTypeMap($options);

if ($hasWriteStage) {
$options = $this->inheritWriteOptions($options);
}

$server = $hasWriteStage
? select_server_for_aggregate_write_stage($this->manager, $options)
: select_server($this->manager, $options);

$operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options);

return $operation->execute($server);
Expand Down
5 changes: 1 addition & 4 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class Database
'root' => BSONDocument::class,
];

private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;

/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
private readonly Encoder $builderEncoder;

Expand Down Expand Up @@ -220,8 +218,7 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
*/
if (
! isset($options['readConcern']) &&
! is_in_transaction($options) &&
( ! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE))
! is_in_transaction($options)
) {
$options['readConcern'] = $this->readConcern;
}
Expand Down
8 changes: 0 additions & 8 deletions src/Operation/FindAndModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ final class FindAndModify implements Explainable
{
private const WIRE_VERSION_FOR_HINT = 9;

private const WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR = 8;

private array $options;

/**
Expand Down Expand Up @@ -227,12 +225,6 @@ public function __construct(private string $databaseName, private string $collec
*/
public function execute(Server $server): array|object|null
{
/* Server versions >= 4.2.0 raise errors for unsupported update options.
* For previous versions, the CRUD spec requires a client-side error. */
if (isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR)) {
throw UnsupportedException::hintNotSupported();
}

/* CRUD spec requires a client-side error when using "hint" with an
* unacknowledged write concern on an unsupported server. */
if (
Expand Down
13 changes: 0 additions & 13 deletions src/Operation/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
use function MongoDB\is_document;
use function MongoDB\is_first_key_operator;
use function MongoDB\is_pipeline;
use function MongoDB\is_write_concern_acknowledged;
use function MongoDB\server_supports_feature;

/**
* Operation for the update command.
Expand All @@ -46,8 +44,6 @@
*/
final class Update implements Explainable
{
private const WIRE_VERSION_FOR_HINT = 8;

private array $options;

/**
Expand Down Expand Up @@ -176,15 +172,6 @@ public function __construct(private string $databaseName, private string $collec
*/
public function execute(Server $server): UpdateResult
{
/* CRUD spec requires a client-side error when using "hint" with an
* unacknowledged write concern on an unsupported server. */
if (
isset($this->options['writeConcern']) && ! is_write_concern_acknowledged($this->options['writeConcern']) &&
isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_HINT)
) {
throw UnsupportedException::hintNotSupported();
}

$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
if ($inTransaction && isset($this->options['writeConcern'])) {
throw UnsupportedException::writeConcernNotSupportedInTransaction();
Expand Down