-
Notifications
You must be signed in to change notification settings - Fork 209
PHPC-409: Compatibility updates for libmongoc 1.2.0-rc0 #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff3061d
4d6157f
3a91948
f420087
356ced1
5732362
98887ff
8250796
51a9ad7
31661a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,9 +512,10 @@ php_phongo_writeresult_t *phongo_writeresult_init(zval *return_value, mongoc_wri | |
SCP(nRemoved); | ||
SCP(nUpserted); | ||
|
||
bson_copy_to(&write_result->upserted, &writeresult->write_result.upserted); | ||
bson_copy_to(&write_result->writeConcernError, &writeresult->write_result.writeConcernError); | ||
bson_copy_to(&write_result->writeErrors, &writeresult->write_result.writeErrors); | ||
bson_copy_to(&write_result->upserted, &writeresult->write_result.upserted); | ||
SCP(n_writeConcernErrors); | ||
bson_copy_to(&write_result->writeConcernErrors, &writeresult->write_result.writeConcernErrors); | ||
bson_copy_to(&write_result->writeErrors, &writeresult->write_result.writeErrors); | ||
SCP(upsert_append_count); | ||
#undef SCP | ||
|
||
|
@@ -684,10 +685,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, mongoc | |
/* The Write failed */ | ||
if (!success) { | ||
/* The Command itself failed */ | ||
if ( | ||
bson_empty0(&writeresult->write_result.writeErrors) | ||
&& bson_empty0(&writeresult->write_result.writeConcernError) | ||
) { | ||
if (bson_empty0(&writeresult->write_result.writeErrors) && bson_empty0(&writeresult->write_result.writeConcernErrors)) { | ||
/* FIXME: Maybe we can look at write_result.error and not pass error at all? */ | ||
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC); | ||
} else { | ||
|
@@ -726,7 +724,9 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, const p | |
return false; | ||
} | ||
|
||
cursor->hint = server_id; | ||
if (server_id > 0) { | ||
cursor->hint = server_id; | ||
} | ||
if (!mongoc_cursor_next(cursor, &doc)) { | ||
bson_error_t error; | ||
|
||
|
@@ -757,7 +757,9 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, const bson_t | |
|
||
|
||
cursor = mongoc_client_command(client, db, MONGOC_QUERY_NONE, 0, 1, 0, command, NULL, read_preference); | ||
cursor->hint = server_id; | ||
if (server_id > 0) { | ||
cursor->hint = server_id; | ||
} | ||
|
||
if (!mongoc_cursor_next(cursor, &doc)) { | ||
bson_error_t error; | ||
|
@@ -821,7 +823,11 @@ void phongo_stream_destroy(mongoc_stream_t *stream_wrap) /* {{{ */ | |
{ | ||
php_phongo_stream_socket *base_stream = (php_phongo_stream_socket *)stream_wrap; | ||
|
||
MONGOC_DEBUG("Not destroying RSRC#%d", base_stream->stream->rsrc_id); | ||
if (base_stream->stream) { | ||
MONGOC_DEBUG("Not destroying RSRC#%d", base_stream->stream->rsrc_id); | ||
} else { | ||
MONGOC_DEBUG("Wrapped stream already destroyed"); | ||
} | ||
/* | ||
* DON'T DO ANYTHING TO THE INTERNAL base_stream->stream | ||
* The stream should not be closed during normal dtor -- as we want it to | ||
|
@@ -851,7 +857,14 @@ int phongo_stream_close(mongoc_stream_t *stream_wrap) /* {{{ */ | |
php_phongo_stream_socket *base_stream = (php_phongo_stream_socket *)stream_wrap; | ||
|
||
MONGOC_DEBUG("Closing RSRC#%d", base_stream->stream->rsrc_id); | ||
phongo_stream_destroy(stream_wrap); | ||
if (base_stream->stream) { | ||
TSRMLS_FETCH_FROM_CTX(base_stream->tsrm_ls); | ||
|
||
MONGOC_DEBUG("Destroying RSRC#%d", base_stream->stream->rsrc_id); | ||
php_stream_free(base_stream->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR); | ||
base_stream->stream = NULL; | ||
} | ||
|
||
return 0; | ||
} /* }}} */ | ||
|
||
|
@@ -2007,25 +2020,30 @@ bool php_phongo_writeresult_get_write_errors(php_phongo_writeresult_t *writeresu | |
} | ||
return false; | ||
} /* }}} */ | ||
|
||
bool php_phongo_writeresult_get_writeconcern_error(php_phongo_writeresult_t *writeresult, bson_error_t *error) /* {{{ */ | ||
{ | ||
const char *err = NULL; | ||
uint32_t code = 0; | ||
bson_iter_t iter; | ||
bson_iter_t citer; | ||
|
||
if (!bson_empty0(&writeresult->write_result.writeConcernError)) { | ||
bson_iter_t iter; | ||
|
||
if (bson_iter_init_find(&iter, &writeresult->write_result.writeConcernError, "code") && BSON_ITER_HOLDS_INT32(&iter)) { | ||
code = bson_iter_int32(&iter); | ||
} | ||
if (bson_iter_init_find(&iter, &writeresult->write_result.writeConcernError, "errmsg") && BSON_ITER_HOLDS_UTF8(&iter)) { | ||
err = bson_iter_utf8(&iter, NULL); | ||
if (!bson_empty0 (&writeresult->write_result.writeConcernErrors) && | ||
bson_iter_init (&iter, &writeresult->write_result.writeConcernErrors) && | ||
bson_iter_next (&iter) && | ||
BSON_ITER_HOLDS_DOCUMENT (&iter) && | ||
bson_iter_recurse (&iter, &citer)) { | ||
while (bson_iter_next (&citer)) { | ||
if (BSON_ITER_IS_KEY (&citer, "errmsg")) { | ||
err = bson_iter_utf8 (&citer, NULL); | ||
} else if (BSON_ITER_IS_KEY (&citer, "code")) { | ||
code = bson_iter_int32 (&citer); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it matter that this will be the last writeConcernErrors (not the first as said in the crud spec)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would this be the last write concern error? This, and the code in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, so the 5 line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. I believe you originally wrote this for extracting the first write error. I just adapted it for the write concern. The @derickr pointed out that we don't have tests for this stuff, so I'm going to add some. |
||
} | ||
|
||
bson_set_error(error, PHONGO_ERROR_WRITECONCERN_FAILED, code, "%s", err); | ||
return true; | ||
} | ||
|
||
return false; | ||
} /* }}} */ | ||
zval* php_phongo_throw_write_errors(php_phongo_writeresult_t *wr TSRMLS_DC) /* {{{ */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--TEST-- | ||
Connect to MongoDB with using X509 retrieving username from certificate #002 | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("STANDALONE_X509"); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
function connect($dsn, $opts) { | ||
try { | ||
$manager = new MongoDB\Driver\Manager($dsn, array(), $opts); | ||
|
||
$bulk = new MongoDB\Driver\BulkWrite(); | ||
$bulk->insert(array("very" => "important")); | ||
$manager->executeBulkWrite(NS, $bulk); | ||
echo "Connected\n"; | ||
} catch(Exception $e) { | ||
echo get_class($e), ": ", $e->getMessage(), "\n"; | ||
} | ||
return $manager; | ||
|
||
} | ||
$SSL_DIR = realpath(__DIR__ . "/" . "./../../scripts/ssl/"); | ||
|
||
$opts = array( | ||
"peer_name" => "server", | ||
"verify_peer" => true, | ||
"verify_peer_name" => true, | ||
"allow_self_signed" => false, | ||
"cafile" => $SSL_DIR . "/ca.pem", /* Defaults to openssl.cafile */ | ||
"capath" => $SSL_DIR, /* Defaults to openssl.capath */ | ||
"local_cert" => $SSL_DIR . "/src/libmongoc/tests/certificates/client.pem", | ||
); | ||
$parsed = parse_url(STANDALONE_X509); | ||
$dsn = sprintf("mongodb://username@%s:%d/%s?ssl=true&authMechanism=MONGODB-X509", $parsed["host"], $parsed["port"], DATABASE_NAME); | ||
|
||
|
||
$m1 = connect($dsn, $opts); | ||
$m2 = connect($dsn, $opts); | ||
|
||
echo "Both should have failed with auth failure - without reusing previous stream\n"; | ||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
MongoDB\Driver\Exception\AuthenticationException: auth failed | ||
MongoDB\Driver\Exception\AuthenticationException: auth failed | ||
Both should have failed with auth failure - without reusing previous stream | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeDelete() write error | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
$manager->executeInsert(NS, ['x' => 1]); | ||
|
||
echo throws(function() use ($manager) { | ||
$manager->executeDelete(NS, ['$foo' => 1], ['limit' => 1]); | ||
}, 'MongoDB\Driver\Exception\WriteException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\WriteException | ||
unknown top level operator: $foo | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeDelete() write concern error | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS("REPLICASET"); CLEANUP(REPLICASET); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(REPLICASET); | ||
|
||
$manager->executeInsert(NS, ['x' => 1]); | ||
|
||
echo throws(function() use ($manager) { | ||
$manager->executeDelete(NS, ['x' => 1], ['limit' => 1], new MongoDB\Driver\WriteConcern(30)); | ||
}, 'MongoDB\Driver\Exception\WriteConcernException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\WriteConcernException | ||
Not enough data-bearing nodes | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeInsert() write error | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
echo throws(function() use ($manager) { | ||
$manager->executeInsert(NS, ['$foo' => 1]); | ||
}, 'MongoDB\Driver\Exception\WriteException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\WriteException | ||
Document can't have $ prefixed field names: $foo | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeInsert() write concern error | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS("REPLICASET"); CLEANUP(REPLICASET); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(REPLICASET); | ||
|
||
echo throws(function() use ($manager) { | ||
$manager->executeInsert(NS, ['x' => 1], new MongoDB\Driver\WriteConcern(30)); | ||
}, 'MongoDB\Driver\Exception\WriteConcernException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\WriteConcernException | ||
Not enough data-bearing nodes | ||
===DONE=== |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeUpdate() write error | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; CLEANUP(STANDALONE) ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
$manager->executeInsert(NS, ['x' => 1]); | ||
|
||
echo throws(function() use ($manager) { | ||
$manager->executeUpdate(NS, ['x' => 1], ['$foo' => 1]); | ||
}, 'MongoDB\Driver\Exception\WriteException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\WriteException | ||
Unknown modifier: $foo | ||
===DONE=== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct and will make #104 broken.
Please include all files. If the file was renamed, please use the new name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we also need the
mongoc-version-functions.c
added toMONGOC_SOURCES
(it was never included). I'll fix both.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. mongoc-version-functions.c is also a new file in the rc0 and needs to be included