@@ -451,51 +451,12 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
451
451
#define PHONGO_WRITECONCERN_ALLOWED 0x01
452
452
#define PHONGO_READPREFERENCE_ALLOWED 0x02
453
453
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
-
489
454
static int process_read_concern (zval * option , bson_t * mongoc_opts TSRMLS_DC )
490
455
{
491
456
if (Z_TYPE_P (option ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (option ), php_phongo_readconcern_ce TSRMLS_CC )) {
492
- zval zreadConcern ;
493
457
const mongoc_read_concern_t * read_concern = phongo_read_concern_from_zval (option TSRMLS_CC );
494
458
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 );
499
460
} else {
500
461
phongo_throw_exception (
501
462
PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC ,
@@ -558,12 +519,14 @@ static int process_read_preference(zval *option, bson_t *mongoc_opts, zval **zre
558
519
return true;
559
520
}
560
521
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 )
562
523
{
563
524
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
+
564
527
* zwriteConcern = option ;
565
528
566
- error : add write concern to command_opts too
529
+ mongoc_write_concern_append (( mongoc_write_concern_t * ) write_concern , mongoc_opts );
567
530
} else {
568
531
phongo_throw_exception (
569
532
PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC ,
@@ -590,11 +553,7 @@ static int phongo_execute_parse_options(mongoc_client_t* client, int server_id,
590
553
}
591
554
592
555
/* 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" )) {
598
557
if (!process_read_concern (driver_option , mongoc_opts )) {
599
558
return false;
600
559
}
@@ -627,16 +586,12 @@ static int phongo_execute_parse_options(mongoc_client_t* client, int server_id,
627
586
}
628
587
629
588
/* 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" )) {
635
590
if (!process_read_concern (* driver_option , mongoc_opts )) {
636
591
return false;
637
592
}
638
593
} 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 )) {
640
595
return false;
641
596
}
642
597
} else if ((!strcasecmp (string_key , "writeConcern" )) && (flags & PHONGO_WRITECONCERN_ALLOWED )) {
0 commit comments