Skip to content

Commit 3929480

Browse files
authored
PHPC-2478: Implement API for bulkWrite command (#1790)
* PHPC-2495, PHPC-2490, PHPC-2491, PHPC-2492: BulkWriteCommand ctor and ops * PHPC-2494: BulkWriteCommandResult and BulkWriteCommandException It was possible to reuse WriteConcernError and WriteError with slight changes to their init functions. * Include missing header in WriteResult.h This was not necessary for compilation, but it makes the header internally consistent. * PHPC-2493: Manager and Server::executeBulkWriteCommand() * PHPC-2494: Handle null error fields in BulkWriteCommandResult Always return arrays for writeErrors and writeConcernErrors * PHPC-2494: Return writeErrors as an associative array * PHPC-2493: Revise error handling for mongoc_bulkwrite_execute * Consistent WriteError and WriteConcernError parsing for bulk write results * BulkWriteCommand tests * clang-format * Remove BulkWriteCommandResult::getServer() Per CDRIVER-5843, libmongoc does not consistently populate this field. It also isn't required by the spec, so omit it for now. * Check for _id extraction before appending insert * Regenerate BulkWriteCommandException arginfo * PHPC-2493: Relocate writeConcern option to executeBulkWriteCommand() * Parse sort option for replaceOne and updateOne * BulkWriteCommand::replaceOne() need not accept root-level arrays * Preserve empty documents for verbose results and error reply Result maps should only be null if verboseResults=false. Additionally, the error reply document can default to an empty document on error (as it is in libmongoc). * PHPC-2494: Relocate error fields to BulkWriteCommandException Revise the stubs to reflect that executeBulkWriteCommand() always returns a BulkWriteCommandResult. If the result is unacknowledged, that is reported via isAcknowledged() and other methods can throw, which is consistent with WriteResult for the legacy bulk write API. If the result is empty on error (i.e. no writes were successful), BulkWriteCommandException::$partialResult is left unset. * Throw BulkWriteCommandException directly for server errors This also ensures that BulkWriteCommandException uses the original server-side error code and message (if available) for top-level errors. * Check for empty error_reply instead of NULL mongoc_bulkwriteexception_errorreply() always returns an initialized document, but it may be empty. This ensures that an InvalidArgumentException is not unnecessarily proxied behind a BulkWriteCommandException.
1 parent d3a079f commit 3929480

File tree

53 files changed

+3365
-25
lines changed

Some content is hidden

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

53 files changed

+3365
-25
lines changed

config.m4

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ if test "$PHP_MONGODB" != "no"; then
167167
src/BSON/UTCDateTime.c \
168168
src/BSON/UTCDateTimeInterface.c \
169169
src/MongoDB/BulkWrite.c \
170+
src/MongoDB/BulkWriteCommand.c \
171+
src/MongoDB/BulkWriteCommandResult.c \
170172
src/MongoDB/ClientEncryption.c \
171173
src/MongoDB/Command.c \
172174
src/MongoDB/Cursor.c \
@@ -186,6 +188,7 @@ if test "$PHP_MONGODB" != "no"; then
186188
src/MongoDB/WriteResult.c \
187189
src/MongoDB/Exception/AuthenticationException.c \
188190
src/MongoDB/Exception/BulkWriteException.c \
191+
src/MongoDB/Exception/BulkWriteCommandException.c \
189192
src/MongoDB/Exception/CommandException.c \
190193
src/MongoDB/Exception/ConnectionException.c \
191194
src/MongoDB/Exception/ConnectionTimeoutException.c \

config.w32

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ if (PHP_MONGODB != "no") {
116116
EXTENSION("mongodb", "php_phongo.c", null, PHP_MONGODB_CFLAGS);
117117
MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_atomic.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_log.c phongo_util.c");
118118
MONGODB_ADD_SOURCES("/src/BSON", "Binary.c BinaryInterface.c Document.c Iterator.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c PackedArray.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c");
119-
MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c");
120-
MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c UnexpectedValueException.c");
119+
MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c BulkWriteCommand.c BulkWriteCommandResult.c ClientEncryption.c Command.c Cursor.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c");
120+
MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c BulkWriteCommandException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c UnexpectedValueException.c");
121121
MONGODB_ADD_SOURCES("/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c LogSubscriber.c SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c");
122122
MONGODB_ADD_SOURCES("/src/libmongoc/src/common/src", PHP_MONGODB_COMMON_SOURCES);
123123
MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/bson", PHP_MONGODB_BSON_SOURCES);

php_phongo.c

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
252252
php_phongo_cursor_interface_init_ce(INIT_FUNC_ARGS_PASSTHRU);
253253

254254
php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS_PASSTHRU);
255+
php_phongo_bulkwritecommand_init_ce(INIT_FUNC_ARGS_PASSTHRU);
256+
php_phongo_bulkwritecommandresult_init_ce(INIT_FUNC_ARGS_PASSTHRU);
255257
php_phongo_clientencryption_init_ce(INIT_FUNC_ARGS_PASSTHRU);
256258
php_phongo_command_init_ce(INIT_FUNC_ARGS_PASSTHRU);
257259
php_phongo_cursor_init_ce(INIT_FUNC_ARGS_PASSTHRU);
@@ -277,6 +279,7 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
277279

278280
php_phongo_authenticationexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
279281
php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
282+
php_phongo_bulkwritecommandexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
280283
php_phongo_commandexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
281284
php_phongo_connectiontimeoutexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);
282285
php_phongo_encryptionexception_init_ce(INIT_FUNC_ARGS_PASSTHRU);

0 commit comments

Comments
 (0)