@@ -100,10 +100,6 @@ zend_class_entry* phongo_exception_from_phongo_domain(php_phongo_error_domain_t
100
100
return php_phongo_runtimeexception_ce ;
101
101
case PHONGO_ERROR_WRITE_FAILED :
102
102
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 ;
107
103
case PHONGO_ERROR_CONNECTION_FAILED :
108
104
return php_phongo_connectionexception_ce ;
109
105
}
@@ -501,93 +497,6 @@ mongoc_bulk_operation_t *phongo_bulkwrite_init(zend_bool ordered) { /* {{{ */
501
497
return mongoc_bulk_operation_new (ordered );
502
498
} /* }}} */
503
499
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
-
591
500
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 ) /* {{{ */
592
501
{
593
502
bson_error_t error ;
@@ -1968,82 +1877,6 @@ void php_phongo_new_regex_from_regex_and_options(zval *object, const char *patte
1968
1877
intern -> flags = estrndup (flags , intern -> flags_len );
1969
1878
} /* }}} */
1970
1879
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
-
2047
1880
static void php_phongo_cursor_free_current (php_phongo_cursor_t * cursor ) /* {{{ */
2048
1881
{
2049
1882
if (cursor -> visitor_data .zchild ) {
@@ -2371,7 +2204,6 @@ PHP_MINIT_FUNCTION(mongodb)
2371
2204
PHP_MINIT (AuthenticationException )(INIT_FUNC_ARGS_PASSTHRU );
2372
2205
PHP_MINIT (SSLConnectionException )(INIT_FUNC_ARGS_PASSTHRU );
2373
2206
PHP_MINIT (WriteException )(INIT_FUNC_ARGS_PASSTHRU );
2374
- PHP_MINIT (WriteConcernException )(INIT_FUNC_ARGS_PASSTHRU );
2375
2207
PHP_MINIT (BulkWriteException )(INIT_FUNC_ARGS_PASSTHRU );
2376
2208
PHP_MINIT (ExecutionTimeoutException )(INIT_FUNC_ARGS_PASSTHRU );
2377
2209
PHP_MINIT (ConnectionTimeoutException )(INIT_FUNC_ARGS_PASSTHRU );
0 commit comments