Skip to content

Commit fa851df

Browse files
committed
PHPC-834: Add Read, ReadWrite and Write command execute methods (fixes crash)
1 parent ffe1fff commit fa851df

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

php_phongo.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, php_ph
621621
php_phongo_writeresult_t *writeresult;
622622
zval *zwriteConcern = NULL;
623623
const mongoc_write_concern_t *write_concern;
624+
bson_t *opts;
624625

625626
if (bulk_write->executed) {
626627
phongo_throw_exception(PHONGO_ERROR_WRITE_FAILED TSRMLS_CC, "BulkWrite objects may only be executed once and this instance has already been executed");
@@ -632,10 +633,12 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, php_ph
632633
return false;
633634
}
634635

636+
opts = bson_new();
637+
635638
/* FIXME: Legacy way of specifying the writeConcern option into this function */
636639
if (options && Z_TYPE_P(options) == IS_OBJECT && instanceof_function(Z_OBJCE_P(options), php_phongo_writeconcern_ce TSRMLS_CC)) {
637640
zwriteConcern = options;
638-
} else if (!phongo_execute_parse_options(client, server_id, options, PHONGO_COMMAND_WRITE, NULL, NULL, &zwriteConcern TSRMLS_CC)) {
641+
} else if (!phongo_execute_parse_options(client, server_id, options, PHONGO_COMMAND_WRITE, opts, NULL, &zwriteConcern TSRMLS_CC)) {
639642
return false;
640643
}
641644

@@ -724,6 +727,7 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
724727
char *collname;
725728
mongoc_collection_t *collection;
726729
zval *zreadPreference = NULL;
730+
bson_t *opts;
727731

728732
if (!phongo_split_namespace(namespace, &dbname, &collname)) {
729733
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s: %s", "Invalid namespace provided", namespace);
@@ -738,11 +742,13 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
738742
if (query->read_concern) {
739743
mongoc_collection_set_read_concern(collection, query->read_concern);
740744
}
745+
746+
opts = bson_new();
741747

742748
/* FIXME: Legacy way of specifying the readPreference option into this function */
743749
if (options && Z_TYPE_P(options) == IS_OBJECT && instanceof_function(Z_OBJCE_P(options), php_phongo_readpreference_ce TSRMLS_CC)) {
744750
zreadPreference = options;
745-
} else if (!phongo_execute_parse_options(client, server_id, options, PHONGO_COMMAND_READ, NULL, &zreadPreference, NULL TSRMLS_CC)) {
751+
} else if (!phongo_execute_parse_options(client, server_id, options, PHONGO_COMMAND_READ, opts, &zreadPreference, NULL TSRMLS_CC)) {
746752
return false;
747753
}
748754

0 commit comments

Comments
 (0)