Project

General

Profile

Actions

Bug #79615

closed

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

Added by Patrick Broens almost 8 years ago. Updated about 7 years ago.

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

100%

Estimated time:
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.

Actions #1

Updated by Patrick Broens almost 8 years ago

  • Target version changed from 8.6 to 8 LTS
Actions #2

Updated by Josef Glatz over 7 years ago

  • Sprint Focus set to Stabilization Sprint
Actions #3

Updated by Tymoteusz Motylewski over 7 years 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.

Actions #4

Updated by Gerrit Code Review over 7 years 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

Actions #5

Updated by Gerrit Code Review over 7 years 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

Actions #6

Updated by Gerrit Code Review over 7 years 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

Actions #7

Updated by Gerrit Code Review over 7 years 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

Actions #8

Updated by Tymoteusz Motylewski over 7 years ago

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

Updated by Gerrit Code Review over 7 years 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

Actions #10

Updated by Gerrit Code Review over 7 years 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

Actions #11

Updated by Gerrit Code Review over 7 years 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

Actions #12

Updated by Tymoteusz Motylewski over 7 years ago

  • Status changed from Under Review to Resolved
Actions #13

Updated by Riccardo De Contardi about 7 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF