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

EZP-31707: Fixed crashes when ezcontentquery field parameters are invalid #48

Merged
merged 1 commit into from
Oct 20, 2020

Conversation

Steveb-p
Copy link
Contributor

@Steveb-p Steveb-p commented Oct 19, 2020

Question Answer
JIRA issue EZP-31707
Type bug
Target eZ Platform version v3.1
BC breaks no
Doc needed no

Steps to reproduce:
Create a content type with an ezcontentquery field. Select query type: relatedTocontent.
Fill the parameters filed with :

content: '@=content'
field: 'test'

Submit your content type.
Create a new object for this content type.

This PR prevents pages with invalid ezcontentquery content from crashing. On production environments pages will receive empty results instead. In development, exceptions will be thrown as it happens currently without change.

Introduces psr/log dependency to allow normal logging to pick up invalid configuration of fields in production as much as possible.

@lserwatka
Copy link
Member

Could you rebase with 2.2 branch, we are going to release 2.2 for Ibexa Platform 3.2

new QueryResultsPagerFantaAdapter(
$this->queryFieldService, $content, $fieldDefinitionIdentifier
)
$adapter = new QueryResultsPagerFantaAdapter(
Copy link

Choose a reason for hiding this comment

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

Maybe it could be better to close it in some factory, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Why not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not so sure about that.

Introducing a factory here means increasing the complexity of this particular code, expecting different PagerFantaAdapters to be introduced in some cases. Currently added code simply decorates the existing adapter if debug property is set to true.

It would also not get rid of the debug property, since the second, pagination-less variant just a few lines below would also still be required. This would mean it would cause the mentioned factory to be also responsible for that second variant / another service be introduced / debug property be left as-is in the injector.
All-in-all, I don't really see the benefit of introducing a factory now. If new adapter variants show up, then I'd be up for it.

Copy link

Choose a reason for hiding this comment

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

It is not as complex code that factory is must-have here but I see some advantages of that approach. It may increase readability - but it is my subjective opinion ;) however similar effect you can achieve by extracting it to a private function.
I not sure about increasing complexity here. if it really happened, it wouldn't be a problem because current complexity is rather low. However, in my opinion, it should reduce complexity because some logic will be moved out of the class and it should be noticeable when you would decide to write a unit test for that.

but probably it is not a game-changer here ;) and this discussion going to have more line than code ;) it was just proposal

Copy link
Member

Choose a reason for hiding this comment

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

Yes, testing where having a factory with an easily describable behavior will make a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kaff @bdunogier code has been redesigned. Instead of changing the behavior of QueryResultsInjector and wrapping PagerFantaAdapter with a decorator, a production-only service (based on kernel.debug parameter) is added to service container that decorates QueryFieldService service.

@kaff kaff requested a review from a team October 19, 2020 13:00
@Steveb-p Steveb-p changed the base branch from master to 2.2 October 20, 2020 06:09
@Steveb-p
Copy link
Contributor Author

@lserwatka PR has been rebased to package version 2.2. However, it is compatible with earlier versions and can be rebased further if you wish.

Copy link

@kaff kaff left a comment

Choose a reason for hiding this comment

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

Are we able to test it somehow?

@Steveb-p
Copy link
Contributor Author

@kaff I'm not familiar with spec tests used in this package, give me a second to see.

@Steveb-p
Copy link
Contributor Author

Steveb-p commented Oct 20, 2020

@kaff please see adc9225 for provided tests. From what I can see Travis CI is not configured for this repository, so you'll have to run them manually to see that they're green?

Should I refactor common code for those tests?

Now that I look at it I think I'll change the approach and wrap calls to QueryfieldServiceInterface instead.

@Steveb-p Steveb-p requested a review from a team October 20, 2020 09:47
@Steveb-p Steveb-p changed the base branch from 2.2 to 2.1 October 20, 2020 09:51
Copy link
Member

@bdunogier bdunogier left a comment

Choose a reason for hiding this comment

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

Looks good to me, good job on the test !

@lserwatka lserwatka merged commit 2287500 into 2.1 Oct 20, 2020
@lserwatka lserwatka deleted the EZP-31707 branch October 20, 2020 10:20
@lserwatka
Copy link
Member

You can merge it up to 2.2 and master.

@Steveb-p Steveb-p changed the title EZP-31825: Fixed crashes when ezcontentquery field parameters are invalid EZP-31707: Fixed crashes when ezcontentquery field parameters are invalid Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants