@@ -238,7 +238,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
238
238
/* }}} */
239
239
240
240
/* {{{ Init objects */
241
- static void phongo_cursor_init (zval * return_value , mongoc_client_t * client , mongoc_cursor_t * cursor , zval * readPreference TSRMLS_DC ) /* {{{ */
241
+ static void phongo_cursor_init (zval * return_value , mongoc_client_t * client , mongoc_cursor_t * cursor , zval * readPreference , zval * session TSRMLS_DC ) /* {{{ */
242
242
{
243
243
php_phongo_cursor_t * intern ;
244
244
@@ -256,15 +256,24 @@ static void phongo_cursor_init(zval *return_value, mongoc_client_t *client, mong
256
256
#else
257
257
Z_ADDREF_P (readPreference );
258
258
intern -> read_preference = readPreference ;
259
+ #endif
260
+ }
261
+
262
+ if (session ) {
263
+ #if PHP_VERSION_ID >= 70000
264
+ ZVAL_ZVAL (& intern -> session , session , 1 , 0 );
265
+ #else
266
+ Z_ADDREF_P (session );
267
+ intern -> session = session ;
259
268
#endif
260
269
}
261
270
} /* }}} */
262
271
263
- static void phongo_cursor_init_for_command (zval * return_value , mongoc_client_t * client , mongoc_cursor_t * cursor , const char * db , zval * command , zval * readPreference TSRMLS_DC ) /* {{{ */
272
+ static void phongo_cursor_init_for_command (zval * return_value , mongoc_client_t * client , mongoc_cursor_t * cursor , const char * db , zval * command , zval * readPreference , zval * session TSRMLS_DC ) /* {{{ */
264
273
{
265
274
php_phongo_cursor_t * intern ;
266
275
267
- phongo_cursor_init (return_value , client , cursor , readPreference TSRMLS_CC );
276
+ phongo_cursor_init (return_value , client , cursor , readPreference , session TSRMLS_CC );
268
277
intern = Z_CURSOR_OBJ_P (return_value );
269
278
270
279
intern -> database = estrdup (db );
@@ -277,11 +286,11 @@ static void phongo_cursor_init_for_command(zval *return_value, mongoc_client_t *
277
286
#endif
278
287
} /* }}} */
279
288
280
- static void phongo_cursor_init_for_query (zval * return_value , mongoc_client_t * client , mongoc_cursor_t * cursor , const char * namespace , zval * query , zval * readPreference TSRMLS_DC ) /* {{{ */
289
+ static void phongo_cursor_init_for_query (zval * return_value , mongoc_client_t * client , mongoc_cursor_t * cursor , const char * namespace , zval * query , zval * readPreference , zval * session TSRMLS_DC ) /* {{{ */
281
290
{
282
291
php_phongo_cursor_t * intern ;
283
292
284
- phongo_cursor_init (return_value , client , cursor , readPreference TSRMLS_CC );
293
+ phongo_cursor_init (return_value , client , cursor , readPreference , session TSRMLS_CC );
285
294
intern = Z_CURSOR_OBJ_P (return_value );
286
295
287
296
/* namespace has already been validated by phongo_execute_query() */
@@ -540,11 +549,13 @@ bool phongo_parse_read_preference(zval *options, zval **zreadPreference TSRMLS_D
540
549
return true;
541
550
} /* }}} */
542
551
543
- /* Parses the "session" option for an execute method. If mongoc_opts is not
544
- * NULL, the option will be appended. If zsession is not NULL, it will be
552
+ /* Parses the "session" option for an execute method. The client object should
553
+ * correspond to the Manager executing the operation and will be used to ensure
554
+ * that the session is correctly associated with that client. If mongoc_opts is
555
+ * not NULL, the option will be appended. If zsession is not NULL, it will be
545
556
* assigned to the option. On error, false is returned and an exception is
546
557
* thrown. */
547
- static bool phongo_parse_session (zval * options , bson_t * mongoc_opts , zval * * zsession , mongoc_client_t * client TSRMLS_DC ) /* {{{ */
558
+ static bool phongo_parse_session (zval * options , mongoc_client_t * client , bson_t * mongoc_opts , zval * * zsession TSRMLS_DC ) /* {{{ */
548
559
{
549
560
zval * option = NULL ;
550
561
const mongoc_client_session_t * client_session ;
@@ -652,7 +663,7 @@ bool phongo_execute_bulk_write(mongoc_client_t *client, const char *namespace, p
652
663
return false;
653
664
}
654
665
655
- if (!phongo_parse_session (options , NULL , & zsession , client TSRMLS_CC )) {
666
+ if (!phongo_parse_session (options , client , NULL , & zsession TSRMLS_CC )) {
656
667
/* Exception should already have been thrown */
657
668
return false;
658
669
}
@@ -746,6 +757,7 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
746
757
char * collname ;
747
758
mongoc_collection_t * collection ;
748
759
zval * zreadPreference = NULL ;
760
+ zval * zsession = NULL ;
749
761
750
762
if (!phongo_split_namespace (namespace , & dbname , & collname )) {
751
763
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s: %s" , "Invalid namespace provided" , namespace );
@@ -767,7 +779,7 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
767
779
return false;
768
780
}
769
781
770
- if (!phongo_parse_session (options , query -> opts , NULL , client TSRMLS_CC )) {
782
+ if (!phongo_parse_session (options , client , query -> opts , & zsession TSRMLS_CC )) {
771
783
/* Exception should already have been thrown */
772
784
mongoc_collection_destroy (collection );
773
785
return false;
@@ -797,7 +809,8 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
797
809
return true;
798
810
}
799
811
800
- phongo_cursor_init_for_query (return_value , client , cursor , namespace , zquery , zreadPreference TSRMLS_CC );
812
+ phongo_cursor_init_for_query (return_value , client , cursor , namespace , zquery , zreadPreference , zsession TSRMLS_CC );
813
+
801
814
return true;
802
815
} /* }}} */
803
816
@@ -823,6 +836,7 @@ int phongo_execute_command(mongoc_client_t *client, php_phongo_command_type_t ty
823
836
bson_t opts = BSON_INITIALIZER ;
824
837
mongoc_cursor_t * cmd_cursor ;
825
838
zval * zreadPreference = NULL ;
839
+ zval * zsession = NULL ;
826
840
int result ;
827
841
828
842
command = Z_COMMAND_OBJ_P (zcommand );
@@ -839,7 +853,7 @@ int phongo_execute_command(mongoc_client_t *client, php_phongo_command_type_t ty
839
853
return false;
840
854
}
841
855
842
- if (!phongo_parse_session (options , & opts , NULL , client TSRMLS_CC )) {
856
+ if (!phongo_parse_session (options , client , & opts , & zsession TSRMLS_CC )) {
843
857
/* Exception should already have been thrown */
844
858
bson_destroy (& opts );
845
859
return false;
@@ -920,7 +934,7 @@ int phongo_execute_command(mongoc_client_t *client, php_phongo_command_type_t ty
920
934
bson_destroy (& reply );
921
935
}
922
936
923
- phongo_cursor_init_for_command (return_value , client , cmd_cursor , db , zcommand , zreadPreference TSRMLS_CC );
937
+ phongo_cursor_init_for_command (return_value , client , cmd_cursor , db , zcommand , zreadPreference , zsession TSRMLS_CC );
924
938
return true;
925
939
} /* }}} */
926
940
/* }}} */
0 commit comments