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

Draft
wants to merge 28 commits into
base: v2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
041e2bf
BulkWriteCommandBuilder
jmikola Mar 3, 2025
acd1204
Test against mongodb/mongo-php-driver#1790
jmikola Mar 4, 2025
942fe78
Psalm stubs for PHPC BulkWriteCommand classes
jmikola Mar 4, 2025
2aad228
BulkWriteCommandBuilder::withCollection returns a new instance
jmikola Mar 7, 2025
ed59ff7
Sanity check Manager association in BulkWriteCommandBuilder
jmikola Mar 7, 2025
e6421bf
Client::bulkWrite() and ClientBulkWrite operation
jmikola Mar 7, 2025
6a69240
Spec tests for Client::bulkWrite()
jmikola Mar 14, 2025
76e1dab
Revise error messages for readConcern and writeConcern in transactions
jmikola Mar 14, 2025
23c7dd8
BulkWriteCommandBuilder is final
jmikola Mar 14, 2025
7c6a707
Re-order BulkWriteCommandBuilder methods to satisfy PedantryTest
jmikola Mar 19, 2025
09556cc
Ignore order of non-public constructors in PedantryTest
jmikola Mar 19, 2025
00f80d3
Fix preparation of unacknowledged BulkWriteCommandResults
jmikola Mar 19, 2025
119cff4
Skip CSFLE namedKMS tests that require schema 1.18
jmikola Mar 19, 2025
648e851
Test Collection::getBuilderEncoder() and getCodec()
jmikola Mar 20, 2025
e116b0e
Default BulkWriteCommandBuilder options to empty arrays
jmikola Mar 22, 2025
f44f0f0
CRUD prose tests 3 and 4
jmikola Mar 22, 2025
e61a8cd
Update Psalm stubs for PHPC BulkWriteCommand API
jmikola Mar 31, 2025
e6d5397
CRUD prose tests 5-9
jmikola Mar 31, 2025
dc674a0
Rename BulkWriteCommandBuilder to ClientBulkWrite
jmikola Apr 1, 2025
c4c0deb
Server::executeBulkWriteCommand() always returns a BulkWriteCommandRe…
jmikola Apr 1, 2025
b7f5de7
Use dropCollection() helper to ensure collections are cleaned up
jmikola Apr 2, 2025
f7abab8
Prose test 11
jmikola Apr 2, 2025
74c5d51
Prose test 12
jmikola Apr 2, 2025
664b955
Prose test 13
jmikola Apr 2, 2025
1909275
Prose test 15
jmikola Apr 2, 2025
ec61231
Validate assigned $options property instead of ctor arg
jmikola Apr 4, 2025
436c2e7
Fix Psalm errors and update baseline
jmikola Apr 7, 2025
aa71e7b
phpcs fixes
jmikola Apr 7, 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
20 changes: 16 additions & 4 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.

5 changes: 4 additions & 1 deletion .evergreen/config/templates/build/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
- func: "compile extension"
# TODO: remove once 2.0.0 is released
vars:
EXTENSION_BRANCH: "v2.x"
# TODO: replace with "v2.x" once mongodb/mongo-php-driver#1790 is merged
# EXTENSION_BRANCH: "v2.x"
EXTENSION_REPO: "https://github.com/jmikola/mongo-php-driver.git"
EXTENSION_BRANCH: "2.x-bulkwrite"
- func: "upload extension"
# TODO: re-enable once 2.0.0 is released
# - name: "build-php-%phpVersion%-lowest"
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 @@ -15,7 +15,9 @@ env:
PHP_VERSION: "8.2"
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"
# TODO: change to "mongodb/[email protected]" once mongodb/mongo-php-driver#1790 is merged
# DRIVER_VERSION: "mongodb/[email protected]"
DRIVER_VERSION: "jmikola/[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 @@ -15,7 +15,9 @@ env:
PHP_VERSION: "8.2"
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"
# TODO: change to "mongodb/[email protected]" once mongodb/mongo-php-driver#1790 is merged
# DRIVER_VERSION: "mongodb/[email protected]"
DRIVER_VERSION: "jmikola/[email protected]"

jobs:
psalm:
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 @@ -21,7 +21,9 @@ env:
PHP_VERSION: "8.2"
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"
# TODO: change to "mongodb/[email protected]" once mongodb/mongo-php-driver#1790 is merged
# DRIVER_VERSION: "mongodb/[email protected]"
DRIVER_VERSION: "jmikola/[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 @@ -14,7 +14,9 @@ on:
env:
# TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/[email protected]"
# TODO: change to "mongodb/[email protected]" once mongodb/mongo-php-driver#1790 is merged
# DRIVER_VERSION: "mongodb/[email protected]"
DRIVER_VERSION: "jmikola/[email protected]"

jobs:
phpunit:
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
Loading