@@ -98,13 +98,21 @@ static const char* php_phongo_get_transaction_state_string(mongoc_transaction_st
98
98
}
99
99
}
100
100
101
- static void php_phongo_transaction_options_to_zval (mongoc_transaction_opt_t * opts , zval * retval )
101
+ static void php_phongo_transaction_options_to_zval (mongoc_client_session_t * cs , zval * retval )
102
102
{
103
+ mongoc_transaction_opt_t * opts ;
103
104
int64_t max_commit_time_ms ;
104
105
const mongoc_read_concern_t * read_concern ;
105
106
const mongoc_read_prefs_t * read_preference ;
106
107
const mongoc_write_concern_t * write_concern ;
107
108
109
+ if (!cs ) {
110
+ ZVAL_NULL (retval );
111
+ return ;
112
+ }
113
+
114
+ opts = mongoc_session_opts_get_transaction_opts (cs );
115
+
108
116
if (!opts ) {
109
117
ZVAL_NULL (retval );
110
118
return ;
@@ -141,6 +149,8 @@ static void php_phongo_transaction_options_to_zval(mongoc_transaction_opt_t* opt
141
149
phongo_writeconcern_init (& zwrite_concern , write_concern );
142
150
ADD_ASSOC_ZVAL_EX (retval , "writeConcern" , & zwrite_concern );
143
151
}
152
+
153
+ mongoc_transaction_opts_destroy (opts );
144
154
}
145
155
146
156
/* {{{ proto void MongoDB\Driver\Session::advanceClusterTime(array|object $clusterTime)
@@ -332,8 +342,8 @@ static PHP_METHOD(Session, getServer)
332
342
Returns options for the currently running transaction */
333
343
static PHP_METHOD (Session , getTransactionOptions )
334
344
{
335
- zend_error_handling error_handling ;
336
- php_phongo_session_t * intern ;
345
+ zend_error_handling error_handling ;
346
+ php_phongo_session_t * intern ;
337
347
338
348
intern = Z_SESSION_OBJ_P (getThis ());
339
349
SESSION_CHECK_LIVELINESS (intern , "getTransactionOptions" )
@@ -345,7 +355,7 @@ static PHP_METHOD(Session, getTransactionOptions)
345
355
}
346
356
zend_restore_error_handling (& error_handling );
347
357
348
- php_phongo_transaction_options_to_zval (mongoc_session_opts_get_transaction_opts ( intern -> client_session ) , return_value );
358
+ php_phongo_transaction_options_to_zval (intern -> client_session , return_value );
349
359
} /* }}} */
350
360
351
361
/* {{{ proto string MongoDB\Driver\Session::getTransactionState()
@@ -728,8 +738,7 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
728
738
}
729
739
730
740
if (intern -> client_session ) {
731
- const mongoc_session_opt_t * cs_opts ;
732
- cs_opts = mongoc_client_session_get_opts (intern -> client_session );
741
+ const mongoc_session_opt_t * cs_opts = mongoc_client_session_get_opts (intern -> client_session );
733
742
ADD_ASSOC_BOOL_EX (& retval , "causalConsistency" , mongoc_session_opts_get_causal_consistency (cs_opts ));
734
743
} else {
735
744
ADD_ASSOC_NULL_EX (& retval , "causalConsistency" );
@@ -776,10 +785,10 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
776
785
777
786
if (intern -> client_session ) {
778
787
const char * state = php_phongo_get_transaction_state_string (mongoc_client_session_get_transaction_state (intern -> client_session ));
779
-
788
+
780
789
if (!state ) {
781
790
/* Exception should already have been thrown */
782
- goto done ;
791
+ goto done ;
783
792
}
784
793
785
794
ADD_ASSOC_STRING (& retval , "transactionState" , state );
@@ -788,17 +797,9 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
788
797
}
789
798
790
799
if (intern -> client_session ) {
791
- mongoc_transaction_opt_t * txn_opts = mongoc_session_opts_get_transaction_opts (intern -> client_session );
792
-
793
- if (txn_opts ) {
794
-
795
- zval transaction ;
796
-
797
- php_phongo_transaction_options_to_zval (txn_opts , & transaction );
798
- ADD_ASSOC_ZVAL_EX (& retval , "transactionOptions" , & transaction );
799
- } else {
800
- ADD_ASSOC_NULL_EX (& retval , "transactionOptions" );
801
- }
800
+ zval txn_opts ;
801
+ php_phongo_transaction_options_to_zval (intern -> client_session , & txn_opts );
802
+ ADD_ASSOC_ZVAL_EX (& retval , "transactionOptions" , & txn_opts );
802
803
} else {
803
804
ADD_ASSOC_NULL_EX (& retval , "transactionOptions" );
804
805
}
0 commit comments