Skip to content

Commit 66f60fb

Browse files
committed
Remove collation, and parse writeConcern correctly.
1 parent fb448fc commit 66f60fb

File tree

1 file changed

+8
-53
lines changed

1 file changed

+8
-53
lines changed

php_phongo.c

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -451,51 +451,12 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
451451
#define PHONGO_WRITECONCERN_ALLOWED 0x01
452452
#define PHONGO_READPREFERENCE_ALLOWED 0x02
453453

454-
/* Appends a document field for the given opts document and key. Returns true on
455-
* success; otherwise, false is returned and an exception is thrown. */
456-
static bool php_phongo_command_opts_append_document(bson_t *opts, const char *opts_key, zval *zarr, const char *zarr_key TSRMLS_DC) /* {{{ */
457-
{
458-
zval *value = php_array_fetch(zarr, zarr_key);
459-
bson_t b = BSON_INITIALIZER;
460-
461-
if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) {
462-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" option to be array or object, %s given", zarr_key, zend_get_type_by_const(Z_TYPE_P(value)));
463-
return false;
464-
}
465-
466-
php_phongo_zval_to_bson(value, PHONGO_BSON_NONE, &b, NULL TSRMLS_CC);
467-
468-
if (EG(exception)) {
469-
bson_destroy(&b);
470-
return false;
471-
}
472-
473-
if (!BSON_APPEND_DOCUMENT(opts, opts_key, &b)) {
474-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", opts_key);
475-
bson_destroy(&b);
476-
return false;
477-
}
478-
479-
bson_destroy(&b);
480-
return true;
481-
} /* }}} */
482-
483-
484-
static int process_collation(zval *option, bson_t *mongoc_opts TSRMLS_DC)
485-
{
486-
return php_phongo_command_opts_append_document(mongoc_opts, "collation", option, "collation" TSRMLS_CC);
487-
}
488-
489454
static int process_read_concern(zval *option, bson_t *mongoc_opts TSRMLS_DC)
490455
{
491456
if (Z_TYPE_P(option) == IS_OBJECT && instanceof_function(Z_OBJCE_P(option), php_phongo_readconcern_ce TSRMLS_CC)) {
492-
zval zreadConcern;
493457
const mongoc_read_concern_t *read_concern = phongo_read_concern_from_zval(option TSRMLS_CC);
494458

495-
php_phongo_read_concern_to_zval(&zreadConcern, read_concern);
496-
convert_to_object(&zreadConcern);
497-
498-
return php_phongo_command_opts_append_document(mongoc_opts, "readConcern", &zreadConcern, "readConcern" TSRMLS_CC);
459+
mongoc_read_concern_append((mongoc_read_concern_t*)read_concern, mongoc_opts);
499460
} else {
500461
phongo_throw_exception(
501462
PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC,
@@ -558,12 +519,14 @@ static int process_read_preference(zval *option, bson_t *mongoc_opts, zval **zre
558519
return true;
559520
}
560521

561-
static int process_write_concern(zval *option, bson_t *command_opts, zval **zwriteConcern TSRMLS_DC)
522+
static int process_write_concern(zval *option, bson_t *mongoc_opts, zval **zwriteConcern TSRMLS_DC)
562523
{
563524
if (Z_TYPE_P(option) == IS_OBJECT && instanceof_function(Z_OBJCE_P(option), php_phongo_writeconcern_ce TSRMLS_CC)) {
525+
const mongoc_write_concern_t *write_concern = phongo_write_concern_from_zval(option TSRMLS_CC);
526+
564527
*zwriteConcern = option;
565528

566-
error: add write concern to command_opts too
529+
mongoc_write_concern_append((mongoc_write_concern_t*) write_concern, mongoc_opts);
567530
} else {
568531
phongo_throw_exception(
569532
PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC,
@@ -590,11 +553,7 @@ static int phongo_execute_parse_options(mongoc_client_t* client, int server_id,
590553
}
591554

592555
/* URI options are case-insensitive */
593-
if (!strcasecmp(ZSTR_VAL(string_key), "collation")) {
594-
if (!process_collation(driver_option, mongoc_opts)) {
595-
return false;
596-
}
597-
} else if (!strcasecmp(ZSTR_VAL(string_key), "readConcern")) {
556+
if (!strcasecmp(ZSTR_VAL(string_key), "readConcern")) {
598557
if (!process_read_concern(driver_option, mongoc_opts)) {
599558
return false;
600559
}
@@ -627,16 +586,12 @@ static int phongo_execute_parse_options(mongoc_client_t* client, int server_id,
627586
}
628587

629588
/* URI options are case-insensitive */
630-
if (!strcasecmp(string_key, "collation")) {
631-
if (!process_collation(*driver_option, mongoc_opts)) {
632-
return false;
633-
}
634-
} else if (!strcasecmp(string_key, "readConcern")) {
589+
if (!strcasecmp(string_key, "readConcern")) {
635590
if (!process_read_concern(*driver_option, mongoc_opts)) {
636591
return false;
637592
}
638593
} else if ((!strcasecmp(string_key, "readPreference")) && (flags & PHONGO_READPREFERENCE_ALLOWED)) {
639-
if (!process_read_preference(*driver_option, zreadPreference TSRMLS_CC)) {
594+
if (!process_read_preference(*driver_option, mongoc_opts, zreadPreference, client, server_id TSRMLS_CC)) {
640595
return false;
641596
}
642597
} else if ((!strcasecmp(string_key, "writeConcern")) && (flags & PHONGO_WRITECONCERN_ALLOWED)) {

0 commit comments

Comments
 (0)