Skip to content

Commit 44a85b5

Browse files
committed
PHPC-427: Do not set WC journal/fsync to false for NULL args
1 parent 68d6b7c commit 44a85b5

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

src/MongoDB/WriteConcern.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ PHP_METHOD(WriteConcern, __construct)
5656
zval *w;
5757
long wtimeout = 0;
5858
zend_bool journal = 0;
59+
zend_bool journal_is_null = 0;
5960
zend_bool fsync = 0;
61+
zend_bool fsync_is_null = 0;
6062

6163
(void)return_value; (void)return_value_ptr; (void)return_value_used;
6264

6365

6466
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
6567
intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
6668

67-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lbb", &w, &wtimeout, &journal, &fsync) == FAILURE) {
69+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lb!b!", &w, &wtimeout, &journal, &journal_is_null, &fsync, &fsync_is_null) == FAILURE) {
6870
zend_restore_error_handling(&error_handling TSRMLS_CC);
6971
return;
7072
}
@@ -92,10 +94,14 @@ PHP_METHOD(WriteConcern, __construct)
9294

9395
switch(ZEND_NUM_ARGS()) {
9496
case 4:
95-
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
97+
if (!fsync_is_null) {
98+
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
99+
}
96100
/* fallthrough */
97101
case 3:
98-
mongoc_write_concern_set_journal(intern->write_concern, journal);
102+
if (!journal_is_null) {
103+
mongoc_write_concern_set_journal(intern->write_concern, journal);
104+
}
99105
/* fallthrough */
100106
case 2:
101107
if (wtimeout < 0) {

tests/writeConcern/writeconcern-ctor-001.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var_dump(new MongoDB\Driver\WriteConcern("string", 7000, true, true));
2424
var_dump(new MongoDB\Driver\WriteConcern("string", 8000, true, false));
2525
var_dump(new MongoDB\Driver\WriteConcern("string", 9000, false, true));
2626

27+
var_dump(new MongoDB\Driver\WriteConcern("string", 10000, null));
28+
var_dump(new MongoDB\Driver\WriteConcern("string", 11000, null, true));
29+
var_dump(new MongoDB\Driver\WriteConcern("string", 12000, true, null));
30+
2731
?>
2832
===DONE===
2933
<?php exit(0); ?>
@@ -172,4 +176,40 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
172176
["journal"]=>
173177
bool(false)
174178
}
179+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
180+
["w"]=>
181+
string(6) "string"
182+
["wmajority"]=>
183+
bool(false)
184+
["wtimeout"]=>
185+
int(10000)
186+
["fsync"]=>
187+
NULL
188+
["journal"]=>
189+
NULL
190+
}
191+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
192+
["w"]=>
193+
string(6) "string"
194+
["wmajority"]=>
195+
bool(false)
196+
["wtimeout"]=>
197+
int(11000)
198+
["fsync"]=>
199+
bool(true)
200+
["journal"]=>
201+
NULL
202+
}
203+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
204+
["w"]=>
205+
string(6) "string"
206+
["wmajority"]=>
207+
bool(false)
208+
["wtimeout"]=>
209+
int(12000)
210+
["fsync"]=>
211+
NULL
212+
["journal"]=>
213+
bool(true)
214+
}
175215
===DONE===

tests/writeConcern/writeconcern-getfsync-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ bool(true)
3131
bool(false)
3232
bool(true)
3333
bool(false)
34-
bool(false)
34+
NULL
3535
NULL
3636
===DONE===

tests/writeConcern/writeconcern-getjournal-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ bool(true)
3131
bool(false)
3232
bool(true)
3333
bool(false)
34-
bool(false)
34+
NULL
3535
NULL
3636
===DONE===

0 commit comments

Comments
 (0)