From d8c5d09851f45eb9277dbf7efa6f74715890e015 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Wed, 9 Oct 2024 10:05:31 -0400 Subject: [PATCH] PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) * PHPLIB-1546: Remove CreateCollection flags option and related constants * PHPLIB-1159: Remove CreateCollection autoIndexId option --- UPGRADE-2.0.md | 4 +++ src/Operation/CreateCollection.php | 33 +----------------------- tests/Operation/CreateCollectionTest.php | 13 ---------- tests/UnifiedSpecTests/Util.php | 2 +- 4 files changed, 6 insertions(+), 46 deletions(-) diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index 0492cef9e..516b57929 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -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 ------------------------- diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index 7f125801b..45a4925d3 100644 --- a/src/Operation/CreateCollection.php +++ b/src/Operation/CreateCollection.php @@ -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. @@ -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. * @@ -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. * @@ -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'); } @@ -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']); } @@ -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'); } @@ -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]; } diff --git a/tests/Operation/CreateCollectionTest.php b/tests/Operation/CreateCollectionTest.php index 6ed8a1f47..4ec92b32f 100644 --- a/tests/Operation/CreateCollectionTest.php +++ b/tests/Operation/CreateCollectionTest.php @@ -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(), @@ -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]); - }); - } } diff --git a/tests/UnifiedSpecTests/Util.php b/tests/UnifiedSpecTests/Util.php index 5d758ab6a..f33522a31 100644 --- a/tests/UnifiedSpecTests/Util.php +++ b/tests/UnifiedSpecTests/Util.php @@ -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'],