Bug #45332
closedcategory api won't work when used with multiple tables
100%
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
Updated by Thorsten Kahler almost 12 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.
Updated by Marc Wöhlken over 11 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() . '"');
Updated by Marc Wöhlken over 11 years ago
- File 45332.diff 45332.diff added
Attached patch for 6.0 branch.
Updated by Alexander Opitz over 11 years ago
- Status changed from Needs Feedback to New
Hi Marc,
can you bring this patch into Gerrit for review?
Updated by Gerrit Code Review over 11 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
Updated by Gerrit Code Review over 11 years ago
Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/21963
Updated by Gerrit Code Review over 11 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
Updated by Gerrit Code Review over 11 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
Updated by Marc Wöhlken over 11 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 3a053b93181c112918963f88b2b8ca8b2b1ae140.