Skip to content

Commit b17d202

Browse files
committed
Merge pull request #227
2 parents d4a6802 + d9674b5 commit b17d202

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

php_phongo.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,41 @@ void php_phongo_populate_default_ssl_ctx(php_stream_context *ctx, zval *driverOp
16341634
#undef SET_STRING_CTX
16351635
} /* }}} */
16361636

1637+
static bool php_phongo_apply_rc_options_to_client(mongoc_client_t *client, bson_t *options TSRMLS_DC) /* {{{ */
1638+
{
1639+
bson_iter_t iter;
1640+
mongoc_read_concern_t *new_rc;
1641+
const mongoc_read_concern_t *old_rc;
1642+
1643+
if (!(old_rc = mongoc_client_get_read_concern(client))) {
1644+
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "Client does not have a read concern");
1645+
1646+
return false;
1647+
}
1648+
1649+
/* Return early if there are no options to apply */
1650+
if (bson_empty0(options)) {
1651+
return true;
1652+
}
1653+
1654+
if (!bson_iter_init_find_case(&iter, options, "readconcernlevel")) {
1655+
return true;
1656+
}
1657+
1658+
new_rc = mongoc_read_concern_copy(old_rc);
1659+
1660+
if (bson_iter_init_find_case(&iter, options, "readconcernlevel") && BSON_ITER_HOLDS_UTF8(&iter)) {
1661+
const char *str = bson_iter_utf8(&iter, NULL);
1662+
1663+
mongoc_read_concern_set_level(new_rc, str);
1664+
}
1665+
1666+
mongoc_client_set_read_concern(client, new_rc);
1667+
mongoc_read_concern_destroy(new_rc);
1668+
1669+
return true;
1670+
} /* }}} */
1671+
16371672
static bool php_phongo_apply_rp_options_to_client(mongoc_client_t *client, bson_t *options TSRMLS_DC) /* {{{ */
16381673
{
16391674
bson_iter_t iter;
@@ -1956,7 +1991,8 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
19561991
return false;
19571992
}
19581993

1959-
if (!php_phongo_apply_rp_options_to_client(manager->client, bson_options TSRMLS_CC) ||
1994+
if (!php_phongo_apply_rc_options_to_client(manager->client, bson_options TSRMLS_CC) ||
1995+
!php_phongo_apply_rp_options_to_client(manager->client, bson_options TSRMLS_CC) ||
19601996
!php_phongo_apply_wc_options_to_client(manager->client, bson_options TSRMLS_CC)) {
19611997
/* Exception should already have been thrown */
19621998
return false;

tests/manager/manager-getreadconcern-001.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ $tests = [
1111
[STANDALONE . '/?readconcernlevel=local', []],
1212
[STANDALONE . '/?readconcernlevel=majority', []],
1313
[STANDALONE . '/?readconcernlevel=not-yet-supported', []],
14+
[STANDALONE, ['readconcernlevel' => 'local']],
15+
[STANDALONE, ['readconcernlevel' => 'majority']],
16+
[STANDALONE, ['readconcernlevel' => 'not-yet-supported']],
17+
[STANDALONE . '/?readconcernlevel=local', ['readconcernlevel' => 'majority']],
1418
];
1519

1620
foreach ($tests as $i => $test) {
@@ -43,4 +47,20 @@ object(MongoDB\Driver\ReadConcern)#%d (%d) {
4347
["level"]=>
4448
string(17) "not-yet-supported"
4549
}
50+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
51+
["level"]=>
52+
string(5) "local"
53+
}
54+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
55+
["level"]=>
56+
string(8) "majority"
57+
}
58+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
59+
["level"]=>
60+
string(17) "not-yet-supported"
61+
}
62+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
63+
["level"]=>
64+
string(8) "majority"
65+
}
4666
===DONE===

0 commit comments

Comments
 (0)