|
27 | 27 |
|
28 | 28 | zend_class_entry *php_phongo_session_ce;
|
29 | 29 |
|
| 30 | +static bool php_phongo_session_get_timestamp_parts(zval *obj, uint32_t *timestamp, uint32_t *increment TSRMLS_DC) |
| 31 | +{ |
| 32 | + bool retval = false; |
| 33 | +#if PHP_VERSION_ID >= 70000 |
| 34 | + zval ztimestamp; |
| 35 | + zval zincrement; |
| 36 | + |
| 37 | + zend_call_method_with_0_params(obj, NULL, NULL, "getTimestamp", &ztimestamp); |
| 38 | + |
| 39 | + if (Z_ISUNDEF(ztimestamp) || EG(exception)) { |
| 40 | + goto cleanup; |
| 41 | + } |
| 42 | + |
| 43 | + zend_call_method_with_0_params(obj, NULL, NULL, "getIncrement", &zincrement); |
| 44 | + |
| 45 | + if (Z_ISUNDEF(zincrement) || EG(exception)) { |
| 46 | + goto cleanup; |
| 47 | + } |
| 48 | + |
| 49 | + *timestamp = Z_LVAL(ztimestamp); |
| 50 | + *increment = Z_LVAL(zincrement); |
| 51 | +#else |
| 52 | + zval *ztimestamp = NULL; |
| 53 | + zval *zincrement = NULL; |
| 54 | + |
| 55 | + zend_call_method_with_0_params(&obj, NULL, NULL, "getTimestamp", &ztimestamp); |
| 56 | + |
| 57 | + if (Z_ISUNDEF(ztimestamp) || EG(exception)) { |
| 58 | + goto cleanup; |
| 59 | + } |
| 60 | + |
| 61 | + zend_call_method_with_0_params(&obj, NULL, NULL, "getIncrement", &zincrement); |
| 62 | + |
| 63 | + if (Z_ISUNDEF(zincrement) || EG(exception)) { |
| 64 | + goto cleanup; |
| 65 | + } |
| 66 | + |
| 67 | + *timestamp = Z_LVAL_P(ztimestamp); |
| 68 | + *increment = Z_LVAL_P(zincrement); |
| 69 | +#endif |
| 70 | + |
| 71 | + retval = true; |
| 72 | + |
| 73 | +cleanup: |
| 74 | + if (!Z_ISUNDEF(ztimestamp)) { |
| 75 | + zval_ptr_dtor(&ztimestamp); |
| 76 | + } |
| 77 | + |
| 78 | + if (!Z_ISUNDEF(zincrement)) { |
| 79 | + zval_ptr_dtor(&zincrement); |
| 80 | + } |
| 81 | + |
| 82 | + return retval; |
| 83 | +} |
| 84 | + |
30 | 85 | /* {{{ proto void MongoDB\Driver\Session::advanceClusterTime(array|object $clusterTime)
|
31 | 86 | Advances the cluster time for this Session */
|
32 | 87 | static PHP_METHOD(Session, advanceClusterTime)
|
@@ -56,6 +111,30 @@ static PHP_METHOD(Session, advanceClusterTime)
|
56 | 111 | bson_destroy(&cluster_time);
|
57 | 112 | } /* }}} */
|
58 | 113 |
|
| 114 | +/* {{{ proto void MongoDB\Driver\Session::advanceOperationTime(MongoDB\BSON\Timestamp $timestamp) |
| 115 | + Advances the operation time for this Session */ |
| 116 | +static PHP_METHOD(Session, advanceOperationTime) |
| 117 | +{ |
| 118 | + php_phongo_session_t *intern; |
| 119 | + zval *ztimestamp; |
| 120 | + uint32_t timestamp = 0; |
| 121 | + uint32_t increment = 0; |
| 122 | + SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) |
| 123 | + |
| 124 | + |
| 125 | + intern = Z_SESSION_OBJ_P(getThis()); |
| 126 | + |
| 127 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &ztimestamp, php_phongo_timestamp_interface_ce) == FAILURE) { |
| 128 | + return; |
| 129 | + } |
| 130 | + |
| 131 | + if (!php_phongo_session_get_timestamp_parts(ztimestamp, ×tamp, &increment TSRMLS_CC)) { |
| 132 | + return; |
| 133 | + } |
| 134 | + |
| 135 | + mongoc_client_session_advance_operation_time(intern->client_session, timestamp, increment); |
| 136 | +} /* }}} */ |
| 137 | + |
59 | 138 | /* {{{ proto object|null MongoDB\Driver\Session::getClusterTime()
|
60 | 139 | Returns the cluster time for this Session */
|
61 | 140 | static PHP_METHOD(Session, getClusterTime)
|
@@ -123,18 +202,51 @@ static PHP_METHOD(Session, getLogicalSessionId)
|
123 | 202 | #endif
|
124 | 203 | } /* }}} */
|
125 | 204 |
|
| 205 | +/* {{{ proto MongoDB\BSON\Timestamp MongoDB\Driver\Session::getOperationTime() |
| 206 | + Returns the operation time for this Session */ |
| 207 | +static PHP_METHOD(Session, getOperationTime) |
| 208 | +{ |
| 209 | + php_phongo_session_t *intern; |
| 210 | + uint32_t timestamp, increment; |
| 211 | + SUPPRESS_UNUSED_WARNING(return_value_ptr) SUPPRESS_UNUSED_WARNING(return_value_used) |
| 212 | + |
| 213 | + |
| 214 | + intern = Z_SESSION_OBJ_P(getThis()); |
| 215 | + |
| 216 | + if (zend_parse_parameters_none() == FAILURE) { |
| 217 | + return; |
| 218 | + } |
| 219 | + |
| 220 | + mongoc_client_session_get_operation_time(intern->client_session, ×tamp, &increment); |
| 221 | + |
| 222 | + /* mongoc_client_session_get_operation_time() returns 0 for both parts if |
| 223 | + * the session has not been used. According to the causal consistency spec, |
| 224 | + * the operation time for an unused session is null. */ |
| 225 | + if (timestamp == 0 && increment == 0) { |
| 226 | + RETURN_NULL(); |
| 227 | + } |
| 228 | + |
| 229 | + php_phongo_new_timestamp_from_increment_and_timestamp(return_value, increment, timestamp TSRMLS_CC); |
| 230 | +} /* }}} */ |
| 231 | + |
126 | 232 | /* {{{ MongoDB\Driver\Session function entries */
|
127 | 233 | ZEND_BEGIN_ARG_INFO_EX(ai_Session_advanceClusterTime, 0, 0, 1)
|
128 | 234 | ZEND_ARG_INFO(0, clusterTime)
|
129 | 235 | ZEND_END_ARG_INFO()
|
130 | 236 |
|
| 237 | +ZEND_BEGIN_ARG_INFO_EX(ai_Session_advanceOperationTime, 0, 0, 1) |
| 238 | + ZEND_ARG_INFO(0, timestamp) |
| 239 | +ZEND_END_ARG_INFO() |
| 240 | + |
131 | 241 | ZEND_BEGIN_ARG_INFO_EX(ai_Session_void, 0, 0, 0)
|
132 | 242 | ZEND_END_ARG_INFO()
|
133 | 243 |
|
134 | 244 | static zend_function_entry php_phongo_session_me[] = {
|
135 | 245 | PHP_ME(Session, advanceClusterTime, ai_Session_advanceClusterTime, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
| 246 | + PHP_ME(Session, advanceOperationTime, ai_Session_advanceOperationTime, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) |
136 | 247 | PHP_ME(Session, getClusterTime, ai_Session_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
137 | 248 | PHP_ME(Session, getLogicalSessionId, ai_Session_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
| 249 | + PHP_ME(Session, getOperationTime, ai_Session_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) |
138 | 250 | ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_Session_void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
|
139 | 251 | ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_Session_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
|
140 | 252 | PHP_FE_END
|
@@ -243,6 +355,29 @@ static HashTable *php_phongo_session_get_debug_info(zval *object, int *is_temp T
|
243 | 355 | cs_opts = mongoc_client_session_get_opts(intern->client_session);
|
244 | 356 | ADD_ASSOC_BOOL_EX(&retval, "causalConsistency", mongoc_session_opts_get_causal_consistency(cs_opts));
|
245 | 357 |
|
| 358 | + { |
| 359 | + uint32_t timestamp, increment; |
| 360 | + |
| 361 | + mongoc_client_session_get_operation_time(intern->client_session, ×tamp, &increment); |
| 362 | + |
| 363 | + if (timestamp && increment) { |
| 364 | +#if PHP_VERSION_ID >= 70000 |
| 365 | + zval ztimestamp; |
| 366 | + |
| 367 | + php_phongo_new_timestamp_from_increment_and_timestamp(&ztimestamp, increment, timestamp TSRMLS_CC); |
| 368 | + ADD_ASSOC_ZVAL_EX(&retval, "operationTime", &ztimestamp); |
| 369 | +#else |
| 370 | + zval *ztimestamp; |
| 371 | + |
| 372 | + MAKE_STD_ZVAL(ztimestamp); |
| 373 | + php_phongo_new_timestamp_from_increment_and_timestamp(ztimestamp, increment, timestamp TSRMLS_CC); |
| 374 | + ADD_ASSOC_ZVAL_EX(&retval, "operationTime", ztimestamp); |
| 375 | +#endif |
| 376 | + } else { |
| 377 | + ADD_ASSOC_NULL_EX(&retval, "operationTime"); |
| 378 | + } |
| 379 | + } |
| 380 | + |
246 | 381 | return Z_ARRVAL(retval);
|
247 | 382 | } /* }}} */
|
248 | 383 | /* }}} */
|
|
0 commit comments