Skip to content
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

Compatibility with MongoDB 5.0 #2401

Merged
merged 2 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- "8.0"
- "8.1"
mongodb-version:
- "5.0"
- "4.4"
- "4.2"
- "4.0"
Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/ODM/MongoDB/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use function array_unique;
use function array_values;
use function assert;
use function count;
use function in_array;
use function is_array;
use function is_string;
use function iterator_count;
use function iterator_to_array;
Expand Down Expand Up @@ -352,9 +354,9 @@ public function updateDocumentValidator(string $documentName, ?int $maxTimeMs =
throw new InvalidArgumentException('Cannot update validators for files, views, mapped super classes, embedded documents or aggregation result documents.');
}

$validator = [];
if ($class->getValidator() !== null) {
$validator = $class->getValidator();
$validator = $class->getValidator();
if ($validator === null || (is_array($validator) && count($validator) === 0)) {
$validator = (object) [];
}

$collection = $this->dm->getDocumentCollection($class->name);
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function testUpdateDocumentValidatorReset(array $expectedWriteOptions, ?i
->with(
[
'collMod' => $class->collection,
'validator' => [],
'validator' => (object) [],
'validationAction' => ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR,
'validationLevel' => ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT,
],
Expand Down