Exemple #1
0
 /**
  * Store document
  *
  * @param Document $document
  * @return void
  */
 protected function storeDocument(Document $document)
 {
     $lastRevision = $this->getLastRevisionSilent($document->_id);
     $this->data[$document->_id][$document->_rev] = $document;
     if ($this->revisionCalculator->getSequence($document->_rev) === $this->revisionCalculator->getSequence($lastRevision)) {
         $this->conflictDecider->select($document, $this->data[$document->_id][$lastRevision]);
     }
     $sequence = count($this->updates) + 1;
     $this->updates[$sequence] = new Update($sequence, $document->_id, array(new Revision($document->_rev)));
 }
Exemple #2
0
 /**
  * Store document
  *
  * @param Document $document
  * @return void
  */
 protected function storeDocument(Document $document)
 {
     $query = $this->database->prepare("INSERT INTO document (d_id, d_revision, d_document) VALUES (:id, :revision, :document);");
     $query->execute(array('id' => $document->_id, 'revision' => $document->_rev, 'document' => serialize($document)));
     $lastRevision = $this->getLastRevisionSilent($document->_id);
     if ($this->revisionCalculator->getSequence($document->_rev) === $this->revisionCalculator->getSequence($lastRevision)) {
         $this->conflictDecider->select($document, $this->getDocument($document->_id, $lastRevision));
     }
     $sequence = $this->getUpdateSequence() + 1;
     $query = $this->database->prepare("INSERT INTO document_update (du_sequence, d_id, d_revision) VALUES (:sequence, :id, :revision);");
     $query->execute(array('sequence' => $sequence, 'id' => $document->_id, 'revision' => $document->_rev));
 }
 /**
  * Filter changes
  *
  * @param Update[] $changes
  * @return Update[]
  */
 public function filterChanges(array $changes)
 {
     $sequenceMap = array();
     foreach ($changes as $index => $update) {
         $revisionSequence = $this->revisionCalculator->getSequence($update->changes[0]->rev);
         $sequenceMap[$update->id][$revisionSequence][] = $index;
     }
     foreach ($sequenceMap as $documentId => $documentChanges) {
         foreach ($documentChanges as $revisionSequence => $revisionChanges) {
             if (count($revisionChanges) > 1) {
                 $firstChange = array_shift($revisionChanges);
                 foreach ($revisionChanges as $index) {
                     $changes[$firstChange] = clone $changes[$firstChange];
                     $changes[$firstChange]->changes = array_merge($changes[$firstChange]->changes, $changes[$index]->changes);
                     $changes[$firstChange]->seq = max($changes[$firstChange]->seq, $changes[$index]->seq);
                     unset($changes[$index]);
                 }
             }
         }
     }
     return array_values($changes);
 }