Skip to content

Commit

Permalink
PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIn…
Browse files Browse the repository at this point in the history
…dexId options (#1478)

* PHPLIB-1546: Remove CreateCollection flags option and related constants

* PHPLIB-1159: Remove CreateCollection autoIndexId option
  • Loading branch information
jmikola authored Oct 9, 2024
1 parent 25a196e commit d8c5d09
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 46 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ UPGRADE FROM 1.x to 2.0
* `MongoDB\Model\IndexInfoIterator`
* `MongoDB\Model\IndexInfoIteratorIterator`
* `MongoDB\Operation\Executable`
* The `flags` and `autoIndexId` options for
`MongoDB\Database::createCollection()` have been removed. Additionally, the
`USE_POWER_OF_2_SIZES` and `NO_PADDING` constants in
`MongoDB\Operation\CreateCollection` have been removed.

Operations with no result
-------------------------
Expand Down
33 changes: 1 addition & 32 deletions src/Operation/CreateCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
use function is_string;
use function MongoDB\is_document;
use function MongoDB\is_pipeline;
use function trigger_error;

use const E_USER_DEPRECATED;

/**
* Operation for the create command.
Expand All @@ -42,22 +39,11 @@
*/
final class CreateCollection
{
public const USE_POWER_OF_2_SIZES = 1;
public const NO_PADDING = 2;

/**
* Constructs a create command.
*
* Supported options:
*
* * autoIndexId (boolean): Specify false to disable the automatic creation
* of an index on the _id field. For replica sets, this option cannot be
* false. The default is true.
*
* This option has been deprecated since MongoDB 3.2. As of MongoDB 4.0,
* this option cannot be false when creating a replicated collection
* (i.e. a collection outside of the local database in any mongod mode).
*
* * capped (boolean): Specify true to create a capped collection. If set,
* the size option must also be specified. The default is false.
*
Expand All @@ -83,11 +69,6 @@ final class CreateCollection
*
* This is not supported for servers versions < 5.0.
*
* * flags (integer): Options for the MMAPv1 storage engine only. Must be a
* bitwise combination CreateCollection::USE_POWER_OF_2_SIZES and
* CreateCollection::NO_PADDING. The default is
* CreateCollection::USE_POWER_OF_2_SIZES.
*
* * indexOptionDefaults (document): Default configuration for indexes when
* creating the collection.
*
Expand Down Expand Up @@ -131,10 +112,6 @@ final class CreateCollection
*/
public function __construct(private string $databaseName, private string $collectionName, private array $options = [])
{
if (isset($this->options['autoIndexId']) && ! is_bool($this->options['autoIndexId'])) {
throw InvalidArgumentException::invalidType('"autoIndexId" option', $this->options['autoIndexId'], 'boolean');
}

if (isset($this->options['capped']) && ! is_bool($this->options['capped'])) {
throw InvalidArgumentException::invalidType('"capped" option', $this->options['capped'], 'boolean');
}
Expand All @@ -159,10 +136,6 @@ public function __construct(private string $databaseName, private string $collec
throw InvalidArgumentException::invalidType('"expireAfterSeconds" option', $this->options['expireAfterSeconds'], 'integer');
}

if (isset($this->options['flags']) && ! is_integer($this->options['flags'])) {
throw InvalidArgumentException::invalidType('"flags" option', $this->options['flags'], 'integer');
}

if (isset($this->options['indexOptionDefaults']) && ! is_document($this->options['indexOptionDefaults'])) {
throw InvalidArgumentException::expectedDocumentType('"indexOptionDefaults" option', $this->options['indexOptionDefaults']);
}
Expand Down Expand Up @@ -219,10 +192,6 @@ public function __construct(private string $databaseName, private string $collec
unset($this->options['writeConcern']);
}

if (isset($this->options['autoIndexId'])) {
trigger_error('The "autoIndexId" option is deprecated and will be removed in version 2.0', E_USER_DEPRECATED);
}

if (isset($this->options['pipeline']) && ! is_pipeline($this->options['pipeline'], true /* allowEmpty */)) {
throw new InvalidArgumentException('"pipeline" option is not a valid aggregation pipeline');
}
Expand All @@ -245,7 +214,7 @@ private function createCommand(): Command
{
$cmd = ['create' => $this->collectionName];

foreach (['autoIndexId', 'capped', 'comment', 'expireAfterSeconds', 'flags', 'max', 'maxTimeMS', 'pipeline', 'size', 'validationAction', 'validationLevel', 'viewOn'] as $option) {
foreach (['capped', 'comment', 'expireAfterSeconds', 'max', 'maxTimeMS', 'pipeline', 'size', 'validationAction', 'validationLevel', 'viewOn'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
Expand Down
13 changes: 0 additions & 13 deletions tests/Operation/CreateCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ public function testConstructorOptionTypeChecks(array $options): void
public static function provideInvalidConstructorOptions()
{
return self::createOptionDataProvider([
'autoIndexId' => self::getInvalidBooleanValues(),
'capped' => self::getInvalidBooleanValues(),
'changeStreamPreAndPostImages' => self::getInvalidDocumentValues(),
'clusteredIndex' => self::getInvalidDocumentValues(),
'collation' => self::getInvalidDocumentValues(),
'encryptedFields' => self::getInvalidDocumentValues(),
'expireAfterSeconds' => self::getInvalidIntegerValues(),
'flags' => self::getInvalidIntegerValues(),
'indexOptionDefaults' => self::getInvalidDocumentValues(),
'max' => self::getInvalidIntegerValues(),
'maxTimeMS' => self::getInvalidIntegerValues(),
Expand All @@ -48,15 +46,4 @@ public static function provideInvalidConstructorOptions()
'writeConcern' => self::getInvalidWriteConcernValues(),
]);
}

public function testAutoIndexIdOptionIsDeprecated(): void
{
$this->assertDeprecated(function (): void {
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['autoIndexId' => true]);
});

$this->assertDeprecated(function (): void {
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['autoIndexId' => false]);
});
}
}
2 changes: 1 addition & 1 deletion tests/UnifiedSpecTests/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class Util
Database::class => [
'aggregate' => ['pipeline', 'session', 'allowDiskUse', 'batchSize', 'bypassDocumentValidation', 'collation', 'comment', 'explain', 'hint', 'let', 'maxAwaitTimeMS', 'maxTimeMS'],
'createChangeStream' => ['pipeline', 'session', 'fullDocument', 'resumeAfter', 'startAfter', 'startAtOperationTime', 'batchSize', 'collation', 'maxAwaitTimeMS', 'showExpandedEvents'],
'createCollection' => ['collection', 'session', 'autoIndexId', 'capped', 'changeStreamPreAndPostImages', 'clusteredIndex', 'collation', 'expireAfterSeconds', 'flags', 'indexOptionDefaults', 'max', 'maxTimeMS', 'pipeline', 'size', 'storageEngine', 'timeseries', 'validationAction', 'validationLevel', 'validator', 'viewOn'],
'createCollection' => ['collection', 'session', 'capped', 'changeStreamPreAndPostImages', 'clusteredIndex', 'collation', 'expireAfterSeconds', 'indexOptionDefaults', 'max', 'maxTimeMS', 'pipeline', 'size', 'storageEngine', 'timeseries', 'validationAction', 'validationLevel', 'validator', 'viewOn'],
'dropCollection' => ['collection', 'session'],
'listCollectionNames' => ['authorizedCollections', 'filter', 'maxTimeMS', 'session'],
'listCollections' => ['authorizedCollections', 'filter', 'maxTimeMS', 'session'],
Expand Down

0 comments on commit d8c5d09

Please sign in to comment.