CustomizeRequest doesn't work well with PostBigRequest
Hi, I'm trying to use both CustomizeRequest and PostBigRequest for a request, but I can't get them to work together.
While building the query, I'm adding a couple of custom parameters. Then I'm converting the request to POST because the request is getting too large. But the custom parameters are not added to the POST rawData.
I followed the code until \Solarium\Core\Client\Client::createRequest and after the POST_CREATE_REQUEST is dispatched I can see that rawData only contains the parameters that were added through the Query object, not the ones that were added to the Client through CustomizeRequest.
Is it a bug, or do I miss something?
Edit: I'm using the 5.1.5 version of the library.
it looks like the CustomizeRequest hooks into the Events::PRE_EXECUTE_REQUEST while you want it to hook into the Events::PRE_CREATE_REQUEST so the PostBigRequest takes the custimizations into consideration while converting from GET to POST.
indeed looks like to a bug to me
A bit more info on the debugging, based on what I found here: https://solarium.readthedocs.io/en/stable/customizing-solarium/ it seems that the PostBigRequest is handled on the POST_CREATE_REQUEST event, while the CustomizeRequest on the PRE_EXECUTE_REQUEST which comes after. So it's not possible to convert the parameters that are added by CustomizeRequest to POST rawData, because the GET-->POST conversion is happening too early.
Haha @wickedOne we posted the same info at the same time :D
haha @efpapado , what are the odds? :-)
if you need to get around this issue quickly, you might want to use the registerPlugin method of the Client class to register your own CustomizeRequest plugin which hooks into the appropriate event.
and of course feel free to open a pull request to get it fixed in the solarium code base
Hooking CustomizeRequest into Events::PRE_CREATE_REQUEST will also fix #350.
I'll try to create a PR on Monday that I'm back at work, thanks for the help :)
By inspection of the code, unless I'm wrong, it seems that hooking CustomizeRequest into Events::PRE_CREATE_REQUEST requires all the implementations of interface RequestBuilderInterface to be changed.
This issue could also be solved by moving the PostBigRequest from POST_CREATE_REQUEST to PRE_EXECUTE_REQUEST , which btw seems to be a bit more proper.
The only side-effect is that the correct combination of CustomizeRequest with PostBigRequest will depend on the order of implementation; but this also makes sense and could not be avoided.
If the PR is accepted, a note could also be added on the documentation.
I think BigPostRequest should be triggered on PRE_EXECUTE_REQUEST. Everything else seems wrong.