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

[BC][2.7] ES extensions no longer executed #5363

Closed
darthf1 opened this issue Jan 24, 2023 · 4 comments · Fixed by #5379
Closed

[BC][2.7] ES extensions no longer executed #5363

darthf1 opened this issue Jan 24, 2023 · 4 comments · Fixed by #5379
Labels

Comments

@darthf1
Copy link
Contributor

darthf1 commented Jan 24, 2023

Hi!

I'm trying to upgrade from v2.6.8 to v2.7.7.

#5283 fixes a lot of issues for me, but now a few of my tests return errors because the API output is different as expected; I get more hydra:items returned as expected.

I use an extension, to perform additional filtering on the results if needed, by changing the ES request body:

<?php

declare(strict_types=1);

namespace App\MyNamespace;

use ApiPlatform\Core\Bridge\Elasticsearch\DataProvider\Extension\RequestBodySearchCollectionExtensionInterface;

final class MyESExtension implements RequestBodySearchCollectionExtensionInterface
{
    public function applyToCollection(array $requestBody, string $resourceClass, ?string $operationName = null, array $context = []): array
    {
        ....
    }
}

When I put a breakpoint inside the applyToCollection function, I noticed It's not called in v2.7.7 and it is called in v2.6.8.

@soyuka
Copy link
Member

soyuka commented Jan 24, 2023

probably that our ES provider is not called anymore, I guess you can't update to 3.x ? Is the ElasticsearchProvider called ? It's also possible that this interface namespace changed and that we forgot to tag this old interface

@darthf1
Copy link
Contributor Author

darthf1 commented Jan 24, 2023

Is the ElasticsearchProvider called?

If the provider would not be called, would I get a result at all? Because my issue is that the request body does not get altered (by me) because the extension is not called, not that I get no results at all.

I'll investigate.

I guess you can't update to 3.x ?

I would really love to migrate to 3.x, especially with the new ES features released in 3.1, but I was hoping I could do it incrementally.

@darthf1
Copy link
Contributor Author

darthf1 commented Jan 24, 2023

It's also possible that this interface namespace changed and that we forgot to tag this old interface

Yep that was it!

I've added the below to my services.php and these tests are now green! :)

<?php

declare(strict_types=1);

namespace MyNamespace;

use ApiPlatform\Core\Bridge\Elasticsearch\DataProvider\Extension\RequestBodySearchCollectionExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    ....

    $services->instanceof(RequestBodySearchCollectionExtensionInterface::class)
        ->tag('api_platform.elasticsearch.request_body_search_extension.collection')
    ;
}

@soyuka
Copy link
Member

soyuka commented Jan 26, 2023

Feel free to patch this on 2.7!

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 a pull request may close this issue.

2 participants