Commit fcb17e8b authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-240: FindAndModify should throw for unsupported write concern

This reverts the logic in 21b7d92a, which was to ignore an unsupported write concern for the duration of 1.x. Since the Collection helper methods do not supply a default write concern option if it is not supported, this change will only affect users that were explicitly passing a write concern and relying on the library to ignore it.

While a minor BC break, this changes makes findAndModify consistent with other write commands.
parent 6faa8907
...@@ -18,6 +18,6 @@ source: ...@@ -18,6 +18,6 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern ref: writeConcern
post: | post: |
This is not supported for server versions prior to 3.2 and will be ignored if This is not supported for server versions prior to 3.2 and will result in an
used. exception at execution time if used.
... ...
...@@ -39,6 +39,6 @@ source: ...@@ -39,6 +39,6 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern ref: writeConcern
post: | post: |
This is not supported for server versions prior to 3.2 and will be ignored if This is not supported for server versions prior to 3.2 and will result in an
used. exception at execution time if used.
... ...
...@@ -39,6 +39,6 @@ source: ...@@ -39,6 +39,6 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern ref: writeConcern
post: | post: |
This is not supported for server versions prior to 3.2 and will be ignored if This is not supported for server versions prior to 3.2 and will result in an
used. exception at execution time if used.
... ...
...@@ -69,7 +69,8 @@ class FindAndModify implements Executable ...@@ -69,7 +69,8 @@ class FindAndModify implements Executable
* *
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
* *
* This is not supported for server versions < 3.2. * This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection name * @param string $collectionName Collection name
...@@ -144,7 +145,7 @@ class FindAndModify implements Executable ...@@ -144,7 +145,7 @@ class FindAndModify implements Executable
* @param Server $server * @param Server $server
* @return object|null * @return object|null
* @throws UnexpectedValueException if the command response was malformed * @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation is used and unsupported * @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors) * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function execute(Server $server) public function execute(Server $server)
...@@ -153,6 +154,10 @@ class FindAndModify implements Executable ...@@ -153,6 +154,10 @@ class FindAndModify implements Executable
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported();
}
$cursor = $server->executeCommand($this->databaseName, $this->createCommand($server)); $cursor = $server->executeCommand($this->databaseName, $this->createCommand($server));
$result = current($cursor->toArray()); $result = current($cursor->toArray());
...@@ -209,11 +214,7 @@ class FindAndModify implements Executable ...@@ -209,11 +214,7 @@ class FindAndModify implements Executable
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
/* In the future, we should throw an exception if the "writeConcern" if (isset($this->options['writeConcern'])) {
* option is specified and not supported by the server (see: SPEC-494).
* For BC in 1.x, we will silently omit it for incompatible servers.
*/
if (isset($this->options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
$cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']); $cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']);
} }
......
...@@ -37,8 +37,10 @@ class FindOneAndDelete implements Executable ...@@ -37,8 +37,10 @@ class FindOneAndDelete implements Executable
* * sort (document): Determines which document the operation modifies if * * sort (document): Determines which document the operation modifies if
* the query selects multiple documents. * the query selects multiple documents.
* *
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option * * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
* is only supported for server versions >= 3.2. *
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection name * @param string $collectionName Collection name
...@@ -75,7 +77,7 @@ class FindOneAndDelete implements Executable ...@@ -75,7 +77,7 @@ class FindOneAndDelete implements Executable
* @see Executable::execute() * @see Executable::execute()
* @param Server $server * @param Server $server
* @return object|null * @return object|null
* @throws UnsupportedException if collation is used and unsupported * @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors) * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function execute(Server $server) public function execute(Server $server)
......
...@@ -52,8 +52,10 @@ class FindOneAndReplace implements Executable ...@@ -52,8 +52,10 @@ class FindOneAndReplace implements Executable
* * upsert (boolean): When true, a new document is created if no document * * upsert (boolean): When true, a new document is created if no document
* matches the query. The default is false. * matches the query. The default is false.
* *
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option * * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
* is only supported for server versions >= 3.2. *
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection name * @param string $collectionName Collection name
...@@ -115,7 +117,7 @@ class FindOneAndReplace implements Executable ...@@ -115,7 +117,7 @@ class FindOneAndReplace implements Executable
* @see Executable::execute() * @see Executable::execute()
* @param Server $server * @param Server $server
* @return object|null * @return object|null
* @throws UnsupportedException if collation is used and unsupported * @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors) * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function execute(Server $server) public function execute(Server $server)
......
...@@ -52,8 +52,10 @@ class FindOneAndUpdate implements Executable ...@@ -52,8 +52,10 @@ class FindOneAndUpdate implements Executable
* * upsert (boolean): When true, a new document is created if no document * * upsert (boolean): When true, a new document is created if no document
* matches the query. The default is false. * matches the query. The default is false.
* *
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option * * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
* is only supported for server versions >= 3.2. *
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
* *
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection name * @param string $collectionName Collection name
...@@ -115,7 +117,7 @@ class FindOneAndUpdate implements Executable ...@@ -115,7 +117,7 @@ class FindOneAndUpdate implements Executable
* @see Executable::execute() * @see Executable::execute()
* @param Server $server * @param Server $server
* @return object|null * @return object|null
* @throws UnsupportedException if collation is used and unsupported * @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors) * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/ */
public function execute(Server $server) public function execute(Server $server)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment