Skip to content

Commit 7264710

Browse files
committed
BulkWriteCommand::replaceOne() need not accept root-level arrays
1 parent 09ce866 commit 7264710

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Diff for: src/MongoDB/BulkWriteCommand.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,19 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommand, replaceOne)
445445
char* ns;
446446
size_t ns_len;
447447
zval* zfilter;
448-
zval* zupdate;
449-
zval* zoptions = NULL;
450-
bson_t bfilter = BSON_INITIALIZER;
451-
bson_t bupdate = BSON_INITIALIZER;
452-
mongoc_bulkwrite_replaceoneopts_t* opts = NULL;
453-
bson_error_t error = { 0 };
448+
zval* zreplacement;
449+
zval* zoptions = NULL;
450+
bson_t bfilter = BSON_INITIALIZER;
451+
bson_t breplacement = BSON_INITIALIZER;
452+
mongoc_bulkwrite_replaceoneopts_t* opts = NULL;
453+
bson_error_t error = { 0 };
454454

455455
intern = Z_BULKWRITECOMMAND_OBJ_P(getThis());
456456

457457
PHONGO_PARSE_PARAMETERS_START(3, 4)
458458
Z_PARAM_STRING(ns, ns_len)
459459
Z_PARAM_ARRAY_OR_OBJECT(zfilter)
460-
Z_PARAM_ARRAY_OR_OBJECT(zupdate)
460+
Z_PARAM_ARRAY_OR_OBJECT(zreplacement)
461461
Z_PARAM_OPTIONAL
462462
Z_PARAM_ARRAY_OR_NULL(zoptions)
463463
PHONGO_PARSE_PARAMETERS_END();
@@ -473,8 +473,7 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommand, replaceOne)
473473
goto cleanup;
474474
}
475475

476-
// Explicitly allow MongoDB\BSON\PackedArray for update pipelines
477-
php_phongo_zval_to_bson(zupdate, PHONGO_BSON_ALLOW_ROOT_ARRAY, &bupdate, NULL);
476+
php_phongo_zval_to_bson(zreplacement, PHONGO_BSON_NONE, &breplacement, NULL);
478477

479478
if (EG(exception)) {
480479
goto cleanup;
@@ -524,7 +523,7 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommand, replaceOne)
524523
}
525524
}
526525

527-
if (!mongoc_bulkwrite_append_replaceone(intern->bw, ns, &bfilter, &bupdate, opts, &error)) {
526+
if (!mongoc_bulkwrite_append_replaceone(intern->bw, ns, &bfilter, &breplacement, opts, &error)) {
528527
phongo_throw_exception_from_bson_error_t(&error);
529528
goto cleanup;
530529
}
@@ -533,7 +532,7 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommand, replaceOne)
533532

534533
cleanup:
535534
bson_destroy(&bfilter);
536-
bson_destroy(&bupdate);
535+
bson_destroy(&breplacement);
537536
mongoc_bulkwrite_replaceoneopts_destroy(opts);
538537
}
539538

0 commit comments

Comments
 (0)