@@ -192,7 +192,7 @@ static void php_phongo_manager_prep_uri_options(zval* options) /* {{{ */
192192 *
193193 * On success, server_id will be set and the function will return true;
194194 * otherwise, false is returned and an exception is thrown. */
195- static bool php_phongo_manager_select_server (bool for_writes , zval * zreadPreference , zval * zsession , mongoc_client_t * client , uint32_t * server_id ) /* {{{ */
195+ static bool php_phongo_manager_select_server (bool for_writes , bool inherit_read_preference , zval * zreadPreference , zval * zsession , mongoc_client_t * client , uint32_t * server_id ) /* {{{ */
196196{
197197 mongoc_server_description_t * selected_server ;
198198 const mongoc_read_prefs_t * read_preference = NULL ;
@@ -210,7 +210,11 @@ static bool php_phongo_manager_select_server(bool for_writes, zval* zreadPrefere
210210 }
211211
212212 if (!for_writes ) {
213- read_preference = zreadPreference ? phongo_read_preference_from_zval (zreadPreference ) : mongoc_client_get_read_prefs (client );
213+ if (zreadPreference ) {
214+ read_preference = phongo_read_preference_from_zval (zreadPreference );
215+ } else if (inherit_read_preference ) {
216+ read_preference = mongoc_client_get_read_prefs (client );
217+ }
214218 }
215219
216220 selected_server = mongoc_client_select_server (client , for_writes , read_preference , & error );
@@ -322,7 +326,7 @@ static PHP_METHOD(Manager, executeCommand)
322326 goto cleanup ;
323327 }
324328
325- if (!php_phongo_manager_select_server (false, zreadPreference , zsession , intern -> client , & server_id )) {
329+ if (!php_phongo_manager_select_server (false, false, zreadPreference , zsession , intern -> client , & server_id )) {
326330 /* Exception should already have been thrown */
327331 goto cleanup ;
328332 }
@@ -369,7 +373,7 @@ static PHP_METHOD(Manager, executeReadCommand)
369373 return ;
370374 }
371375
372- if (!php_phongo_manager_select_server (false, zreadPreference , zsession , intern -> client , & server_id )) {
376+ if (!php_phongo_manager_select_server (false, true, zreadPreference , zsession , intern -> client , & server_id )) {
373377 /* Exception should already have been thrown */
374378 return ;
375379 }
@@ -405,7 +409,7 @@ static PHP_METHOD(Manager, executeWriteCommand)
405409 return ;
406410 }
407411
408- if (!php_phongo_manager_select_server (true, NULL , zsession , intern -> client , & server_id )) {
412+ if (!php_phongo_manager_select_server (true, false, NULL , zsession , intern -> client , & server_id )) {
409413 /* Exception should already have been thrown */
410414 return ;
411415 }
@@ -441,7 +445,7 @@ static PHP_METHOD(Manager, executeReadWriteCommand)
441445 return ;
442446 }
443447
444- if (!php_phongo_manager_select_server (true, NULL , zsession , intern -> client , & server_id )) {
448+ if (!php_phongo_manager_select_server (true, false, NULL , zsession , intern -> client , & server_id )) {
445449 /* Exception should already have been thrown */
446450 return ;
447451 }
@@ -486,7 +490,7 @@ static PHP_METHOD(Manager, executeQuery)
486490 goto cleanup ;
487491 }
488492
489- if (!php_phongo_manager_select_server (false, zreadPreference , zsession , intern -> client , & server_id )) {
493+ if (!php_phongo_manager_select_server (false, true, zreadPreference , zsession , intern -> client , & server_id )) {
490494 /* Exception should already have been thrown */
491495 goto cleanup ;
492496 }
@@ -532,7 +536,7 @@ static PHP_METHOD(Manager, executeBulkWrite)
532536 return ;
533537 }
534538
535- if (!php_phongo_manager_select_server (true, NULL , zsession , intern -> client , & server_id )) {
539+ if (!php_phongo_manager_select_server (true, false, NULL , zsession , intern -> client , & server_id )) {
536540 /* Exception should already have been thrown */
537541 goto cleanup ;
538542 }
@@ -635,7 +639,7 @@ static PHP_METHOD(Manager, selectServer)
635639 return ;
636640 }
637641
638- if (!php_phongo_manager_select_server (false, zreadPreference , NULL , intern -> client , & server_id )) {
642+ if (!php_phongo_manager_select_server (false, true, zreadPreference , NULL , intern -> client , & server_id )) {
639643 /* Exception should already have been thrown */
640644 return ;
641645 }
0 commit comments