Skip to content

PHPLIB-1627: BulkWriteCommand API #1630

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

Merged
merged 38 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
83ef432
BulkWriteCommandBuilder
jmikola Mar 3, 2025
e9afb05
Test against mongodb/mongo-php-driver#1790
jmikola Mar 4, 2025
31ca089
Psalm stubs for PHPC BulkWriteCommand classes
jmikola Mar 4, 2025
6f95040
BulkWriteCommandBuilder::withCollection returns a new instance
jmikola Mar 7, 2025
a4a5045
Sanity check Manager association in BulkWriteCommandBuilder
jmikola Mar 7, 2025
56d76c7
Client::bulkWrite() and ClientBulkWrite operation
jmikola Mar 7, 2025
3e97082
Spec tests for Client::bulkWrite()
jmikola Mar 14, 2025
59417c2
Revise error messages for readConcern and writeConcern in transactions
jmikola Mar 14, 2025
8aa313e
BulkWriteCommandBuilder is final
jmikola Mar 14, 2025
3123d59
Re-order BulkWriteCommandBuilder methods to satisfy PedantryTest
jmikola Mar 19, 2025
cf40774
Ignore order of non-public constructors in PedantryTest
jmikola Mar 19, 2025
54da642
Fix preparation of unacknowledged BulkWriteCommandResults
jmikola Mar 19, 2025
41ee8b2
Skip CSFLE namedKMS tests that require schema 1.18
jmikola Mar 19, 2025
b1b6368
Test Collection::getBuilderEncoder() and getCodec()
jmikola Mar 20, 2025
b86eceb
Default BulkWriteCommandBuilder options to empty arrays
jmikola Mar 22, 2025
3163a7c
CRUD prose tests 3 and 4
jmikola Mar 22, 2025
36e08f1
Update Psalm stubs for PHPC BulkWriteCommand API
jmikola Mar 31, 2025
21af350
CRUD prose tests 5-9
jmikola Mar 31, 2025
0686263
Rename BulkWriteCommandBuilder to ClientBulkWrite
jmikola Apr 1, 2025
408ad40
Server::executeBulkWriteCommand() always returns a BulkWriteCommandRe…
jmikola Apr 1, 2025
bc45571
Use dropCollection() helper to ensure collections are cleaned up
jmikola Apr 2, 2025
7b150c8
Prose test 11
jmikola Apr 2, 2025
49a97e9
Prose test 12
jmikola Apr 2, 2025
e6a37b2
Prose test 13
jmikola Apr 2, 2025
e63f54b
Prose test 15
jmikola Apr 2, 2025
683da03
Validate assigned $options property instead of ctor arg
jmikola Apr 4, 2025
0d13135
Fix Psalm errors and update baseline
jmikola Apr 7, 2025
b3cd950
phpcs fixes
jmikola Apr 7, 2025
b448941
Test against v2.x
GromNaN May 9, 2025
ff9e162
Fix CS
GromNaN May 9, 2025
1befabe
Remove readonly qualifier on the class, PHP 8.2 would be required
GromNaN May 9, 2025
66ed280
Add NoDiscard attribute to 'withCollection' methods
GromNaN May 9, 2025
97a5121
Switch all EXTENSION_BRANCH versions
GromNaN May 9, 2025
3029042
Always build against v2.x
alcaeus May 12, 2025
f207cdb
Append CRYPT_SHARED_LIB_PATH to autoEncryptionOpts in tests
alcaeus May 12, 2025
bb34d7f
PHPLIB-1677: Assert unset BulkWriteException.partialResult in CRUD pr…
alcaeus May 12, 2025
72f5b6e
Use explicit null check
alcaeus May 12, 2025
2d97846
Require ext-mongodb 2.1
alcaeus May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions .evergreen/config/generated/build/build-extension.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions .evergreen/config/templates/build/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
vars:
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
# TODO: Remove vars to switch to latest stable version when 2.1.0 is releeased
vars:
EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
- name: "build-php-%phpVersion%-lowest"
tags: ["build", "php%phpVersion%", "lowest", "pr", "tag"]
Expand All @@ -14,7 +17,9 @@
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
vars:
EXTENSION_VERSION: "2.0.0"
# TODO: Switch to 2.1.0 when it is released
# EXTENSION_VERSION: "2.0.0"
EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
- name: "build-php-%phpVersion%-next-stable"
tags: ["build", "php%phpVersion%", "next-stable", "pr", "tag"]
Expand All @@ -24,7 +29,9 @@
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
vars:
EXTENSION_BRANCH: "v2.0"
# TODO: Switch to v2.1 when 2.1.0 is released
# EXTENSION_VERSION: "v2.1"
EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
- name: "build-php-%phpVersion%-next-minor"
tags: ["build", "php%phpVersion%", "next-minor"]
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ on:

env:
PHP_VERSION: "8.2"
DRIVER_VERSION: "stable"
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"

jobs:
phpcs:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ on:

env:
PHP_VERSION: "8.2"
DRIVER_VERSION: "stable"
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"

jobs:
diff:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ on:

env:
PHP_VERSION: "8.2"
DRIVER_VERSION: "stable"
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"

jobs:
psalm:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ on:
- "feature/*"

env:
DRIVER_VERSION: "stable"
# TODO: change to "stable" once 2.0.0 is released
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO: change to "stable" once 2.0.0 is released
# TODO: change to "stable" once 2.1.0 is released

# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"

jobs:
phpunit:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
],
"require": {
"php": "^8.1",
"ext-mongodb": "^2.0",
"ext-mongodb": "^2.1",
"composer-runtime-api": "^2.0",
"psr/log": "^1.1.4|^2|^3"
"psr/log": "^1.1.4|^2|^3",
"symfony/polyfill-php85": "^1.32"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
Expand Down
14 changes: 14 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@
<code><![CDATA[$pipeline]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/ClientBulkWrite.php">
<PossiblyInvalidArgument>
<code><![CDATA[$document]]></code>
<code><![CDATA[$replacement]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Codec/EncodeIfSupported.php">
<ArgumentTypeCoercion>
<code><![CDATA[$value]]></code>
Expand Down Expand Up @@ -545,6 +551,14 @@
<code><![CDATA[$args[2]]]></code>
</MixedOperand>
</file>
<file src="src/Operation/ClientBulkWriteCommand.php">
<MixedMethodCall>
<code><![CDATA[isInTransaction]]></code>
</MixedMethodCall>
<MixedReturnStatement>
<code><![CDATA[$server->executeBulkWriteCommand($this->bulkWriteCommand, $options)]]></code>
</MixedReturnStatement>
</file>
<file src="src/Operation/Count.php">
<MixedAssignment>
<code><![CDATA[$cmd[$option]]]></code>
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</projectFiles>

<stubs>
<file name="stubs/Driver/BulkWriteCommand.stub.php"/>
<file name="stubs/Driver/BulkWriteCommandException.stub.php"/>
<file name="stubs/Driver/BulkWriteCommandResult.stub.php"/>
<file name="stubs/Driver/Cursor.stub.php"/>
<file name="stubs/Driver/CursorInterface.stub.php"/>
<file name="stubs/Driver/WriteResult.stub.php"/>
Expand Down
29 changes: 29 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use MongoDB\Builder\BuilderEncoder;
use MongoDB\Builder\Pipeline;
use MongoDB\Codec\Encoder;
use MongoDB\Driver\BulkWriteCommand;
use MongoDB\Driver\BulkWriteCommandResult;
use MongoDB\Driver\ClientEncryption;
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
Expand All @@ -39,6 +41,7 @@
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\DatabaseInfo;
use MongoDB\Operation\ClientBulkWriteCommand;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabaseNames;
use MongoDB\Operation\ListDatabases;
Expand Down Expand Up @@ -189,6 +192,32 @@ final public function addSubscriber(Subscriber $subscriber): void
$this->manager->addSubscriber($subscriber);
}

/**
* Executes multiple write operations across multiple namespaces.
*
* @param BulkWriteCommand|ClientBulkWrite $bulk Assembled bulk write command or builder
* @param array $options Additional options
* @throws UnsupportedException if options are unsupported on the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
* @see ClientBulkWriteCommand::__construct() for supported options
*/
public function bulkWrite(BulkWriteCommand|ClientBulkWrite $bulk, array $options = []): BulkWriteCommandResult
{
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
$options['writeConcern'] = $this->writeConcern;
}

if ($bulk instanceof ClientBulkWrite) {
$bulk = $bulk->bulkWriteCommand;
}

$operation = new ClientBulkWriteCommand($bulk, $options);
$server = select_server_for_write($this->manager, $options);

return $operation->execute($server);
}

/**
* Returns a ClientEncryption instance for explicit encryption and decryption
*
Expand Down
Loading