@@ -160,6 +160,9 @@ public function save($collectionId, Document $document, $create = NULL) {
160
160
* Update an existing document in a collection, identified by the document itself
161
161
* This will update the document on the server
162
162
* This will throw if the document cannot be updated
163
+ * If policy is set to error (locally or globally through the connectionoptions)
164
+ * and the passed document has a _rev value set, the database will check
165
+ * that the revision of the to-be-replaced document is the same as the one given.
163
166
*
164
167
* @throws Exception
165
168
* @param Document $document - document to be updated
@@ -176,6 +179,9 @@ public function update(Document $document, $policy = NULL) {
176
179
* Replace an existing document in a collection, identified by the document itself
177
180
* This will update the document on the server
178
181
* This will throw if the document cannot be replaced
182
+ * If policy is set to error (locally or globally through the connectionoptions)
183
+ * and the passed document has a _rev value set, the database will check
184
+ * that the revision of the to-be-replaced document is the same as the one given.
179
185
*
180
186
* @throws Exception
181
187
* @param Document $document - document to be updated
@@ -193,6 +199,9 @@ public function replace(Document $document, $policy = NULL) {
193
199
* Update an existing document in a collection, identified by collection id and document id
194
200
* This will update the document on the server
195
201
* This will throw if the document cannot be updated
202
+ * If policy is set to error (locally or globally through the connectionoptions)
203
+ * and the passed document has a _rev value set, the database will check
204
+ * that the revision of the to-be-replaced document is the same as the one given.
196
205
*
197
206
* @throws Exception
198
207
* @param mixed $collectionId - collection id as string or number
@@ -212,6 +221,9 @@ public function updateById($collectionId, $documentId, Document $document, $poli
212
221
* Replace an existing document in a collection, identified by collection id and document id
213
222
* This will update the document on the server
214
223
* This will throw if the document cannot be Replaced
224
+ * If policy is set to error (locally or globally through the connectionoptions)
225
+ * and the passed document has a _rev value set, the database will check
226
+ * that the revision of the to-be-replaced document is the same as the one given.
215
227
*
216
228
* @throws Exception
217
229
* @param mixed $collectionId - collection id as string or number
@@ -221,15 +233,24 @@ public function updateById($collectionId, $documentId, Document $document, $poli
221
233
* @return bool - always true, will throw if there is an error
222
234
*/
223
235
public function replaceById ($ collectionId , $ documentId , Document $ document , $ policy = NULL ) {
236
+ $ rev = $ document ->getRevision ();
237
+ if (!is_null ($ rev )) {
238
+ $ params [ConnectionOptions::OPTION_REVISION ]=$ rev ;
239
+ }
240
+
241
+
242
+
224
243
if ($ policy === NULL ) {
225
244
$ policy = $ this ->getConnection ()->getOption (ConnectionOptions::OPTION_UPDATE_POLICY );
226
245
}
227
-
246
+ $ params [ConnectionOptions::OPTION_UPDATE_POLICY ]=$ policy ;
247
+
248
+
228
249
UpdatePolicy::validate ($ policy );
229
250
230
251
$ data = $ document ->getAll ();
231
252
$ url = UrlHelper::buildUrl (Urls::URL_DOCUMENT , $ collectionId , $ documentId );
232
- $ url = UrlHelper::appendParamsUrl ($ url , array (ConnectionOptions:: OPTION_UPDATE_POLICY => $ policy ) );
253
+ $ url = UrlHelper::appendParamsUrl ($ url , $ params );
233
254
$ result = $ this ->getConnection ()->put ($ url , json_encode ($ data ));
234
255
235
256
return true ;
0 commit comments