Skip to content

Commit 3e83aa7

Browse files
authored
PHPLIB-297 Support maxTimeMS option for DropIndexes operation (#434)
* PHPLIB-297 Support maxTimeMS option for DropIndexes operation
1 parent 1af82a4 commit 3e83aa7

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

docs/includes/apiargs-MongoDBCollection-method-dropIndex-option.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
source:
2+
file: apiargs-common-option.yaml
3+
ref: maxTimeMS
4+
---
15
source:
26
file: apiargs-MongoDBCollection-common-option.yaml
37
ref: typeMap

docs/includes/apiargs-MongoDBCollection-method-dropIndexes-option.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
source:
2+
file: apiargs-common-option.yaml
3+
ref: maxTimeMS
4+
---
15
source:
26
file: apiargs-MongoDBCollection-common-option.yaml
37
ref: typeMap

src/Operation/DropIndexes.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class DropIndexes implements Executable
4545
*
4646
* Supported options:
4747
*
48+
* * maxTimeMS (integer): The maximum amount of time to allow the query to
49+
* run.
50+
*
4851
* * typeMap (array): Type map for BSON deserialization. This will be used
4952
* for the returned command result document.
5053
*
@@ -67,6 +70,10 @@ public function __construct($databaseName, $collectionName, $indexName, array $o
6770
throw new InvalidArgumentException('$indexName cannot be empty');
6871
}
6972

73+
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
74+
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
75+
}
76+
7077
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
7178
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
7279
}
@@ -121,6 +128,10 @@ private function createCommand()
121128
'index' => $this->indexName,
122129
];
123130

131+
if (isset($this->options['maxTimeMS'])) {
132+
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
133+
}
134+
124135
if (isset($this->options['writeConcern'])) {
125136
$cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']);
126137
}

tests/Operation/DropIndexesTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function provideInvalidConstructorOptions()
2727
{
2828
$options = [];
2929

30+
foreach ($this->getInvalidIntegerValues() as $value) {
31+
$options[][] = ['maxTimeMS' => $value];
32+
}
33+
3034
foreach ($this->getInvalidArrayValues() as $value) {
3135
$options[][] = ['typeMap' => $value];
3236
}

0 commit comments

Comments
 (0)