Unverified Commit 5042a2fa authored by Andreas Braun's avatar Andreas Braun

Merge pull request #662

parents e4213652 f86f2207
......@@ -220,7 +220,7 @@ class ChangeStream implements Iterator
*/
private function resume()
{
$this->iterator = call_user_func($this->resumeCallable, $this->getResumeToken());
$this->iterator = call_user_func($this->resumeCallable, $this->getResumeToken(), $this->hasAdvanced);
$this->iterator->rewind();
$this->onIteration($this->hasAdvanced);
......
......@@ -250,7 +250,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
{
return new ChangeStream(
$this->createChangeStreamIterator($server),
function($resumeToken) { return $this->resume($resumeToken); }
function($resumeToken, $hasAdvanced) { return $this->resume($resumeToken, $hasAdvanced); }
);
}
......@@ -333,10 +333,11 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
*
* @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#resume-process
* @param array|object|null $resumeToken
* @param bool $hasAdvanced
* @return ChangeStreamIterator
* @throws InvalidArgumentException
*/
private function resume($resumeToken = null)
private function resume($resumeToken = null, $hasAdvanced = false)
{
if (isset($resumeToken) && ! is_array($resumeToken) && ! is_object($resumeToken)) {
throw InvalidArgumentException::invalidType('$resumeToken', $resumeToken, 'array or object');
......@@ -347,12 +348,14 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
// Select a new server using the original read preference
$server = $this->manager->selectServer($this->aggregateOptions['readPreference']);
$resumeOption = isset($this->changeStreamOptions['startAfter']) && !$hasAdvanced ? 'startAfter' : 'resumeAfter';
unset($this->changeStreamOptions['resumeAfter']);
unset($this->changeStreamOptions['startAfter']);
unset($this->changeStreamOptions['startAtOperationTime']);
if ($resumeToken !== null) {
$this->changeStreamOptions['resumeAfter'] = $resumeToken;
$this->changeStreamOptions[$resumeOption] = $resumeToken;
}
if ($resumeToken === null && $this->operationTime !== null) {
......
This diff is collapsed.
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