@@ -603,19 +603,11 @@ static bson_t *create_wrapped_command_envelope(const char *db, bson_t *reply)
603603 return tmp ;
604604}
605605
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 )
607607{
608- const php_phongo_command_t * command ;
609- bson_iter_t iter ;
610- bson_t reply ;
611608 bson_error_t error ;
612- bson_t * opts ;
613- mongoc_cursor_t * cmd_cursor ;
614609 uint32_t selected_server_id ;
615610
616- command = Z_COMMAND_OBJ_P (zcommand );
617-
618- opts = bson_new ();
619611 if (server_id > 0 ) {
620612 bson_append_int32 (opts , "serverId" , -1 , server_id );
621613 selected_server_id = server_id ;
@@ -633,11 +625,33 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, zval *zcomma
633625 phongo_throw_exception_from_bson_error_t (& error TSRMLS_CC );
634626 }
635627
636- bson_free (opts );
637628 return false;
638629 }
639630 }
640631
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+
641655 if (!mongoc_client_command_with_opts (client , db , command -> bson , phongo_read_preference_from_zval (zreadPreference TSRMLS_CC ), opts , & reply , & error )) {
642656 phongo_throw_exception_from_bson_error_t (& error TSRMLS_CC );
643657 bson_free (opts );
0 commit comments