Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ $w = MongoDB\Driver\WriteConcern::MAJORITY;
* I have an application to run! */
$wtimeout = 1000;

/* No need to journal or fsync (are infact discouraged in general) */
$journal = $fsync = false;

/* Construct the WriteConcern object from our options */
$wc = new MongoDB\Driver\WriteConcern($w, $wtimeout, $journal, $fsync);
$wc = new MongoDB\Driver\WriteConcern($w, $wtimeout);


/* We prefer to read from the secondary, but are OK to read from the primary
Expand Down
8 changes: 2 additions & 6 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t
const char *wtag = mongoc_write_concern_get_wtag(write_concern);
const int32_t w = mongoc_write_concern_get_w(write_concern);

array_init_size(retval, 5);
array_init_size(retval, 4);

if (wtag) {
add_assoc_string_ex(retval, ZEND_STRS("w"), (char *)wtag, 1);
Expand All @@ -1432,11 +1432,7 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t

add_assoc_bool_ex(retval, ZEND_STRS("wmajority"), mongoc_write_concern_get_wmajority(write_concern));
add_assoc_long_ex(retval, ZEND_STRS("wtimeout"), mongoc_write_concern_get_wtimeout(write_concern));
if (write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) {
add_assoc_bool_ex(retval, ZEND_STRS("fsync"), mongoc_write_concern_get_fsync(write_concern));
} else {
add_assoc_null_ex(retval, ZEND_STRS("fsync"));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update the array_init_size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍

if (write_concern->journal != MONGOC_WRITE_CONCERN_JOURNAL_DEFAULT) {
add_assoc_bool_ex(retval, ZEND_STRS("journal"), mongoc_write_concern_get_journal(write_concern));
} else {
Expand Down
47 changes: 6 additions & 41 deletions src/MongoDB/WriteConcern.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,22 @@ PHONGO_API zend_class_entry *php_phongo_writeconcern_ce;

zend_object_handlers php_phongo_handler_writeconcern;

/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(integer|string $w[, integer $wtimeout[, boolean $journal[, boolean $fsync]]])
/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(integer|string $w[, integer $wtimeout[, boolean $journal]])
Constructs a new WriteConcern */
PHP_METHOD(WriteConcern, __construct)
{
php_phongo_writeconcern_t *intern;
zend_error_handling error_handling;
zval *w;
zval *w, *journal;
long wtimeout = 0;
zend_bool journal = 0;
zend_bool journal_is_null = 0;
zend_bool fsync = 0;
zend_bool fsync_is_null = 0;

(void)return_value; (void)return_value_ptr; (void)return_value_used;


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

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lb!b!", &w, &wtimeout, &journal, &journal_is_null, &fsync, &fsync_is_null) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lz", &w, &wtimeout, &journal) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
Expand All @@ -93,14 +89,9 @@ PHP_METHOD(WriteConcern, __construct)
}

switch(ZEND_NUM_ARGS()) {
case 4:
if (!fsync_is_null) {
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
}
/* fallthrough */
case 3:
if (!journal_is_null) {
mongoc_write_concern_set_journal(intern->write_concern, journal);
if (Z_TYPE_P(journal) != IS_NULL) {
mongoc_write_concern_set_journal(intern->write_concern, Z_BVAL_P(journal));
}
/* fallthrough */
case 2:
Expand Down Expand Up @@ -184,37 +175,15 @@ PHP_METHOD(WriteConcern, getJournal)
}
/* }}} */

/* {{{ proto null|boolean WriteConcern::getFsync()
Returns the WriteConcern "fsync" option */
PHP_METHOD(WriteConcern, getFsync)
{
php_phongo_writeconcern_t *intern;
(void)return_value_ptr; (void)return_value_used;

intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC);

if (zend_parse_parameters_none() == FAILURE) {
return;
}

if (intern->write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) {
RETURN_BOOL(mongoc_write_concern_get_fsync(intern->write_concern));
}

RETURN_NULL();
}
/* }}} */

/**
* Value object for write concern used in issuing write operations.
*/
/* {{{ MongoDB\Driver\WriteConcern */

ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern___construct, 0, 0, 1)
ZEND_ARG_INFO(0, wstring)
ZEND_ARG_INFO(0, w)
ZEND_ARG_INFO(0, wtimeout)
ZEND_ARG_INFO(0, journal)
ZEND_ARG_INFO(0, fsync)
ZEND_END_ARG_INFO();

ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_getW, 0, 0, 0)
Expand All @@ -226,15 +195,11 @@ ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_getJournal, 0, 0, 0)
ZEND_END_ARG_INFO();

ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_getFsync, 0, 0, 0)
ZEND_END_ARG_INFO();

static zend_function_entry php_phongo_writeconcern_me[] = {
PHP_ME(WriteConcern, __construct, ai_WriteConcern___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getW, ai_WriteConcern_getW, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getWtimeout, ai_WriteConcern_getWtimeout, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getJournal, ai_WriteConcern_getJournal, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getFsync, ai_WriteConcern_getFsync, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};

Expand Down
4 changes: 1 addition & 3 deletions tests/bulk/write-0002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
["server_id"]=>
int(1)
["write_concern"]=>
array(5) {
array(%d) {
["w"]=>
int(1)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
22 changes: 0 additions & 22 deletions tests/manager/manager-getwriteconcern-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -54,8 +52,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -66,8 +62,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -78,8 +72,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
Expand All @@ -90,8 +82,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
Expand All @@ -102,8 +92,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
bool(false)
}
Expand All @@ -114,8 +102,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -126,8 +112,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -138,8 +122,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -150,8 +132,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand All @@ -162,8 +142,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
2 changes: 0 additions & 2 deletions tests/replicaset/writeresult-getserver-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
2 changes: 0 additions & 2 deletions tests/server/server-executeBulkWrite-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
2 changes: 0 additions & 2 deletions tests/standalone/writeresult-isacknowledged-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
4 changes: 1 addition & 3 deletions tests/standalone/writeresult-isacknowledged-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(5) {
array(%d) {
["w"]=>
int(0)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
4 changes: 1 addition & 3 deletions tests/standalone/writeresult-isacknowledged-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(5) {
array(%d) {
["w"]=>
int(0)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
Expand Down
Loading