Bug #45332

category api won't work when used with multiple tables

Added by Thomas Allmer over 8 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2013-02-09
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.1
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

if you have tableA, and tableB both using the category api the function
\TYPO3\CMS\Core\Category\Collection\CategoryCollection::load(...)
will return wrong results

example:
tableA has an element A1, A2, A3
tableB has an element B1, B2, B3

A1 is in the category c1
B2 is in the category c1
B3 is in the category c1

now if you use the function to get c1 of tableA it will give u A1, A2, A3 even though ONLY A1 is in the category... (as it will also get B2, B3 and as the id element is also available for tableA it shows them..

the function getCollectedRecords only checks for uid and not for the tablename
the solution is simple... just add a
"AND sys_category_record_mm.tablenames = <table_to_display>"


Files

45332.diff (1.26 KB) 45332.diff Marc Wöhlken, 2013-05-28 21:24

Related issues

Related to TYPO3 Core - Task #50091: Category API: Add test for categories with multiple tablesClosed2013-07-16

Actions
#1

Updated by Thorsten Kahler over 8 years ago

  • Category set to Database API (Doctrine DBAL)
  • Status changed from New to Needs Feedback
  • Assignee set to Thomas Allmer
  • Priority changed from Must have to Should have

Could you please give a code example? I can't reproduce that issue from reading the TYPO3 code.

#2

Updated by Marc Wöhlken about 8 years ago

Stumbled over the same issue using TYPO3 6.0.6.

The problem is that CategoryCollection->getCollectedRecords() fetches all records assigned to a given category, no matter from which table.

Imagine you have a page with uid 1 and a news entry with uid 2, both assigned to category 99. Additionally you have a page with uid 2, not assigned to any category.

When trying to fetch all records from table pages which are assigned to category 99 the following will happen. getCollectedRecords() finds each and every entry with category 99 (no matter from which table), extracts its uid and joins the result with the target table (pages). This produces one entry for the above mentioned news record (as the category matches) which is then successfully joined with the "pages" record having uid 2.

This results in wrong category collections.

This example will only work, if the uid of the news record is also available as a valid uid from pages table.

CategoryCollection->getCollectedRecords() has to be modified:
Wrong:
$resource = $this->getDatabase()->exec_SELECT_mm_query($this->getItemTableName() . '.*', self::$storageTableName, 'sys_category_record_mm', $this->getItemTableName(), 'AND ' . self::$storageTableName . '.uid=' . intval($this->getIdentifier()));

Correct:
$resource = $this->getDatabase()->exec_SELECT_mm_query($this->getItemTableName() . '.*', self::$storageTableName, 'sys_category_record_mm', $this->getItemTableName(), 'AND ' . self::$storageTableName . '.uid=' . intval($this->getIdentifier()) . ' AND sys_category_record_mm.tablenames = "' . $this->getItemTableName() . '"');

#3

Updated by Marc Wöhlken about 8 years ago

Attached patch for 6.0 branch.

#4

Updated by Alexander Opitz about 8 years ago

  • Status changed from Needs Feedback to New

Hi Marc,

can you bring this patch into Gerrit for review?

#5

Updated by Gerrit Code Review almost 8 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/21963

#6

Updated by Gerrit Code Review almost 8 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/21963

#7

Updated by Gerrit Code Review almost 8 years ago

Patch set 1 for branch TYPO3_6-1 has been pushed to the review server.
It is available at https://review.typo3.org/22366

#8

Updated by Gerrit Code Review almost 8 years ago

Patch set 1 for branch TYPO3_6-0 has been pushed to the review server.
It is available at https://review.typo3.org/22367

#9

Updated by Marc Wöhlken almost 8 years ago

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

Updated by Benni Mack over 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF