Commit eb2dee4b authored by Katherine Walker's avatar Katherine Walker

PHPLIB-322: Add resume logic to ChangeStream::rewind()

parent de2e3310
...@@ -117,7 +117,26 @@ class ChangeStream implements Iterator ...@@ -117,7 +117,26 @@ class ChangeStream implements Iterator
*/ */
public function rewind() public function rewind()
{ {
$this->csIt->rewind(); $resumable = false;
try {
$this->csIt->rewind();
if ($this->valid()) {
$this->extractResumeToken($this->csIt->current());
}
} catch (RuntimeException $e) {
if (strpos($e->getMessage(), "not master") !== false) {
$resumable = true;
}
if ($e->getCode() === self::CURSOR_NOT_FOUND) {
$resumable = true;
}
if ($e instanceof ConnectionTimeoutException) {
$resumable = true;
}
}
if ($resumable) {
$this->resume();
}
} }
/** /**
......
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