Skip to content

PHPLIB-749: Support comment option on command helpers #925

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 17 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source:
ref: bypassDocumentValidation
---
source:
file: apiargs-aggregate-option.yaml
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: bypassDocumentValidation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: let
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
arg_name: option
name: hint
type: string|array|object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
arg_name: option
name: hint
type: string|array|object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: maxTimeMS
Expand Down
14 changes: 5 additions & 9 deletions docs/includes/apiargs-MongoDBCollection-method-find-option.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,11 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
arg_name: option
name: comment
type: string
description: |
A comment to attach to the query to help interpret and trace query
:dbcommand:`profile` data.
interface: phpmethod
operation: ~
optional: true
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
arg_name: option
name: cursorType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ source:
ref: collation
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: bypassDocumentValidation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-MongoDBCollection-method-bulkWrite-option.yaml
ref: ordered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: bypassDocumentValidation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-common-option.yaml
ref: hint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ source:
file: apiargs-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-method-watch-option.yaml
ref: fullDocument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source:
ref: bypassDocumentValidation
---
source:
file: apiargs-aggregate-option.yaml
file: apiargs-common-option.yaml
ref: comment
---
source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ source:
file: apiargs-common-option.yaml
ref: collation
---
source:
file: apiargs-common-option.yaml
ref: comment
post: |
.. versionadded:: 1.13
---
source:
file: apiargs-method-watch-option.yaml
ref: fullDocument
Expand Down
10 changes: 0 additions & 10 deletions docs/includes/apiargs-aggregate-option.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ post: |
:ref:`$out <agg-merge>` stages.
---
arg_name: option
name: comment
type: string
description: |
Users can specify an arbitrary string to help trace the operation through the
database profiler, currentOp, and logs.
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: explain
type: boolean
description: |
Expand Down
16 changes: 16 additions & 0 deletions docs/includes/apiargs-common-option.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ operation: ~
optional: true
---
arg_name: option
name: comment
type: mixed
description: |
Enables users to specify an arbitrary comment to help trace the operation through
the database profiler, currentOp and logs. The default is to not send a value.

The comment can be any valid BSON type for server versions 4.4 and above.
Server versions between 3.6 and 4.2 only support string as comment,
and providing a non-string type will result in a server-side error.
Older server versions do not support comment for aggregate command at all,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that apiargs-common-option.yaml is a common include shared by various methods, but this is specific to the aggregate command.

and providing one will result in a server-side error.
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: hint
type: string|array|object
description: |
Expand Down
15 changes: 9 additions & 6 deletions src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ class Aggregate implements Executable, Explainable
*
* * collation (document): Collation specification.
*
* * comment (string): An arbitrary string to help trace the operation
* through the database profiler, currentOp, and logs.
* * comment (mixed): Enables users to specify an arbitrary comment to help trace
* the operation through the database profiler, currentOp and logs. The
* default is to not send a value.
*
* The comment can be any valid BSON type for server versions 4.4 and above.
* Server versions between 3.6 and 4.2 only support string as comment,
* and providing a non-string type will result in a server-side error.
* Older server versions do not support comment for aggregate command at all,
* and providing one will result in a server-side error.
*
* * explain (boolean): Specifies whether or not to return the information
* on the processing of the pipeline.
Expand Down Expand Up @@ -170,10 +177,6 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
}

if (isset($options['comment']) && ! is_string($options['comment'])) {
throw InvalidArgumentException::invalidType('"comment" option', $options['comment'], 'string');
}

if (isset($options['explain']) && ! is_bool($options['explain'])) {
throw InvalidArgumentException::invalidType('"explain" option', $options['explain'], 'boolean');
}
Expand Down
16 changes: 14 additions & 2 deletions src/Operation/BulkWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ class BulkWrite implements Executable
* * bypassDocumentValidation (boolean): If true, allows the write to
* circumvent document level validation. The default is false.
*
* * comment (mixed): Enables users to specify an arbitrary comment to help trace
* the operation through the database profiler, currentOp and logs. The
* default is to not send a value.
*
* The comment can be any valid BSON type for server versions 4.4 and above.
* Server versions between 3.6 and 4.2 only support string as comment,
* and providing a non-string type will result in a server-side error.
* Older server versions do not support comment for aggregate command at all,
* and providing one will result in a server-side error.
*
* * ordered (boolean): If true, when an insert fails, return without
* performing the remaining writes. If false, when a write fails,
* continue with the remaining writes, if any. The default is true.
Expand Down Expand Up @@ -353,8 +363,10 @@ private function createBulkWriteOptions()
{
$options = ['ordered' => $this->options['ordered']];

if (isset($this->options['bypassDocumentValidation'])) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
foreach (['bypassDocumentValidation', 'comment'] as $option) {
if (isset($this->options[$option])) {
$options[$option] = $this->options[$option];
}
}

if (isset($this->options['let'])) {
Expand Down
12 changes: 11 additions & 1 deletion src/Operation/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ class Count implements Executable, Explainable
*
* * collation (document): Collation specification.
*
* * comment (mixed): Enables users to specify an arbitrary comment to help trace
* the operation through the database profiler, currentOp and logs. The
* default is to not send a value.
*
* The comment can be any valid BSON type for server versions 4.4 and above.
* Server versions between 3.6 and 4.2 only support string as comment,
* and providing a non-string type will result in a server-side error.
* Older server versions do not support comment for aggregate command at all,
* and providing one will result in a server-side error.
*
* * hint (string|document): The index to use. Specify either the index
* name as a string or the index key pattern as a document. If specified,
* then the query system will only consider plans using the hinted index.
Expand Down Expand Up @@ -195,7 +205,7 @@ private function createCommandDocument()
$cmd['hint'] = is_array($this->options['hint']) ? (object) $this->options['hint'] : $this->options['hint'];
}

foreach (['limit', 'maxTimeMS', 'skip'] as $option) {
foreach (['comment', 'limit', 'maxTimeMS', 'skip'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
Expand Down
Loading