Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Replication.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class Replication {

protected $targetLog;

/**
* Array of deleted revs, keyed with the rev id.
*
* @var string[]
*/
protected $deletedRevs = [];

/**
* @param CouchDBClient $source
* @param CouchDBClient $target
Expand Down Expand Up @@ -71,6 +78,7 @@ public function __construct(CouchDBClient $source, CouchDBClient $target, Replic

public function start($printStatus = true, $getFinalReport = true)
{
$this->deletedRevs = [];
$this->startTime = new \DateTime();
// DB info (via GET /{db}) for source and target.
$this->verifyPeers();
Expand Down Expand Up @@ -310,6 +318,11 @@ public function getMapping($changes)
foreach ($row['changes'] as $revision) {
$mapping[$row['id']][] = $revision['rev'];
}
// Remember deleted revs for later.
if (!empty($row['deleted'])) {
$this->deletedRevs[$revision['rev']] = $revision['rev'];
}

}
return $mapping;
}
Expand Down Expand Up @@ -532,6 +545,13 @@ public function replicateChanges(array &$revDiff)
throw HTTPException::fromResponse('*/*', $response);
}
list($docStack, $multipartResponse) = $response;
// Mark docs as deleted according the changes.
foreach ($docStack as &$doc) {
$doc = json_decode($doc, true);
if (!empty($this->deletedRevs[$doc['_rev']])) {
$doc['deleted'] = TRUE;
}
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
Expand Down