Skip to content

Commit

Permalink
PHPLIB-539: Rework client-side error logic for unacknowledged findAnd…
Browse files Browse the repository at this point in the history
…Modify
  • Loading branch information
alcaeus committed Apr 2, 2020
1 parent 79b828e commit ee91ccf
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Operation/FindAndModify.php
Expand Up @@ -55,6 +55,9 @@ class FindAndModify implements Executable, Explainable
/** @var integer */
private static $wireVersionForDocumentLevelValidation = 4;

/** @var integer */
private static $wireVersionForHint = 9;

/** @var integer */
private static $wireVersionForHintServerSideError = 8;

Expand Down Expand Up @@ -245,7 +248,7 @@ public function execute(Server $server)
* options (SERVER-40005), but the CRUD spec requires client-side errors
* for server versions < 4.2. For later versions, we'll rely on the
* server to either utilize the option or report its own error. */
if (isset($this->options['hint']) && ! server_supports_feature($server, self::$wireVersionForHintServerSideError)) {
if (isset($this->options['hint']) && ! $this->isHintSupported($server)) {
throw UnsupportedException::hintNotSupported();
}

Expand Down Expand Up @@ -338,4 +341,20 @@ private function createOptions()

return $options;
}

private function isAcknowledgedWriteConcern() : bool
{
if (! isset($this->options['writeConcern'])) {
return true;
}

return $this->options['writeConcern']->getW() > 1 || $this->options['writeConcern']->getJournal();
}

private function isHintSupported(Server $server) : bool
{
$requiredWireVersion = $this->isAcknowledgedWriteConcern() ? self::$wireVersionForHintServerSideError : self::$wireVersionForHint;

return server_supports_feature($server, $requiredWireVersion);
}
}

0 comments on commit ee91ccf

Please sign in to comment.