@@ -448,32 +448,30 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
448
448
return mongoc_bulk_operation_new (ordered );
449
449
} /* }}} */
450
450
451
- #define PHONGO_WRITECONCERN_ALLOWED 0x01
452
- #define PHONGO_READPREFERENCE_ALLOWED 0x02
453
-
454
451
static bool process_read_concern (zval * option , bson_t * mongoc_opts TSRMLS_DC )
455
452
{
456
453
if (Z_TYPE_P (option ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (option ), php_phongo_readconcern_ce TSRMLS_CC )) {
457
454
const mongoc_read_concern_t * read_concern = phongo_read_concern_from_zval (option TSRMLS_CC );
458
455
459
456
if (!mongoc_read_concern_append ((mongoc_read_concern_t * )read_concern , mongoc_opts )) {
460
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"%s\" option" , "ReadPreference" );
457
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"%s\" option" , "ReadConcern" );
458
+ return false;
461
459
}
462
460
} else {
463
461
phongo_throw_exception (
464
462
PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC ,
465
- "Expected 'readConcern' option to be 'MongoDB\\Driver\\ReadPreference ', %s given" ,
463
+ "Expected 'readConcern' option to be 'MongoDB\\Driver\\ReadConcern ', %s given" ,
466
464
zend_get_type_by_const (Z_TYPE_P (option ))
467
465
);
468
466
return false;
469
467
}
470
468
return true;
471
469
}
472
470
473
- static int phongo_do_select_server (mongoc_client_t * client , bson_t * opts , zval * zreadPreference , int server_id TSRMLS_DC )
471
+ static uint32_t phongo_do_select_server (mongoc_client_t * client , bson_t * opts , zval * zreadPreference , int server_id TSRMLS_DC )
474
472
{
475
473
bson_error_t error ;
476
- uint32_t selected_server_id ;
474
+ uint32_t selected_server_id = 0 ;
477
475
478
476
if (server_id > 0 ) {
479
477
bson_append_int32 (opts , "serverId" , -1 , server_id );
@@ -491,8 +489,6 @@ static int phongo_do_select_server(mongoc_client_t *client, bson_t *opts, zval *
491
489
if (!EG (exception )) {
492
490
phongo_throw_exception_from_bson_error_t (& error TSRMLS_CC );
493
491
}
494
-
495
- return false;
496
492
}
497
493
}
498
494
@@ -504,7 +500,9 @@ static bool process_read_preference(zval *option, bson_t *mongoc_opts, zval **zr
504
500
if (Z_TYPE_P (option ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (option ), php_phongo_readpreference_ce TSRMLS_CC )) {
505
501
int selected_server_id ;
506
502
507
- * zreadPreference = option ;
503
+ if (zreadPreference ) {
504
+ * zreadPreference = option ;
505
+ }
508
506
509
507
selected_server_id = phongo_do_select_server (client , mongoc_opts , * zreadPreference , server_id TSRMLS_CC );
510
508
if (!selected_server_id ) {
@@ -526,7 +524,9 @@ static bool process_write_concern(zval *option, bson_t *mongoc_opts, zval **zwri
526
524
if (Z_TYPE_P (option ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (option ), php_phongo_writeconcern_ce TSRMLS_CC )) {
527
525
const mongoc_write_concern_t * write_concern = phongo_write_concern_from_zval (option TSRMLS_CC );
528
526
529
- * zwriteConcern = option ;
527
+ if (zwriteConcern ) {
528
+ * zwriteConcern = option ;
529
+ }
530
530
531
531
if (!mongoc_write_concern_append ((mongoc_write_concern_t * ) write_concern , mongoc_opts )) {
532
532
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Error appending \"%s\" option" , "WriteConcern" );
@@ -542,7 +542,7 @@ static bool process_write_concern(zval *option, bson_t *mongoc_opts, zval **zwri
542
542
return true;
543
543
}
544
544
545
- static int phongo_execute_parse_options (mongoc_client_t * client , int server_id , zval * driver_options , int flags , bson_t * mongoc_opts , zval * * zreadPreference , zval * * zwriteConcern TSRMLS_DC )
545
+ static int phongo_execute_parse_options (mongoc_client_t * client , int server_id , zval * driver_options , int type , bson_t * mongoc_opts , zval * * zreadPreference , zval * * zwriteConcern TSRMLS_DC )
546
546
{
547
547
if (driver_options && Z_TYPE_P (driver_options ) == IS_ARRAY ) {
548
548
HashTable * ht_data = HASH_OF (driver_options );
@@ -557,15 +557,15 @@ static int phongo_execute_parse_options(mongoc_client_t* client, int server_id,
557
557
}
558
558
559
559
/* URI options are case-insensitive */
560
- if (!strcasecmp (ZSTR_VAL (string_key ), "readConcern" )) {
560
+ if (( !strcasecmp (ZSTR_VAL (string_key ), "readConcern" )) && ( type & PHONGO_COMMAND_READ )) {
561
561
if (!process_read_concern (driver_option , mongoc_opts )) {
562
562
return false;
563
563
}
564
- } else if ((!strcasecmp (ZSTR_VAL (string_key ), "readPreference" )) && (flags & PHONGO_READPREFERENCE_ALLOWED )) {
564
+ } else if ((!strcasecmp (ZSTR_VAL (string_key ), "readPreference" )) && (type == PHONGO_COMMAND_READ || type == PHONGO_COMMAND_RAW )) {
565
565
if (!process_read_preference (driver_option , mongoc_opts , zreadPreference , client , server_id )) {
566
566
return false;
567
567
}
568
- } else if ((!strcasecmp (ZSTR_VAL (string_key ), "writeConcern" )) && (flags & PHONGO_WRITECONCERN_ALLOWED )) {
568
+ } else if ((!strcasecmp (ZSTR_VAL (string_key ), "writeConcern" )) && (type & PHONGO_COMMAND_WRITE )) {
569
569
if (!process_write_concern (driver_option , mongoc_opts , zwriteConcern )) {
570
570
return false;
571
571
}
@@ -590,15 +590,15 @@ static int phongo_execute_parse_options(mongoc_client_t* client, int server_id,
590
590
}
591
591
592
592
/* URI options are case-insensitive */
593
- if (!strcasecmp (string_key , "readConcern" )) {
593
+ if (( !strcasecmp (string_key , "readConcern" )) && ( type & PHONGO_COMMAND_READ )) {
594
594
if (!process_read_concern (* driver_option , mongoc_opts )) {
595
595
return false;
596
596
}
597
- } else if ((!strcasecmp (string_key , "readPreference" )) && (flags & PHONGO_READPREFERENCE_ALLOWED )) {
597
+ } else if ((!strcasecmp (string_key , "readPreference" )) && (type == PHONGO_COMMAND_READ )) {
598
598
if (!process_read_preference (* driver_option , mongoc_opts , zreadPreference , client , server_id TSRMLS_CC )) {
599
599
return false;
600
600
}
601
- } else if ((!strcasecmp (string_key , "writeConcern" )) && (flags & PHONGO_WRITECONCERN_ALLOWED )) {
601
+ } else if ((!strcasecmp (string_key , "writeConcern" )) && (type & PHONGO_COMMAND_WRITE )) {
602
602
if (!process_write_concern (* driver_option , mongoc_opts , zwriteConcern TSRMLS_CC )) {
603
603
return false;
604
604
}
@@ -635,7 +635,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, php_ph
635
635
/* FIXME: Legacy way of specifying the writeConcern option into this function */
636
636
if (options && Z_TYPE_P (options ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (options ), php_phongo_writeconcern_ce TSRMLS_CC )) {
637
637
zwriteConcern = options ;
638
- } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_WRITECONCERN_ALLOWED , NULL , NULL , & zwriteConcern TSRMLS_CC )) {
638
+ } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_COMMAND_WRITE , NULL , NULL , & zwriteConcern TSRMLS_CC )) {
639
639
return false;
640
640
}
641
641
@@ -742,7 +742,7 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
742
742
/* FIXME: Legacy way of specifying the readPreference option into this function */
743
743
if (options && Z_TYPE_P (options ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (options ), php_phongo_readpreference_ce TSRMLS_CC )) {
744
744
zreadPreference = options ;
745
- } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_READPREFERENCE_ALLOWED , NULL , & zreadPreference , NULL TSRMLS_CC )) {
745
+ } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_COMMAND_READ , NULL , & zreadPreference , NULL TSRMLS_CC )) {
746
746
return false;
747
747
}
748
748
@@ -804,7 +804,7 @@ int phongo_execute_command(mongoc_client_t *client, php_phongo_command_type_t ty
804
804
/* FIXME: Legacy way of specifying the readPreference option into this function */
805
805
if (options && Z_TYPE_P (options ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (options ), php_phongo_readpreference_ce TSRMLS_CC )) {
806
806
zreadPreference = options ;
807
- } else if (!phongo_execute_parse_options (client , server_id , options , PHONGO_READPREFERENCE_ALLOWED , opts , & zreadPreference , NULL TSRMLS_CC )) {
807
+ } else if (!phongo_execute_parse_options (client , server_id , options , type , opts , & zreadPreference , NULL TSRMLS_CC )) {
808
808
return false;
809
809
}
810
810
0 commit comments