Bug #79615

QueryRestrictionBuilder restrictions not working when using table multiple times in one query

Added by Patrick Broens 10 months ago. Updated about 1 month ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
Start date:
2017-02-03
Due date:
% Done:

100%

TYPO3 Version:
8
PHP Version:
7.0
Tags:
Complexity:
Is Regression:
No
Sprint Focus:
Stabilization Sprint

Description

For several reasons it is sometimes necessary to join a table in a single query which is used before. This can be in ->from() or another ->join().

When using a statement like

$statement = $queryBuilder
            ->select('original.*')
            ->from('pages', 'original')
            ->join(
                'original',
                'pages',
                'similar',
                $queryBuilder->expr()->eq(
                    'similar.uid',
                    <PUT_SOME_UID_HERE>
                )
            )
            ...

or joining the same table multiple times will only add the restrictions for the last mentioned table.

This is due to the fact the method "getQueriedTables()" in the "QueryBuilder" does not take multiple use of a single table into account. The array returned from this method will look like

[
            'pages' => 'similar'
]

while it should be multidimensional like

[
            'pages' => [
                        'original'
                        'similar'
            ]
]

While setting this array it will overwrite the alias "original" with the second one "similar".

The RestrictionBuilder is using this array to iterate over all tables setting their restrictions, which fails for "original". The RestrictionBuilder should also take into account there can be multiple use of one table, using the multidimensional array.

Associated revisions

Revision aa339608 (diff)
Added by Tymoteusz Motylewski 9 months ago

[BUGFIX] Add query restrictions for all tables in query

QueryBuilder::getQueriedTables now returns an array with table
alias as a key and table name as value.
If a table doesn't have an alias, both key and value are containing
table name.

This change is needed to make query restriction classes add restrictions
for all tables in case the self inner join is made.
A test covering the case was added to QueryBuilderTest.

Releases: master
Resolves: #79615
Change-Id: Ibf797189334ed86db0fce1a4ef3f0898cb0ada11
Reviewed-on: https://review.typo3.org/51902
Tested-by: TYPO3com <>
Reviewed-by: Morton Jonuschat <>
Tested-by: Morton Jonuschat <>
Reviewed-by: Patrick Broens <>
Tested-by: Patrick Broens <>
Reviewed-by: Georg Ringer <>
Tested-by: Georg Ringer <>

Revision f85326d3 (diff)
Added by Tymoteusz Motylewski 9 months ago

[FOLLOWUP][BUGFIX] Add query restrictions for all tables in query

This patch ensures a correct table name is used within the restrictions
to be able to find TCA information.

Resolves: #79615
Releases: master
Change-Id: I1e96531602bfb5debeb0a1202ed91eb90cc31032
Reviewed-on: https://review.typo3.org/51912
Tested-by: TYPO3com <>
Reviewed-by: Nicole Cordes <>
Tested-by: Nicole Cordes <>
Reviewed-by: Wouter Wolters <>
Reviewed-by: Thomas Hohn <>
Reviewed-by: Jigal van Hemert <>
Tested-by: Jigal van Hemert <>
Reviewed-by: Georg Ringer <>
Tested-by: Georg Ringer <>

History

#1 Updated by Patrick Broens 9 months ago

  • Target version changed from 8.6 to 8 LTS

#2 Updated by Josef Glatz 9 months ago

  • Sprint Focus set to Stabilization Sprint

#3 Updated by Tymoteusz Motylewski 9 months ago

This issue is e.g. present in LocalizationRepository::fetchOriginLanguage
The query there is inner joining tt_content with self (alias tt_content_orig) which results in delete where clause being added only for tt_content_orig and not for tt_content.

#4 Updated by Gerrit Code Review 9 months ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51902

#5 Updated by Gerrit Code Review 9 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51902

#6 Updated by Gerrit Code Review 9 months ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51902

#7 Updated by Gerrit Code Review 9 months ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51902

#8 Updated by Tymoteusz Motylewski 9 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#9 Updated by Gerrit Code Review 9 months ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51912

#10 Updated by Gerrit Code Review 9 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51912

#11 Updated by Gerrit Code Review 9 months ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51912

#12 Updated by Tymoteusz Motylewski 9 months ago

  • Status changed from Under Review to Resolved

#13 Updated by Riccardo De Contardi about 1 month ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF