@@ -594,21 +594,32 @@ public function saveVertex($graph, $document, $collection = null)
594
594
if (is_array ($ document )) {
595
595
$ document = Vertex::createFromArray ($ document );
596
596
}
597
+
598
+ $ vertexCollections = $ this ->getVertexCollections ($ graph );
599
+ $ vertexCollectionsCount = count ($ vertexCollections );
597
600
if ($ collection === null ) {
598
- if (count ( $ this -> getVertexCollections ( $ graph )) !== 1 ) {
601
+ if ($ vertexCollectionsCount !== 1 ) {
599
602
throw new ClientException ('A collection must be provided. ' );
600
603
}
601
- else if (count ($ this ->getVertexCollections ($ graph )) === 1 ) {
602
- $ collection = $ this ->getVertexCollections ($ graph );
603
- $ collection = $ collection [0 ];
604
+ else if ($ vertexCollectionsCount === 1 ) {
605
+ $ collection = $ vertexCollections [0 ];
604
606
}
605
607
}
606
608
$ data = $ document ->getAll ();
607
609
$ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX , $ collection ]);
608
610
609
611
$ response = $ this ->getConnection ()->post ($ url , $ this ->json_encode_wrapper ($ data ));
610
612
611
- $ jsonArray = $ response ->getJson ();
613
+ // This makes sure that if we're in batch mode, it will not go further and choke on the checks below.
614
+ // Caution: Instead of a document ID, we are returning the batchpart object.
615
+ // The Id of the BatchPart can be retrieved by calling getId() on it.
616
+ // We're basically returning an object here, in order not to accidentally use the batch part id as the document id
617
+ if ($ batchPart = $ response ->getBatchPart ())
618
+ {
619
+ return $ batchPart ;
620
+ }
621
+
622
+ $ jsonArray = $ response ->getJson ();
612
623
$ vertex = $ jsonArray ['vertex ' ];
613
624
614
625
$ document ->setInternalId ($ vertex [Vertex::ENTRY_ID ]);
0 commit comments