Skip to content

Commit 8ed4ba8

Browse files
committed
Merge pull request #128
2 parents e156b23 + 70c092f commit 8ed4ba8

File tree

72 files changed

+669
-861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+669
-861
lines changed

config.m4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ if test "$MONGODB" != "no"; then
181181
src/MongoDB/Exception/ExecutionTimeoutException.c \
182182
src/MongoDB/Exception/ConnectionTimeoutException.c \
183183
src/MongoDB/Exception/WriteException.c \
184-
src/MongoDB/Exception/WriteConcernException.c \
185184
src/MongoDB/Exception/BulkWriteException.c \
186185
";
187186

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (PHP_MONGODB != "no") {
1010
ADD_SOURCES(configure_module_dirname + "/src", "bson.c", "mongodb");
1111
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Type.c Unserializable.c Serializable.c Persistable.c Binary.c Javascript.c MaxKey.c MinKey.c ObjectID.c Regex.c Timestamp.c UTCDateTime.c", "mongodb");
1212
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "Command.c Cursor.c CursorId.c Manager.c Query.c ReadPreference.c Server.c BulkWrite.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");
13-
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "Exception.c LogicException.c RuntimeException.c UnexpectedValueException.c InvalidArgumentException.c ConnectionException.c AuthenticationException.c SSLConnectionException.c ExecutionTimeoutException.c ConnectionTimeoutException.c WriteException.c WriteConcernException.c BulkWriteException.c", "mongodb");
13+
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "Exception.c LogicException.c RuntimeException.c UnexpectedValueException.c InvalidArgumentException.c ConnectionException.c AuthenticationException.c SSLConnectionException.c ExecutionTimeoutException.c ConnectionTimeoutException.c WriteException.c BulkWriteException.c", "mongodb");
1414
ADD_SOURCES(configure_module_dirname + "/src/contrib/", "php-ssl.c", "mongodb");
1515
ADD_SOURCES(configure_module_dirname + "/src/libbson/src/yajl", "yajl_version.c yajl.c yajl_encode.c yajl_lex.c yajl_parser.c yajl_buf.c yajl_tree.c yajl_alloc.c yajl_gen.c", "mongodb");
1616
ADD_SOURCES(configure_module_dirname + "/src/libbson/src/bson", "bcon.c bson.c bson-atomic.c bson-clock.c bson-context.c bson-error.c bson-iter.c bson-iso8601.c bson-json.c bson-keys.c bson-md5.c bson-memory.c bson-oid.c bson-reader.c bson-string.c bson-timegm.c bson-utf8.c bson-value.c bson-version-functions.c bson-writer.c", "mongodb");

php_phongo.c

Lines changed: 0 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ zend_class_entry* phongo_exception_from_phongo_domain(php_phongo_error_domain_t
100100
return php_phongo_runtimeexception_ce;
101101
case PHONGO_ERROR_WRITE_FAILED:
102102
return php_phongo_bulkwriteexception_ce;
103-
case PHONGO_ERROR_WRITE_SINGLE_FAILED:
104-
return php_phongo_writeexception_ce;
105-
case PHONGO_ERROR_WRITECONCERN_FAILED:
106-
return php_phongo_writeconcernexception_ce;
107103
case PHONGO_ERROR_CONNECTION_FAILED:
108104
return php_phongo_connectionexception_ce;
109105
}
@@ -501,93 +497,6 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
501497
return mongoc_bulk_operation_new(ordered);
502498
} /* }}} */
503499

504-
void phongo_unwrap_exception(bool retval, zval *return_value TSRMLS_DC)
505-
{
506-
if (!retval) {
507-
if (instanceof_function(Z_OBJCE_P(EG(exception)), php_phongo_bulkwriteexception_ce TSRMLS_CC)) {
508-
php_phongo_writeresult_t *wr = php_phongo_writeresult_get_from_bulkwriteexception(EG(exception) TSRMLS_CC);
509-
510-
/* Clear the BulkWriteException */
511-
zend_clear_exception(TSRMLS_C);
512-
513-
/* Throw WriteError and/or WriteConcernErrors */
514-
php_phongo_throw_write_errors(wr TSRMLS_CC);
515-
php_phongo_throw_write_concern_error(wr TSRMLS_CC);
516-
517-
if (instanceof_function(Z_OBJCE_P(EG(exception)), php_phongo_writeexception_ce TSRMLS_CC)) {
518-
zend_update_property(Z_OBJCE_P(EG(exception)), EG(exception), ZEND_STRL("writeResult"), return_value TSRMLS_CC);
519-
}
520-
}
521-
}
522-
}
523-
524-
int phongo_execute_single_insert(mongoc_client_t *client, const char *namespace, const bson_t *doc, const mongoc_write_concern_t *write_concern, int server_id, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
525-
{
526-
bool retval = false;
527-
mongoc_bulk_operation_t *bulk;
528-
529-
bulk = phongo_bulkwrite_init(true);
530-
mongoc_bulk_operation_insert(bulk, doc);
531-
532-
retval = phongo_execute_write(client, namespace, bulk, write_concern, server_id, return_value, return_value_used TSRMLS_CC);
533-
mongoc_bulk_operation_destroy(bulk);
534-
535-
phongo_unwrap_exception(retval, return_value TSRMLS_CC);
536-
return retval;
537-
} /* }}} */
538-
539-
int phongo_execute_single_update(mongoc_client_t *client, const char *namespace, const bson_t *query, const bson_t *update, const mongoc_write_concern_t *write_concern, int server_id, mongoc_update_flags_t flags, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
540-
{
541-
bool retval = false;
542-
mongoc_bulk_operation_t *bulk;
543-
544-
bulk = phongo_bulkwrite_init(true);
545-
if (flags & MONGOC_UPDATE_MULTI_UPDATE) {
546-
mongoc_bulk_operation_update(bulk, query, update, !!(flags & MONGOC_UPDATE_UPSERT));
547-
} else {
548-
bson_iter_t iter;
549-
zend_bool replaced = 0;
550-
551-
if (bson_iter_init(&iter, update)) {
552-
while (bson_iter_next (&iter)) {
553-
if (!strchr (bson_iter_key (&iter), '$')) {
554-
mongoc_bulk_operation_replace_one(bulk, query, update, !!(flags & MONGOC_UPDATE_UPSERT));
555-
replaced = 1;
556-
break;
557-
}
558-
}
559-
}
560-
561-
if (!replaced) {
562-
mongoc_bulk_operation_update_one(bulk, query, update, !!(flags & MONGOC_UPDATE_UPSERT));
563-
}
564-
}
565-
retval = phongo_execute_write(client, namespace, bulk, write_concern, server_id, return_value, return_value_used TSRMLS_CC);
566-
mongoc_bulk_operation_destroy(bulk);
567-
568-
phongo_unwrap_exception(retval, return_value TSRMLS_CC);
569-
return retval;
570-
} /* }}} */
571-
572-
int phongo_execute_single_delete(mongoc_client_t *client, const char *namespace, const bson_t *query, const mongoc_write_concern_t *write_concern, int server_id, mongoc_delete_flags_t flags, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
573-
{
574-
bool retval = false;
575-
mongoc_bulk_operation_t *bulk;
576-
577-
bulk = phongo_bulkwrite_init(true);
578-
if (flags & MONGOC_DELETE_SINGLE_REMOVE) {
579-
mongoc_bulk_operation_remove_one(bulk, query);
580-
} else {
581-
mongoc_bulk_operation_remove(bulk, query);
582-
}
583-
584-
retval = phongo_execute_write(client, namespace, bulk, write_concern, server_id, return_value, return_value_used TSRMLS_CC);
585-
mongoc_bulk_operation_destroy(bulk);
586-
587-
phongo_unwrap_exception(retval, return_value TSRMLS_CC);
588-
return retval;
589-
} /* }}} */
590-
591500
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) /* {{{ */
592501
{
593502
bson_error_t error;
@@ -1968,82 +1877,6 @@ void php_phongo_new_regex_from_regex_and_options(zval *object, const char *patte
19681877
intern->flags = estrndup(flags, intern->flags_len);
19691878
} /* }}} */
19701879

1971-
bool php_phongo_writeresult_get_write_errors(php_phongo_writeresult_t *writeresult, bson_error_t *error) /* {{{ */
1972-
{
1973-
const char *err = NULL;
1974-
uint32_t code = 0;
1975-
1976-
bson_iter_t iter;
1977-
bson_iter_t citer;
1978-
if (!bson_empty0 (&writeresult->write_result.writeErrors) &&
1979-
bson_iter_init (&iter, &writeresult->write_result.writeErrors) &&
1980-
bson_iter_next (&iter) &&
1981-
BSON_ITER_HOLDS_DOCUMENT (&iter) &&
1982-
bson_iter_recurse (&iter, &citer)) {
1983-
while (bson_iter_next (&citer)) {
1984-
if (BSON_ITER_IS_KEY (&citer, "errmsg")) {
1985-
err = bson_iter_utf8 (&citer, NULL);
1986-
} else if (BSON_ITER_IS_KEY (&citer, "code")) {
1987-
code = bson_iter_int32 (&citer);
1988-
}
1989-
}
1990-
1991-
bson_set_error(error, PHONGO_ERROR_WRITE_SINGLE_FAILED, code, "%s", err);
1992-
return true;
1993-
}
1994-
return false;
1995-
} /* }}} */
1996-
1997-
bool php_phongo_writeresult_get_writeconcern_error(php_phongo_writeresult_t *writeresult, bson_error_t *error) /* {{{ */
1998-
{
1999-
const char *err = NULL;
2000-
uint32_t code = 0;
2001-
bson_iter_t iter;
2002-
bson_iter_t citer;
2003-
2004-
if (!bson_empty0 (&writeresult->write_result.writeConcernErrors) &&
2005-
bson_iter_init (&iter, &writeresult->write_result.writeConcernErrors) &&
2006-
bson_iter_next (&iter) &&
2007-
BSON_ITER_HOLDS_DOCUMENT (&iter) &&
2008-
bson_iter_recurse (&iter, &citer)) {
2009-
while (bson_iter_next (&citer)) {
2010-
if (BSON_ITER_IS_KEY (&citer, "errmsg")) {
2011-
err = bson_iter_utf8 (&citer, NULL);
2012-
} else if (BSON_ITER_IS_KEY (&citer, "code")) {
2013-
code = bson_iter_int32 (&citer);
2014-
}
2015-
}
2016-
2017-
bson_set_error(error, PHONGO_ERROR_WRITECONCERN_FAILED, code, "%s", err);
2018-
return true;
2019-
}
2020-
return false;
2021-
} /* }}} */
2022-
zval* php_phongo_throw_write_errors(php_phongo_writeresult_t *wr TSRMLS_DC) /* {{{ */
2023-
{
2024-
bson_error_t error;
2025-
2026-
if (php_phongo_writeresult_get_write_errors(wr, &error)) {
2027-
return phongo_throw_exception(PHONGO_ERROR_WRITE_SINGLE_FAILED TSRMLS_CC, "%s", error.message);
2028-
}
2029-
return NULL;
2030-
} /* }}} */
2031-
zval* php_phongo_throw_write_concern_error(php_phongo_writeresult_t *wr TSRMLS_DC) /* {{{ */
2032-
{
2033-
bson_error_t error;
2034-
2035-
if (php_phongo_writeresult_get_writeconcern_error(wr, &error)) {
2036-
return phongo_throw_exception(PHONGO_ERROR_WRITECONCERN_FAILED TSRMLS_CC, "%s", error.message);
2037-
}
2038-
return NULL;
2039-
} /* }}} */
2040-
php_phongo_writeresult_t *php_phongo_writeresult_get_from_bulkwriteexception(zval *ex TSRMLS_DC) /* {{{ */
2041-
{
2042-
zval *wr = zend_read_property(php_phongo_bulkwriteexception_ce, ex, ZEND_STRL("writeResult"), 0 TSRMLS_CC);
2043-
2044-
return (php_phongo_writeresult_t *)zend_object_store_get_object(wr TSRMLS_CC);
2045-
} /* }}} */
2046-
20471880
static void php_phongo_cursor_free_current(php_phongo_cursor_t *cursor) /* {{{ */
20481881
{
20491882
if (cursor->visitor_data.zchild) {
@@ -2371,7 +2204,6 @@ PHP_MINIT_FUNCTION(mongodb)
23712204
PHP_MINIT(AuthenticationException)(INIT_FUNC_ARGS_PASSTHRU);
23722205
PHP_MINIT(SSLConnectionException)(INIT_FUNC_ARGS_PASSTHRU);
23732206
PHP_MINIT(WriteException)(INIT_FUNC_ARGS_PASSTHRU);
2374-
PHP_MINIT(WriteConcernException)(INIT_FUNC_ARGS_PASSTHRU);
23752207
PHP_MINIT(BulkWriteException)(INIT_FUNC_ARGS_PASSTHRU);
23762208
PHP_MINIT(ExecutionTimeoutException)(INIT_FUNC_ARGS_PASSTHRU);
23772209
PHP_MINIT(ConnectionTimeoutException)(INIT_FUNC_ARGS_PASSTHRU);

php_phongo.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ typedef enum {
7373
PHONGO_ERROR_RUNTIME = 2,
7474
PHONGO_ERROR_UNEXPECTED_VALUE = 8,
7575
PHONGO_ERROR_MONGOC_FAILED = 3,
76-
PHONGO_ERROR_WRITE_SINGLE_FAILED = 4,
7776
PHONGO_ERROR_WRITE_FAILED = 5,
78-
PHONGO_ERROR_WRITECONCERN_FAILED = 6,
7977
PHONGO_ERROR_CONNECTION_FAILED = 7,
8078
PHONGO_ERROR_LOGIC = 9
8179
} php_phongo_error_domain_t;
@@ -119,9 +117,6 @@ mongoc_bulk_operation_t* phongo_bulkwrite_init (zend_bool ordered);
119117
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);
120118
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);
121119
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);
122-
int phongo_execute_single_insert(mongoc_client_t *client, const char *namespace, const bson_t *doc, const mongoc_write_concern_t *write_concern, int server_id, zval *return_value, int return_value_used TSRMLS_DC);
123-
int phongo_execute_single_update(mongoc_client_t *client, const char *namespace, const bson_t *query, const bson_t *update, const mongoc_write_concern_t *write_concern, int server_id, mongoc_update_flags_t flags, zval *return_value, int return_value_used TSRMLS_DC);
124-
int phongo_execute_single_delete(mongoc_client_t *client, const char *namespace, const bson_t *query, const mongoc_write_concern_t *write_concern, int server_id, mongoc_delete_flags_t flags, zval *return_value, int return_value_used TSRMLS_DC);
125120

126121
mongoc_stream_t* phongo_stream_initiator (const mongoc_uri_t *uri, const mongoc_host_list_t *host, void *user_data, bson_error_t *error);
127122
const mongoc_read_prefs_t* phongo_read_preference_from_zval(zval *zread_preference TSRMLS_DC);
@@ -147,9 +142,6 @@ void php_phongo_new_javascript_from_javascript_and_scope(int init, zval *object,
147142
void php_phongo_new_binary_from_binary_and_type(zval *object, const char *data, size_t data_len, bson_subtype_t type TSRMLS_DC);
148143
void php_phongo_new_regex_from_regex_and_options(zval *object, const char *pattern, const char *flags TSRMLS_DC);
149144

150-
php_phongo_writeresult_t *php_phongo_writeresult_get_from_bulkwriteexception(zval *ex TSRMLS_DC);
151-
zval* php_phongo_throw_write_errors(php_phongo_writeresult_t *wr TSRMLS_DC);
152-
zval* php_phongo_throw_write_concern_error(php_phongo_writeresult_t *wr TSRMLS_DC);
153145
zend_bool phongo_writeerror_init(zval *return_value, bson_t *bson TSRMLS_DC);
154146
zend_bool phongo_writeconcernerror_init(zval *return_value, bson_t *bson TSRMLS_DC);
155147

php_phongo_classes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ extern PHONGO_API zend_class_entry *php_phongo_sslconnectionexception_ce;
186186
extern PHONGO_API zend_class_entry *php_phongo_executiontimeoutexception_ce;
187187
extern PHONGO_API zend_class_entry *php_phongo_connectiontimeoutexception_ce;
188188
extern PHONGO_API zend_class_entry *php_phongo_writeexception_ce;
189-
extern PHONGO_API zend_class_entry *php_phongo_writeconcernexception_ce;
190189
extern PHONGO_API zend_class_entry *php_phongo_bulkwriteexception_ce;
191190

192191
extern PHONGO_API zend_class_entry *php_phongo_type_ce;
@@ -235,7 +234,6 @@ PHP_MINIT_FUNCTION(SSLConnectionException);
235234
PHP_MINIT_FUNCTION(ExecutionTimeoutException);
236235
PHP_MINIT_FUNCTION(ConnectionTimeoutException);
237236
PHP_MINIT_FUNCTION(WriteException);
238-
PHP_MINIT_FUNCTION(WriteConcernException);
239237
PHP_MINIT_FUNCTION(BulkWriteException);
240238

241239
PHP_MINIT_FUNCTION(Type);

scripts/convert-mo-tests.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ 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+
\$bulk = new MongoDB\Driver\BulkWrite();
246+
\$bulk->insert($doc);
247+
\$result = \$manager->executeBulkWrite("databaseName.collectionName", \$bulk, \$wc);
246248
if (\$result->getInsertedCount() == 1) {
247249
var_dump(array("ok" => 1));
248250
} else {

src/MongoDB/Exception/WriteConcernException.c

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/MongoDB/Exception/WriteException.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ PHP_MINIT_FUNCTION(WriteException)
8989

9090
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Exception", "WriteException", php_phongo_writeexception_me);
9191
php_phongo_writeexception_ce = zend_register_internal_class_ex(&ce, php_phongo_runtimeexception_ce, NULL TSRMLS_CC);
92+
php_phongo_writeexception_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
9293

9394
zend_declare_property_null(php_phongo_writeexception_ce, ZEND_STRL("writeResult"), ZEND_ACC_PROTECTED TSRMLS_CC);
9495

0 commit comments

Comments
 (0)