Skip to content

Commit 5d16172

Browse files
committed
Merge pull request #125
2 parents 57cb6ac + 52dfd6b commit 5d16172

28 files changed

+46
-38
lines changed

php_phongo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void phongo_server_init (zval *return_value, mongoc
115115
void phongo_readpreference_init (zval *return_value, const mongoc_read_prefs_t *read_prefs TSRMLS_DC);
116116
void phongo_writeconcern_init (zval *return_value, const mongoc_write_concern_t *write_concern TSRMLS_DC);
117117
bool phongo_query_init (php_phongo_query_t *query, bson_t *filter, bson_t *options TSRMLS_DC);
118-
mongoc_bulk_operation_t* phongo_bulkwrite_init (zend_bool ordered);
118+
mongoc_bulk_operation_t* phongo_bulkwrite_init (zend_bool ordered);
119119
bool phongo_execute_write (mongoc_client_t *client, const char *namespace, mongoc_bulk_operation_t *bulk, const mongoc_write_concern_t *write_concern, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
120120
int phongo_execute_command (mongoc_client_t *client, const char *db, const bson_t *command, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
121121
int phongo_execute_query (mongoc_client_t *client, const char *namespace, const php_phongo_query_t *query, const mongoc_read_prefs_t *read_preference, int server_id, zval *return_value, int return_value_used TSRMLS_DC);

scripts/convert-mo-tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function clientOperation($phase, &$output) {
242242
$retval = <<< CODE
243243
try {
244244
\$wc = new MongoDB\\Driver\\WriteConcern($wc);
245-
\$result = \$manager->executeInsert("databaseName.collectionName", $doc, \$wc);
245+
\$result = \$manager->executeInsert("databaseName.collectionName", $doc, [], \$wc);
246246
if (\$result->getInsertedCount() == 1) {
247247
var_dump(array("ok" => 1));
248248
} else {

src/MongoDB/BulkWrite.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,29 @@ PHONGO_API zend_class_entry *php_phongo_bulkwrite_ce;
5151

5252
zend_object_handlers php_phongo_handler_bulkwrite;
5353

54-
/* {{{ proto MongoDB\Driver\BulkWrite BulkWrite::__construct(boolean $ordered)
54+
/* {{{ proto MongoDB\Driver\BulkWrite BulkWrite::__construct([array $options = array()])
5555
Constructs a new BulkWrite */
5656
PHP_METHOD(BulkWrite, __construct)
5757
{
5858
php_phongo_bulkwrite_t *intern;
59-
zend_error_handling error_handling;
60-
zend_bool ordered = 1;
59+
zend_error_handling error_handling;
60+
zval *options = NULL;
61+
zend_bool ordered = 1;
6162
(void)return_value_ptr; (void)return_value; (void)return_value_used;
6263

6364

6465
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
6566
intern = (php_phongo_bulkwrite_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
6667

67-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &ordered) == FAILURE) {
68+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &options) == FAILURE) {
6869
zend_restore_error_handling(&error_handling TSRMLS_CC);
6970
return;
7071
}
7172
zend_restore_error_handling(&error_handling TSRMLS_CC);
7273

74+
if (options && php_array_exists(options, "ordered")) {
75+
ordered = php_array_fetch_bool(options, "ordered");
76+
}
7377

7478
intern->bulk = phongo_bulkwrite_init(ordered);
7579
}
@@ -225,7 +229,7 @@ PHP_METHOD(BulkWrite, count)
225229
/* {{{ MongoDB\Driver\BulkWrite */
226230

227231
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite___construct, 0, 0, 0)
228-
ZEND_ARG_INFO(0, ordered)
232+
ZEND_ARG_ARRAY_INFO(0, options, 1)
229233
ZEND_END_ARG_INFO();
230234

231235
ZEND_BEGIN_ARG_INFO_EX(ai_BulkWrite_insert, 0, 0, 1)

src/MongoDB/Manager.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,33 @@ PHP_METHOD(Manager, executeBulkWrite)
180180
phongo_execute_write(intern->client, namespace, bulk->bulk, phongo_write_concern_from_zval(zwrite_concern TSRMLS_CC), -1, return_value, return_value_used TSRMLS_CC);
181181
}
182182
/* }}} */
183-
/* {{{ proto MongoDB\Driver\WriteResult Manager::executeInsert(string $namespace, array|object $document[, MongoDB\Driver\WriteConcern $writeConcern = null])
183+
/* {{{ proto MongoDB\Driver\WriteResult Manager::executeInsert(string $namespace, array|object $document[, array $insertOptions = array()[, MongoDB\Driver\WriteConcern $writeConcern = null]])
184184
Convenience method for single insert operation. */
185185
PHP_METHOD(Manager, executeInsert)
186186
{
187187
php_phongo_manager_t *intern;
188188
char *namespace;
189189
int namespace_len;
190190
zval *document;
191+
zval *insertOptions = NULL;
191192
zval *zwrite_concern = NULL;
192193
bson_t *bson;
193194
(void)return_value_ptr;
194195

195196

196197
intern = (php_phongo_manager_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
197198

198-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sA|O!", &namespace, &namespace_len, &document, &zwrite_concern, php_phongo_writeconcern_ce) == FAILURE) {
199+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sA|a!O!", &namespace, &namespace_len, &document, &insertOptions, &zwrite_concern, php_phongo_writeconcern_ce) == FAILURE) {
199200
return;
200201
}
201202

202203

203204
bson = bson_new();
204205
zval_to_bson(document, PHONGO_BSON_ADD_ODS|PHONGO_BSON_ADD_CHILD_ODS, bson, NULL TSRMLS_CC);
206+
207+
/* When PHPC-443 is implemented, insertOptions will be parsed for the
208+
* bypassDocumentValidation option; however, there's nothing to do now. */
209+
205210
phongo_execute_single_insert(intern->client, namespace, bson, phongo_write_concern_from_zval(zwrite_concern TSRMLS_CC), -1, return_value, return_value_used TSRMLS_CC);
206211
bson_clear(&bson);
207212
}
@@ -422,6 +427,7 @@ ZEND_END_ARG_INFO();
422427
ZEND_BEGIN_ARG_INFO_EX(ai_Manager_executeInsert, 0, 0, 2)
423428
ZEND_ARG_INFO(0, namespace)
424429
ZEND_ARG_INFO(0, document)
430+
ZEND_ARG_ARRAY_INFO(0, insertOptions, 1)
425431
ZEND_ARG_OBJ_INFO(0, writeConcern, MongoDB\\Driver\\WriteConcern, 1)
426432
ZEND_END_ARG_INFO();
427433

tests/bulk/write-0002.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ $manager = new MongoDB\Driver\Manager(STANDALONE);
1010

1111
$hannes = array("name" => "Hannes", "country" => "USA", "gender" => "male");
1212
$hayley = array("name" => "Hayley", "country" => "USA", "gender" => "female");
13-
$ordered = true;
1413

15-
$insertBulk = new \MongoDB\Driver\BulkWrite($ordered);
14+
$insertBulk = new \MongoDB\Driver\BulkWrite(['ordered' => true]);
1615
$hannes_id = $insertBulk->insert($hannes);
1716
$hayley_id = $insertBulk->insert($hayley);
1817

tests/cluster/rs/connection/read/primary-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ try {
9191
$wc = new MongoDB\Driver\WriteConcern(1);
9292
$result = $manager->executeInsert("databaseName.collectionName", array (
9393
'x' => 1,
94-
), $wc);
94+
), [], $wc);
9595
if ($result->getInsertedCount() == 1) {
9696
var_dump(array("ok" => 1));
9797
} else {

tests/cluster/rs/connection/read/primary-not-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ try {
9191
$wc = new MongoDB\Driver\WriteConcern(1);
9292
$result = $manager->executeInsert("databaseName.collectionName", array (
9393
'x' => 1,
94-
), $wc);
94+
), [], $wc);
9595
if ($result->getInsertedCount() == 1) {
9696
var_dump(array("ok" => 1));
9797
} else {

tests/cluster/rs/connection/write/primary-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ try {
9191
$wc = new MongoDB\Driver\WriteConcern(1);
9292
$result = $manager->executeInsert("databaseName.collectionName", array (
9393
'x' => 1,
94-
), $wc);
94+
), [], $wc);
9595
if ($result->getInsertedCount() == 1) {
9696
var_dump(array("ok" => 1));
9797
} else {

tests/cluster/rs/connection/write/primary-not-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ try {
9595
$wc = new MongoDB\Driver\WriteConcern(1);
9696
$result = $manager->executeInsert("databaseName.collectionName", array (
9797
'x' => 1,
98-
), $wc);
98+
), [], $wc);
9999
if ($result->getInsertedCount() == 1) {
100100
var_dump(array("ok" => 1));
101101
} else {

tests/cluster/rs/connection/write/primary-restarted.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ try {
9595
$wc = new MongoDB\Driver\WriteConcern(1);
9696
$result = $manager->executeInsert("databaseName.collectionName", array (
9797
'x' => 1,
98-
), $wc);
98+
), [], $wc);
9999
if ($result->getInsertedCount() == 1) {
100100
var_dump(array("ok" => 1));
101101
} else {
@@ -113,7 +113,7 @@ try {
113113
$wc = new MongoDB\Driver\WriteConcern(1);
114114
$result = $manager->executeInsert("databaseName.collectionName", array (
115115
'x' => 2,
116-
), $wc);
116+
), [], $wc);
117117
if ($result->getInsertedCount() == 1) {
118118
var_dump(array("ok" => 1));
119119
} else {

tests/cluster/rs/discovery/remove-all-add-members.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ try {
109109
$wc = new MongoDB\Driver\WriteConcern(1);
110110
$result = $manager->executeInsert("databaseName.collectionName", array (
111111
'x' => 1,
112-
), $wc);
112+
), [], $wc);
113113
if ($result->getInsertedCount() == 1) {
114114
var_dump(array("ok" => 1));
115115
} else {

tests/cluster/rs/discovery/stepped-down-primary-triggers-refresh.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ try {
109109
$wc = new MongoDB\Driver\WriteConcern(1);
110110
$result = $manager->executeInsert("databaseName.collectionName", array (
111111
'x' => 1,
112-
), $wc);
112+
), [], $wc);
113113
if ($result->getInsertedCount() == 1) {
114114
var_dump(array("ok" => 1));
115115
} else {

tests/cluster/sharded/connection/all-mongos-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ try {
8282
$wc = new MongoDB\Driver\WriteConcern(1);
8383
$result = $manager->executeInsert("databaseName.collectionName", array (
8484
'x' => 1,
85-
), $wc);
85+
), [], $wc);
8686
if ($result->getInsertedCount() == 1) {
8787
var_dump(array("ok" => 1));
8888
} else {

tests/cluster/sharded/connection/no-mongos-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ try {
8282
$wc = new MongoDB\Driver\WriteConcern(1);
8383
$result = $manager->executeInsert("databaseName.collectionName", array (
8484
'x' => 1,
85-
), $wc);
85+
), [], $wc);
8686
if ($result->getInsertedCount() == 1) {
8787
var_dump(array("ok" => 1));
8888
} else {

tests/cluster/single/connection/read/standalone-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ try {
6464
$wc = new MongoDB\Driver\WriteConcern(1);
6565
$result = $manager->executeInsert("databaseName.collectionName", array (
6666
'x' => 1,
67-
), $wc);
67+
), [], $wc);
6868
if ($result->getInsertedCount() == 1) {
6969
var_dump(array("ok" => 1));
7070
} else {

tests/cluster/single/connection/read/standalone-not-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ try {
6464
$wc = new MongoDB\Driver\WriteConcern(1);
6565
$result = $manager->executeInsert("databaseName.collectionName", array (
6666
'x' => 1,
67-
), $wc);
67+
), [], $wc);
6868
if ($result->getInsertedCount() == 1) {
6969
var_dump(array("ok" => 1));
7070
} else {

tests/cluster/single/connection/read/standalone-restarted.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ try {
6464
$wc = new MongoDB\Driver\WriteConcern(1);
6565
$result = $manager->executeInsert("databaseName.collectionName", array (
6666
'x' => 1,
67-
), $wc);
67+
), [], $wc);
6868
if ($result->getInsertedCount() == 1) {
6969
var_dump(array("ok" => 1));
7070
} else {

tests/cluster/single/connection/write/standalone-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ try {
6464
$wc = new MongoDB\Driver\WriteConcern(1);
6565
$result = $manager->executeInsert("databaseName.collectionName", array (
6666
'x' => 1,
67-
), $wc);
67+
), [], $wc);
6868
if ($result->getInsertedCount() == 1) {
6969
var_dump(array("ok" => 1));
7070
} else {

tests/cluster/single/connection/write/standalone-not-available.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ try {
6868
$wc = new MongoDB\Driver\WriteConcern(1);
6969
$result = $manager->executeInsert("databaseName.collectionName", array (
7070
'x' => 1,
71-
), $wc);
71+
), [], $wc);
7272
if ($result->getInsertedCount() == 1) {
7373
var_dump(array("ok" => 1));
7474
} else {

tests/cluster/single/connection/write/standalone-restarted.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ try {
6464
$wc = new MongoDB\Driver\WriteConcern(1);
6565
$result = $manager->executeInsert("databaseName.collectionName", array (
6666
'x' => 1,
67-
), $wc);
67+
), [], $wc);
6868
if ($result->getInsertedCount() == 1) {
6969
var_dump(array("ok" => 1));
7070
} else {
@@ -82,7 +82,7 @@ try {
8282
$wc = new MongoDB\Driver\WriteConcern(1);
8383
$result = $manager->executeInsert("databaseName.collectionName", array (
8484
'x' => 2,
85-
), $wc);
85+
), [], $wc);
8686
if ($result->getInsertedCount() == 1) {
8787
var_dump(array("ok" => 1));
8888
} else {
@@ -100,7 +100,7 @@ try {
100100
$wc = new MongoDB\Driver\WriteConcern(1);
101101
$result = $manager->executeInsert("databaseName.collectionName", array (
102102
'x' => 3,
103-
), $wc);
103+
), [], $wc);
104104
if ($result->getInsertedCount() == 1) {
105105
var_dump(array("ok" => 1));
106106
} else {

tests/manager/manager-executeBulkWrite-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . "/../utils/basic.inc";
88

99
$manager = new MongoDB\Driver\Manager(STANDALONE);
1010

11-
$bulk = new MongoDB\Driver\BulkWrite(true);
11+
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => true]);
1212
$bulk->insert(array('_id' => 1));
1313
$bulk->insert(array('_id' => 1));
1414
$bulk->insert(array('_id' => 2));

tests/manager/manager-executeBulkWrite-003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . "/../utils/basic.inc";
88

99
$manager = new MongoDB\Driver\Manager(STANDALONE);
1010

11-
$bulk = new MongoDB\Driver\BulkWrite(false);
11+
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
1212
$bulk->insert(array('_id' => 1));
1313
$bulk->insert(array('_id' => 1));
1414
$bulk->insert(array('_id' => 2));

tests/manager/manager-executeBulkWrite-004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . "/../utils/basic.inc";
88

99
$manager = new MongoDB\Driver\Manager(STANDALONE);
1010

11-
$bulk = new MongoDB\Driver\BulkWrite(false);
11+
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
1212
$bulk->update(array('x' => 'foo'), array('$set' => array('y' => 'foo')), array('upsert' => true));
1313
$bulk->update(array('x' => 'bar'), array('$set' => array('y' => 'bar')), array('upsert' => true));
1414
$bulk->update(array('x' => 'foo'), array('$set' => array('y' => 'bar')));

tests/manager/manager-executeInsert_error-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require_once __DIR__ . "/../utils/basic.inc";
1010
$manager = new MongoDB\Driver\Manager(REPLICASET);
1111

1212
echo throws(function() use ($manager) {
13-
$manager->executeInsert(NS, ['x' => 1], new MongoDB\Driver\WriteConcern(30));
13+
$manager->executeInsert(NS, ['x' => 1], [], new MongoDB\Driver\WriteConcern(30));
1414
}, 'MongoDB\Driver\Exception\WriteConcernException'), "\n";
1515

1616
?>

tests/replicaset/bug0155.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $wc = new MongoDB\Driver\WriteConcern("MultipleDC", 500);
1313

1414
$doc = array("example" => "document");
1515
try {
16-
$result = $manager->executeInsert("databaseName.collectionName", $doc, $wc);
16+
$result = $manager->executeInsert("databaseName.collectionName", $doc, [], $wc);
1717
} catch(MongoDB\Driver\Exception\WriteConcernException $e) {
1818
var_dump($e->getWriteResult()->getWriteConcernError());
1919
}

tests/standalone/write-error-001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ require_once __DIR__ . "/../utils/basic.inc";
99
$manager = new MongoDB\Driver\Manager(STANDALONE);
1010

1111
$hannes = array("name" => "Hannes", "country" => "USA", "gender" => "male");
12-
$ordered = true;
1312

14-
$bulk = new \MongoDB\Driver\BulkWrite($ordered);
13+
$bulk = new \MongoDB\Driver\BulkWrite(['ordered' => true]);
1514
$hannes_id = $bulk->insert($hannes);
1615

1716
$w = 2;

tests/standalone/writeresult-isacknowledged-003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require_once __DIR__ . "/../utils/basic.inc";
88

99
$manager = new MongoDB\Driver\Manager(STANDALONE);
1010

11-
$result = $manager->executeInsert(NS, array('x' => 2), new MongoDB\Driver\WriteConcern(0));
11+
$result = $manager->executeInsert(NS, array('x' => 2), [], new MongoDB\Driver\WriteConcern(0));
1212

1313
printf("WriteResult::isAcknowledged(): %s\n", $result->isAcknowledged() ? 'true' : 'false');
1414
var_dump($result);

tests/utils/tools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function LOAD($uri, $dbname = DATABASE_NAME, $collname = COLLECTION_NAME, $filen
101101
}
102102

103103
$manager = new MongoDB\Driver\Manager($uri);
104-
$bulk = new MongoDB\Driver\BulkWrite(false);
104+
$bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
105105

106106
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY));
107107

0 commit comments

Comments
 (0)