@@ -603,19 +603,11 @@ static bson_t *create_wrapped_command_envelope(const char *db, bson_t *reply)
603
603
return tmp ;
604
604
}
605
605
606
- int phongo_execute_command (mongoc_client_t * client , const char * db , zval * zcommand , zval * zreadPreference , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
606
+ static int phongo_do_select_server (mongoc_client_t * client , bson_t * opts , zval * zreadPreference , int server_id )
607
607
{
608
- const php_phongo_command_t * command ;
609
- bson_iter_t iter ;
610
- bson_t reply ;
611
608
bson_error_t error ;
612
- bson_t * opts ;
613
- mongoc_cursor_t * cmd_cursor ;
614
609
uint32_t selected_server_id ;
615
610
616
- command = Z_COMMAND_OBJ_P (zcommand );
617
-
618
- opts = bson_new ();
619
611
if (server_id > 0 ) {
620
612
bson_append_int32 (opts , "serverId" , -1 , server_id );
621
613
selected_server_id = server_id ;
@@ -633,11 +625,33 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, zval *zcomma
633
625
phongo_throw_exception_from_bson_error_t (& error TSRMLS_CC );
634
626
}
635
627
636
- bson_free (opts );
637
628
return false;
638
629
}
639
630
}
640
631
632
+ return selected_server_id ;
633
+ }
634
+
635
+ int phongo_execute_command (mongoc_client_t * client , const char * db , zval * zcommand , zval * zreadPreference , int server_id , zval * return_value , int return_value_used TSRMLS_DC ) /* {{{ */
636
+ {
637
+ const php_phongo_command_t * command ;
638
+ bson_iter_t iter ;
639
+ bson_t reply ;
640
+ bson_error_t error ;
641
+ bson_t * opts ;
642
+ mongoc_cursor_t * cmd_cursor ;
643
+ uint32_t selected_server_id ;
644
+
645
+ command = Z_COMMAND_OBJ_P (zcommand );
646
+
647
+ opts = bson_new ();
648
+
649
+ selected_server_id = phongo_do_select_server (client , opts , zreadPreference , server_id );
650
+ if (!selected_server_id ) {
651
+ bson_free (opts );
652
+ return false;
653
+ }
654
+
641
655
if (!mongoc_client_command_with_opts (client , db , command -> bson , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ), opts , & reply , & error )) {
642
656
phongo_throw_exception_from_bson_error_t (& error TSRMLS_CC );
643
657
bson_free (opts );
0 commit comments