Beispiel #1
0
 /**
  * @param String $string
  * @param $behavior
  */
 private function registerString($string, $behavior)
 {
     $existingDoc = $this->findDocument($string->hash());
     $doc = empty($existingDoc) ? $string->asDocument() : self::mergeStrings($existingDoc, $string->asDocument(), $behavior);
     if (isset($doc['_id'])) {
         $this->db->putDocument($doc, $doc['_id']);
     } else {
         $this->db->postDocument($doc);
     }
 }
 /**
  * @param CouchDBClient $studentClient
  * @param CouchDBClient $solutionClient
  * @throws \Doctrine\CouchDB\HTTP\HTTPException
  */
 private function replicateDbFromStudentToSolution(CouchDBClient $studentClient, CouchDBClient $solutionClient)
 {
     $response = $studentClient->allDocs();
     if ($response->status !== 200) {
         //should maybe throw an exception - but what should we print?
         return;
     }
     foreach ($response->body['rows'] as $row) {
         $doc = $row['doc'];
         $data = array_filter($doc, function ($key) {
             return !in_array($key, ['_id', '_rev']);
         }, ARRAY_FILTER_USE_KEY);
         try {
             $solutionClient->putDocument($data, $doc['_id'], $doc['_rev']);
         } catch (HTTPException $e) {
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function update($storageName, $key, array $data)
 {
     $key = $this->flattenKey($storageName, $key);
     $this->client->putDocument($data, $key);
 }