Commit 8dcc7784 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-229: Operations should not accept unsupported read concern options

parent 89742f31
...@@ -36,6 +36,9 @@ type: :php:`MongoDB\\Driver\\ReadConcern <class.mongodb-driver-readconcern>` ...@@ -36,6 +36,9 @@ type: :php:`MongoDB\\Driver\\ReadConcern <class.mongodb-driver-readconcern>`
description: | description: |
:manual:`Read concern </reference/read-concern>` to use for the operation. :manual:`Read concern </reference/read-concern>` to use for the operation.
Defaults to the collection's read concern. Defaults to the collection's read concern.
This is not supported for server versions prior to 3.2 and will result in an
exception at execution time if used.
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
......
...@@ -29,5 +29,6 @@ content: | ...@@ -29,5 +29,6 @@ content: |
ref: error-unsupportedexception ref: error-unsupportedexception
content: | content: |
:phpclass:`MongoDB\\Exception\\UnsupportedException` if options are used and :phpclass:`MongoDB\\Exception\\UnsupportedException` if options are used and
not supported by the selected server (e.g. ``collation``, ``writeConcern``). not supported by the selected server (e.g. ``collation``, ``readConcern``,
``writeConcern``).
... ...
...@@ -14,6 +14,16 @@ class UnsupportedException extends RuntimeException implements Exception ...@@ -14,6 +14,16 @@ class UnsupportedException extends RuntimeException implements Exception
return new static('Collations are not supported by the server executing this operation'); return new static('Collations are not supported by the server executing this operation');
} }
/**
* Thrown when a command's readConcern option is not supported by a server.
*
* @return self
*/
public static function readConcernNotSupported()
{
return new static('Read concern is not supported by the server executing this command');
}
/** /**
* Thrown when a command's writeConcern option is not supported by a server. * Thrown when a command's writeConcern option is not supported by a server.
* *
......
...@@ -64,8 +64,8 @@ class Aggregate implements Executable ...@@ -64,8 +64,8 @@ class Aggregate implements Executable
* * readConcern (MongoDB\Driver\ReadConcern): Read concern. Note that a * * readConcern (MongoDB\Driver\ReadConcern): Read concern. Note that a
* "majority" read concern is not compatible with the $out stage. * "majority" read concern is not compatible with the $out stage.
* *
* For servers < 3.2, this option is ignored as read concern is not * This is not supported for server versions < 3.2 and will result in an
* available. * exception at execution time if used.
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
...@@ -182,7 +182,7 @@ class Aggregate implements Executable ...@@ -182,7 +182,7 @@ class Aggregate implements Executable
* @param Server $server * @param Server $server
* @return Traversable * @return Traversable
* @throws UnexpectedValueException if the command response was malformed * @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation or write concern is used and unsupported * @throws UnsupportedException if collation, read concern, 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)
...@@ -191,6 +191,10 @@ class Aggregate implements Executable ...@@ -191,6 +191,10 @@ class Aggregate implements Executable
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported();
}
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported(); throw UnsupportedException::writeConcernNotSupported();
} }
...@@ -254,7 +258,7 @@ class Aggregate implements Executable ...@@ -254,7 +258,7 @@ class Aggregate implements Executable
$cmd['maxTimeMS'] = $this->options['maxTimeMS']; $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
} }
if (isset($this->options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern'])) {
$cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']); $cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']);
} }
......
...@@ -48,8 +48,8 @@ class Count implements Executable ...@@ -48,8 +48,8 @@ class Count implements Executable
* *
* * readConcern (MongoDB\Driver\ReadConcern): Read concern. * * readConcern (MongoDB\Driver\ReadConcern): Read concern.
* *
* For servers < 3.2, this option is ignored as read concern is not * This is not supported for server versions < 3.2 and will result in an
* available. * exception at execution time if used.
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
...@@ -115,7 +115,7 @@ class Count implements Executable ...@@ -115,7 +115,7 @@ class Count implements Executable
* @param Server $server * @param Server $server
* @return integer * @return integer
* @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 read 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)
...@@ -124,6 +124,10 @@ class Count implements Executable ...@@ -124,6 +124,10 @@ class Count implements Executable
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported();
}
$readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null; $readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null;
$cursor = $server->executeCommand($this->databaseName, $this->createCommand($server), $readPreference); $cursor = $server->executeCommand($this->databaseName, $this->createCommand($server), $readPreference);
...@@ -161,7 +165,7 @@ class Count implements Executable ...@@ -161,7 +165,7 @@ class Count implements Executable
} }
} }
if (isset($this->options['readConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { if (isset($this->options['readConcern'])) {
$cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']); $cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']);
} }
......
...@@ -44,8 +44,8 @@ class Distinct implements Executable ...@@ -44,8 +44,8 @@ class Distinct implements Executable
* *
* * readConcern (MongoDB\Driver\ReadConcern): Read concern. * * readConcern (MongoDB\Driver\ReadConcern): Read concern.
* *
* For servers < 3.2, this option is ignored as read concern is not * This is not supported for server versions < 3.2 and will result in an
* available. * exception at execution time if used.
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
...@@ -92,7 +92,7 @@ class Distinct implements Executable ...@@ -92,7 +92,7 @@ class Distinct implements Executable
* @param Server $server * @param Server $server
* @return mixed[] * @return mixed[]
* @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 read 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)
...@@ -101,6 +101,10 @@ class Distinct implements Executable ...@@ -101,6 +101,10 @@ class Distinct implements Executable
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported();
}
$readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null; $readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null;
$cursor = $server->executeCommand($this->databaseName, $this->createCommand($server), $readPreference); $cursor = $server->executeCommand($this->databaseName, $this->createCommand($server), $readPreference);
......
...@@ -75,8 +75,8 @@ class Find implements Executable ...@@ -75,8 +75,8 @@ class Find implements Executable
* *
* * readConcern (MongoDB\Driver\ReadConcern): Read concern. * * readConcern (MongoDB\Driver\ReadConcern): Read concern.
* *
* For servers < 3.2, this option is ignored as read concern is not * This is not supported for server versions < 3.2 and will result in an
* available. * exception at execution time if used.
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
...@@ -185,7 +185,7 @@ class Find implements Executable ...@@ -185,7 +185,7 @@ class Find implements Executable
* @see Executable::execute() * @see Executable::execute()
* @param Server $server * @param Server $server
* @return Cursor * @return Cursor
* @throws UnsupportedException if collation is used and unsupported * @throws UnsupportedException if collation or read 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)
...@@ -194,6 +194,10 @@ class Find implements Executable ...@@ -194,6 +194,10 @@ class Find implements Executable
throw UnsupportedException::collationNotSupported(); throw UnsupportedException::collationNotSupported();
} }
if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
throw UnsupportedException::readConcernNotSupported();
}
$readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null; $readPreference = isset($this->options['readPreference']) ? $this->options['readPreference'] : null;
$cursor = $server->executeQuery($this->databaseName . '.' . $this->collectionName, $this->createQuery(), $readPreference); $cursor = $server->executeQuery($this->databaseName . '.' . $this->collectionName, $this->createQuery(), $readPreference);
......
...@@ -45,8 +45,8 @@ class FindOne implements Executable ...@@ -45,8 +45,8 @@ class FindOne implements Executable
* *
* * readConcern (MongoDB\Driver\ReadConcern): Read concern. * * readConcern (MongoDB\Driver\ReadConcern): Read concern.
* *
* For servers < 3.2, this option is ignored as read concern is not * This is not supported for server versions < 3.2 and will result in an
* available. * exception at execution time if used.
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
...@@ -82,7 +82,7 @@ class FindOne implements Executable ...@@ -82,7 +82,7 @@ class FindOne implements Executable
* @see Executable::execute() * @see Executable::execute()
* @param Server $server * @param Server $server
* @return array|object|null * @return array|object|null
* @throws UnsupportedException if collation is used and unsupported * @throws UnsupportedException if collation or read 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