-
Notifications
You must be signed in to change notification settings - Fork 203
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-30027: [REST] Fixed logical op. parsing for Criterions of the same type #2527
EZP-30027: [REST] Fixed logical op. parsing for Criterions of the same type #2527
Conversation
How shall I ask for a code review? Do I have to do something else apart from creating the PR? |
Usually by reaching out at our Community Slack or pinging relevant people if you know who to ping. But don't worry, since I saw this PR, I got you covered here :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks promising :)
In general things to change:
- This PR should rather target
6.7
branch (LTS) as bug probably exists there also. - While the tests cases you've implemented are quite valuable, in case of REST, foremost we need some integration/functional tests in
eZ/Bundle/EzPublishRestBundle/Tests/Functional
namespace.
Other remarks and questions:
{ | ||
$criteria = []; | ||
foreach ($criteriaByType as $type => $criterion) { | ||
if (is_array($criterion) && $this->isNumericArray($criterion)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is usually called zero-indexed array. But could you elaborate on what happens here, so this code is required?
(this is just a question, not change request. I need to have full understanding of what happens here and right now I don't follow 😅 ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey.
Of course. When parsing a view-input query
<Query>
<OR>
<Criterion1>some-value</Criterion1>
<Criterion2>some-value</Criterion2>
</OR>
</Query>
EZ will not parse this into a numeric array instead create an associative array with criteria name (Criterion1 & Criterion2) as indexes.
[
"Criterion1" => "some-value",
"Criterion2" => "some-value"
]
This is a problem when there is two criteria of same type, like:
<Query>
<OR>
<ContentTypeIdentifierCriterion>author</ContentTypeIdentifierCriterion>
<ContentTypeIdentifierCriterion>book</ContentTypeIdentifierCriterion>
<SomeOtherCriterion>some-value</SomeOtherCriterion>
</OR>
</Query>
The decoder will transform this into a nested array:
[
"ContentTypeIdentifierCriterion" => [
0 => "author",
1 => "book",
],
"SomeOtherCriterion" => "some-value"
]
The method transforms this into a flattend criterion=>configuration array:
[
0 => [
"type" => "ContentTypeIdentifierCriterion",
"data" => "author"
],
1 => [
"type" => "ContentTypeIdentifierCriterion",
"data" => "book"
],
2 => [
"type" => "SomeOtherCriterion",
"data" => "some-value"
],
]
In case you have a better explaining name for the method please tell me and i will change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks promising :)
In general things to change:
- This PR should rather target
6.7
branch (LTS) as bug probably exists there also.- While the tests cases you've implemented are quite valuable, in case of REST, foremost we need some integration/functional tests in
eZ/Bundle/EzPublishRestBundle/Tests/Functional
namespace.Other remarks and questions:
I will add a functional test and change the target branch (probably tomorrow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a functional test and change the target branch (probably tomorrow).
👍 that will alos help understanding this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the target version to 6.7 and implemented functional tests for the View POST route and LogicalAnd, LogicalOr and nesting of those.
[ x ] PHP Code Fixer applied
[ x ] Functional Tests implemented
[ x ] Unit Tests implemented
[ x ] Bug fixed
[ x ] Target version is now 6.7
Side notice:
I realized that on 6.7 the FieldCriterion Parser is not yet implemented and to curiosity backported the current one to it and it works perfect with all tests passing, though I was not sure if it is a good idea to add this feature on this bugfix branch. If you think that backporting the FieldCriterion is an option i would rather merge this:
https://github.com/RozbehSharahi/ezpublish-kernel/commits/backup/fix/rest-api-logical-operators
So people can also use the FieldCriterion on REST and 6.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alongosz WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that on 6.7 the FieldCriterion Parser is not yet implemented and to curiosity backported the current one to it and it works perfect with all tests passing, though I was not sure if it is a good idea to add this feature on this bugfix branch.
No, we're not backporting features unless we have to due to technical constraints :)
eZ/Publish/Core/REST/Server/Tests/Input/Parser/Criterion/LogicalAndTest.php
Outdated
Show resolved
Hide resolved
eZ/Publish/Core/REST/Server/Tests/Input/Parser/Criterion/LogicalOrTest.php
Outdated
Show resolved
Hide resolved
c456005
to
4eb5f4b
Compare
4eb5f4b
to
ead8990
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I've dug into this a little bit deeper. The root cause of a bug lays within XML processing of input (in \eZ\Publish\Core\REST\Common\Input\Handler\Xml::convertDom
). It passes, through several layers, inconsistent data to Criteria.
Basically both cases:
<Query>
<OR>
<ContentTypeIdentifierCriterion>author</ContentTypeIdentifierCriterion>
<ContentTypeIdentifierCriterion>book</ContentTypeIdentifierCriterion>
</OR>
</Query>
and
<Query>
<OR>
<ContentTypeIdentifierCriterion>author</ContentTypeIdentifierCriterion>
</OR>
</Query>
should produce an array of elements before passing it to LogicalAnd
and LogicalOr
criterion.
So something like that, for the latter case, should already be given:
[
"ContentTypeIdentifierCriterion" => [
0 => "author",
],
]
However the mentioned XML handler is too generic to be able to distinguish what should be parsed how. We might attempt to fix it in the future, but probably rather by redesigning entire input handling.
So given that I'll accept current solution. 🎉
Few final remarks:
eZ/Publish/Core/REST/Server/Input/Parser/Criterion/LogicalAnd.php
Outdated
Show resolved
Hide resolved
eZ/Publish/Core/REST/Server/Input/Parser/Criterion/LogicalAnd.php
Outdated
Show resolved
Hide resolved
eZ/Publish/Core/REST/Server/Input/Parser/Criterion/LogicalAnd.php
Outdated
Show resolved
Hide resolved
eZ/Publish/Core/REST/Server/Input/Parser/Criterion/LogicalAnd.php
Outdated
Show resolved
Hide resolved
@alongosz Hey, i did all changes you requested but still added some final comments above to clarify some stuff. |
fba1d9a
to
917c961
Compare
@alongosz maybe you can pass this to QA? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, but hopefully it will be in time for 1.7.9 🙂
Looks ok to me, QA approved - ping @alongosz
917c961
to
a2605af
Compare
Great! This is few months old, so rebased. Waiting for CI before merging. |
Merged up to Thank you @RozbehSharahi |
TODO:
$ composer fix-cs
).