From ccc5ae2638ac01dfa71162c349762c7dce2ef698 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 8 Oct 2024 13:43:47 -0400 Subject: [PATCH 1/4] PHPLIB-1546: Remove CreateCollection flags option and related constants --- src/Operation/CreateCollection.php | 14 +------------- tests/Operation/CreateCollectionTest.php | 1 - tests/UnifiedSpecTests/Util.php | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index 7f125801b..fe4add415 100644 --- a/src/Operation/CreateCollection.php +++ b/src/Operation/CreateCollection.php @@ -42,9 +42,6 @@ */ final class CreateCollection { - public const USE_POWER_OF_2_SIZES = 1; - public const NO_PADDING = 2; - /** * Constructs a create command. * @@ -83,11 +80,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. * @@ -159,10 +151,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']); } @@ -245,7 +233,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 (['autoIndexId', '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..e67b7c33a 100644 --- a/tests/Operation/CreateCollectionTest.php +++ b/tests/Operation/CreateCollectionTest.php @@ -32,7 +32,6 @@ public static function provideInvalidConstructorOptions() 'collation' => self::getInvalidDocumentValues(), 'encryptedFields' => self::getInvalidDocumentValues(), 'expireAfterSeconds' => self::getInvalidIntegerValues(), - 'flags' => self::getInvalidIntegerValues(), 'indexOptionDefaults' => self::getInvalidDocumentValues(), 'max' => self::getInvalidIntegerValues(), 'maxTimeMS' => self::getInvalidIntegerValues(), diff --git a/tests/UnifiedSpecTests/Util.php b/tests/UnifiedSpecTests/Util.php index 5d758ab6a..75c758a6f 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', 'autoIndexId', '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'], From f9fd89692e50fa651e004f4d247cc00030c84f16 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 8 Oct 2024 13:45:54 -0400 Subject: [PATCH 2/4] PHPLIB-1159: Remove CreateCollection autoIndexId option --- src/Operation/CreateCollection.php | 18 +----------------- tests/Operation/CreateCollectionTest.php | 12 ------------ tests/UnifiedSpecTests/Util.php | 2 +- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index fe4add415..6dc72a2ef 100644 --- a/src/Operation/CreateCollection.php +++ b/src/Operation/CreateCollection.php @@ -47,14 +47,6 @@ final class CreateCollection * * 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. * @@ -123,10 +115,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'); } @@ -207,10 +195,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'); } @@ -233,7 +217,7 @@ private function createCommand(): Command { $cmd = ['create' => $this->collectionName]; - foreach (['autoIndexId', 'capped', 'comment', 'expireAfterSeconds', '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 e67b7c33a..4ec92b32f 100644 --- a/tests/Operation/CreateCollectionTest.php +++ b/tests/Operation/CreateCollectionTest.php @@ -25,7 +25,6 @@ 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(), @@ -47,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 75c758a6f..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', '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'], From 1f7071b1c17b74a2b34a3d0e60c84844412e2eb5 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 8 Oct 2024 23:19:30 -0400 Subject: [PATCH 3/4] Note removals in upgrade docs --- UPGRADE-2.0.md | 4 ++++ 1 file changed, 4 insertions(+) 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 ------------------------- From 424c2826672db74aa551728ee22b19d63cd058cb Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 8 Oct 2024 23:20:43 -0400 Subject: [PATCH 4/4] Remove unnecessary use statements --- src/Operation/CreateCollection.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php index 6dc72a2ef..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.