Esempio n. 1
0
 /**
  * Store synced change
  *
  * Returns the revision of the created document.
  *
  * @param array $revisionDocument
  * @return string
  */
 public function storeSyncedChange(array $revisionDocument)
 {
     $id = substr($revisionDocument['_id'], strpos($revisionDocument['_id'], '/') + 1);
     $revisionDocument['_rev'] = $this->revisionCalculator->getNextRevision($revisionDocument);
     $this->syncedRevisions[$id] = $revisionDocument;
     return $revisionDocument['_rev'];
 }
Esempio n. 2
0
 /**
  * Store synced change
  *
  * Returns the revision of the created document.
  *
  * @param array $revisionDocument
  * @return string
  */
 public function storeSyncedChange(array $revisionDocument)
 {
     $revisionId = substr($revisionDocument['_id'], strpos($revisionDocument['_id'], '/') + 1);
     $revisionDocument['_rev'] = $this->revisionCalculator->getNextRevision($revisionDocument);
     $query = $this->database->prepare("INSERT INTO\n                revision (r_id, r_revision)\n            VALUES\n                (:id, :revision)\n            ON DUPLICATE KEY UPDATE\n                r_revision = VALUES(r_revision);");
     $query->execute(array('id' => $revisionId, 'revision' => serialize($revisionDocument)));
     return $revisionDocument['_rev'];
 }
Esempio n. 3
0
 /**
  * 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);
 }