Skip to content

PHPORM-356: Skip search indexes not enabled exception #2787

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

Merged
merged 1 commit into from
Jul 9, 2025

Conversation

paulinevos
Copy link
Contributor

If search indexes are not enabled on the server, we should simply skip any search index operation. This commit adds an error code to the search index error check already in place.

Closes PHPORM-356

@paulinevos paulinevos requested review from alcaeus and GromNaN July 8, 2025 12:27
Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test like other exceptions have:

public function testCreateDocumentSearchIndexesNotSupported(): void
{
$exception = $this->createSearchIndexCommandException();
$cmsArticleCollectionName = $this->dm->getClassMetadata(CmsArticle::class)->getCollection();
foreach ($this->documentCollections as $collectionName => $collection) {
if ($collectionName === $cmsArticleCollectionName) {
$collection
->expects($this->once())
->method('createSearchIndexes')
->with($this->anything())
->willThrowException($exception);
} else {
$collection->expects($this->never())->method('createSearchIndexes');
}
}
$this->expectExceptionObject($exception);
$this->schemaManager->createDocumentSearchIndexes(CmsArticle::class);
}

@@ -47,6 +47,7 @@ final class SchemaManager

private const CODE_SHARDING_ALREADY_INITIALIZED = 23;
private const CODE_COMMAND_NOT_SUPPORTED = 115;
private const CODE_SEARCH_NOT_ENABLED = 31082;
Copy link
Member

@malarzm malarzm Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great to have this exposed as a const from one of underlying libs. Or is it still not exposed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we have the same issue in the Laravel package: https://github.com/mongodb/laravel-mongodb/blob/a2b4ab86dfc9248050b2592d9830773ac335774e/src/Schema/Builder.php#L386-L395

But if we rely on a new function in the mongodb/mongodb library, we would have to increase the minimum version for low benefits.
I'm tracking this request: PHPLIB-1689

@paulinevos paulinevos force-pushed the 356_skip-not-enabled-error branch 2 times, most recently from 67d3da4 to d49a393 Compare July 9, 2025 07:24
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the comment is added.

If search indexes are not enabled on the server, we should simply skip
any search index operation. This commit adds an error code to the search
index error check already in place.
@paulinevos paulinevos force-pushed the 356_skip-not-enabled-error branch from d49a393 to 2715d7c Compare July 9, 2025 11:17
@paulinevos paulinevos merged commit a69de4c into doctrine:2.11.x Jul 9, 2025
20 checks passed
@paulinevos paulinevos deleted the 356_skip-not-enabled-error branch July 9, 2025 11:36
@GromNaN GromNaN added this to the 2.11.3 milestone Jul 9, 2025
@GromNaN GromNaN added the Bug label Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants