Skip to content

Commit 5de7c87

Browse files
committed
Merge pull request #1049
2 parents 3aecfdb + 09f83fa commit 5de7c87

File tree

5 files changed

+174
-7
lines changed

5 files changed

+174
-7
lines changed

config.m4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ if test "$PHP_MONGODB" != "no"; then
190190
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
191191
AC_MSG_CHECKING(for libbson)
192192
if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libbson-1.0; then
193-
if $PKG_CONFIG libbson-1.0 --atleast-version 1.15.0; then
193+
if $PKG_CONFIG libbson-1.0 --atleast-version 1.16.0; then
194194
PHP_MONGODB_BSON_CFLAGS=`$PKG_CONFIG libbson-1.0 --cflags`
195195
PHP_MONGODB_BSON_LIBS=`$PKG_CONFIG libbson-1.0 --libs`
196196
PHP_MONGODB_BSON_VERSION=`$PKG_CONFIG libbson-1.0 --modversion`
197197
AC_MSG_RESULT(version $PHP_MONGODB_BSON_VERSION found)
198198
else
199-
AC_MSG_ERROR(system libbson must be upgraded to version >= 1.15.0)
199+
AC_MSG_ERROR(system libbson must be upgraded to version >= 1.16.0)
200200
fi
201201
else
202202
AC_MSG_ERROR(pkgconfig and libbson must be installed)
@@ -214,13 +214,13 @@ if test "$PHP_MONGODB" != "no"; then
214214
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
215215
AC_MSG_CHECKING(for libmongoc)
216216
if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libmongoc-1.0; then
217-
if $PKG_CONFIG libmongoc-1.0 --atleast-version 1.15.0; then
217+
if $PKG_CONFIG libmongoc-1.0 --atleast-version 1.16.0; then
218218
PHP_MONGODB_MONGOC_CFLAGS=`$PKG_CONFIG libmongoc-1.0 --cflags`
219219
PHP_MONGODB_MONGOC_LIBS=`$PKG_CONFIG libmongoc-1.0 --libs`
220220
PHP_MONGODB_MONGOC_VERSION=`$PKG_CONFIG libmongoc-1.0 --modversion`
221221
AC_MSG_RESULT(version $PHP_MONGODB_MONGOC_VERSION found)
222222
else
223-
AC_MSG_ERROR(system libmongoc must be upgraded to version >= 1.15.0)
223+
AC_MSG_ERROR(system libmongoc must be upgraded to version >= 1.16.0)
224224
fi
225225
else
226226
AC_MSG_ERROR(pkgconfig and libmongoc must be installed)

src/LIBMONGOC_VERSION_CURRENT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.15.1
1+
1.16.0-20191029+gitce14000d77

src/MongoDB/Session.c

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,93 @@ static PHP_METHOD(Session, getServer)
256256

257257
/* For sessions without a pinned server, 0 is returned. */
258258
if (!server_id) {
259-
RETURN_NULL();
259+
RETURN_NULL();
260260
}
261261

262262
phongo_server_init(return_value, mongoc_client_session_get_client(intern->client_session), server_id TSRMLS_CC);
263263
} /* }}} */
264264

265+
/* {{{ proto array|null MongoDB\Driver\Session::getTransactionOptions()
266+
Returns options for the currently running transaction */
267+
static PHP_METHOD(Session, getTransactionOptions)
268+
{
269+
php_phongo_session_t* intern;
270+
mongoc_transaction_opt_t* opts;
271+
int64_t max_commit_time_ms;
272+
const mongoc_read_concern_t* read_concern;
273+
const mongoc_read_prefs_t* read_preference;
274+
const mongoc_write_concern_t* write_concern;
275+
276+
intern = Z_SESSION_OBJ_P(getThis());
277+
SESSION_CHECK_LIVELINESS(intern, "getTransactionOptions")
278+
279+
if (zend_parse_parameters_none() == FAILURE) {
280+
return;
281+
}
282+
283+
opts = mongoc_session_opts_get_transaction_opts(intern->client_session);
284+
285+
if (!opts) {
286+
return;
287+
}
288+
289+
max_commit_time_ms = mongoc_transaction_opts_get_max_commit_time_ms(opts);
290+
read_concern = mongoc_transaction_opts_get_read_concern(opts);
291+
read_preference = mongoc_transaction_opts_get_read_prefs(opts);
292+
write_concern = mongoc_transaction_opts_get_write_concern(opts);
293+
294+
array_init_size(return_value, 4);
295+
296+
if (max_commit_time_ms) {
297+
ADD_ASSOC_LONG_EX(return_value, "maxCommitTimeMS", max_commit_time_ms);
298+
}
299+
300+
if (!mongoc_read_concern_is_default(read_concern)) {
301+
#if PHP_VERSION_ID >= 70000
302+
zval zread_concern;
303+
304+
phongo_readconcern_init(&zread_concern, read_concern TSRMLS_CC);
305+
ADD_ASSOC_ZVAL_EX(return_value, "readConcern", &zread_concern);
306+
#else
307+
zval* zread_concern = NULL;
308+
MAKE_STD_ZVAL(zread_concern);
309+
310+
phongo_readconcern_init(zread_concern, read_concern TSRMLS_CC);
311+
ADD_ASSOC_ZVAL_EX(return_value, "readConcern", zread_concern);
312+
#endif
313+
}
314+
315+
if (read_preference) {
316+
#if PHP_VERSION_ID >= 70000
317+
zval zread_preference;
318+
319+
phongo_readpreference_init(&zread_preference, read_preference TSRMLS_CC);
320+
ADD_ASSOC_ZVAL_EX(return_value, "readPreference", &zread_preference);
321+
#else
322+
zval* zread_preference = NULL;
323+
MAKE_STD_ZVAL(zread_preference);
324+
325+
phongo_readpreference_init(zread_preference, read_preference TSRMLS_CC);
326+
ADD_ASSOC_ZVAL_EX(return_value, "readPreference", zread_preference);
327+
#endif
328+
}
329+
330+
if (!mongoc_write_concern_is_default(write_concern)) {
331+
#if PHP_VERSION_ID >= 70000
332+
zval zwrite_concern;
333+
334+
phongo_writeconcern_init(&zwrite_concern, write_concern TSRMLS_CC);
335+
ADD_ASSOC_ZVAL_EX(return_value, "writeConcern", &zwrite_concern);
336+
#else
337+
zval* zwrite_concern = NULL;
338+
MAKE_STD_ZVAL(zwrite_concern);
339+
340+
phongo_writeconcern_init(zwrite_concern, write_concern TSRMLS_CC);
341+
ADD_ASSOC_ZVAL_EX(return_value, "writeConcern", zwrite_concern);
342+
#endif
343+
}
344+
} /* }}} */
345+
265346
/* Creates a opts structure from an array optionally containing an RP, RC,
266347
* WC object, and/or maxCommitTimeMS int. Returns NULL if no options were found,
267348
* or there was an invalid option. If there was an invalid option or structure,
@@ -490,6 +571,7 @@ static zend_function_entry php_phongo_session_me[] = {
490571
PHP_ME(Session, getLogicalSessionId, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
491572
PHP_ME(Session, getOperationTime, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
492573
PHP_ME(Session, getServer, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
574+
PHP_ME(Session, getTransactionOptions, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
493575
PHP_ME(Session, isInTransaction, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
494576
PHP_ME(Session, startTransaction, ai_Session_startTransaction, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL)
495577
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_Session_void, ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)

src/libmongoc

Submodule libmongoc updated 96 files
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
--TEST--
2+
MongoDB\Driver\Session::getTransactionOptions()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto(); ?>
6+
<?php skip_if_server_version('<', '4.0'); ?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$manager = new MongoDB\Driver\Manager(URI);
12+
$session = $manager->startSession();
13+
14+
var_dump($session->getTransactionOptions());
15+
16+
$options = [
17+
['maxCommitTimeMS' => 0],
18+
['maxCommitTimeMS' => 1],
19+
['readConcern' => new \MongoDB\Driver\ReadConcern('majority')],
20+
['readPreference' => new \MongoDB\Driver\ReadPreference('primaryPreferred')],
21+
['writeConcern' => new \MongoDB\Driver\WriteConcern('majority')],
22+
];
23+
24+
foreach ($options as $test) {
25+
// Session no longer needs to be restarted once CDRIVER-3366 is fixed
26+
$session = $manager->startSession();
27+
28+
$session->startTransaction($test);
29+
30+
var_dump($session->getTransactionOptions());
31+
}
32+
33+
?>
34+
===DONE===
35+
<?php exit(0); ?>
36+
--EXPECTF--
37+
NULL
38+
array(1) {
39+
["readPreference"]=>
40+
object(MongoDB\Driver\ReadPreference)#%d (1) {
41+
["mode"]=>
42+
string(7) "primary"
43+
}
44+
}
45+
array(2) {
46+
["maxCommitTimeMS"]=>
47+
int(1)
48+
["readPreference"]=>
49+
object(MongoDB\Driver\ReadPreference)#%d (1) {
50+
["mode"]=>
51+
string(7) "primary"
52+
}
53+
}
54+
array(2) {
55+
["readConcern"]=>
56+
object(MongoDB\Driver\ReadConcern)#%d (1) {
57+
["level"]=>
58+
string(8) "majority"
59+
}
60+
["readPreference"]=>
61+
object(MongoDB\Driver\ReadPreference)#%d (1) {
62+
["mode"]=>
63+
string(7) "primary"
64+
}
65+
}
66+
array(1) {
67+
["readPreference"]=>
68+
object(MongoDB\Driver\ReadPreference)#%d (1) {
69+
["mode"]=>
70+
string(16) "primaryPreferred"
71+
}
72+
}
73+
array(2) {
74+
["readPreference"]=>
75+
object(MongoDB\Driver\ReadPreference)#%d (1) {
76+
["mode"]=>
77+
string(7) "primary"
78+
}
79+
["writeConcern"]=>
80+
object(MongoDB\Driver\WriteConcern)#%d (1) {
81+
["w"]=>
82+
string(8) "majority"
83+
}
84+
}
85+
===DONE===

0 commit comments

Comments
 (0)