Project

General

Profile

Actions

Bug #78128

closed

MM-Relations not correctly removed when deleting parent object

Added by Robert Jelinek about 8 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Extbase
Target version:
-
Start date:
2016-10-02
Due date:
% Done:

100%

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

Description

Situation:

Table A, B
A contains objects
B contains objects with an MM-relation to A
In that situation extbase uses an intermediate table C holding the references from B to A

Deleting rows from B with repository->remove(x) does not clean up the references in the intermediate table. It only removes the row from B.

This leads to buggy behaviour, because the intermediate table holds active entries, which are used when a new row in B will be created with the UID of the deleted row.

Solution: see attached patch (only 3 lines)


Files

mm-relations-remove.patch (461 Bytes) mm-relations-remove.patch Robert Jelinek, 2016-10-02 18:50
mm-relations-remove.patch (477 Bytes) mm-relations-remove.patch Robert Jelinek, 2016-10-02 19:49
issue78128_1.0.0_201610040938.zip (22.9 KB) issue78128_1.0.0_201610040938.zip Robert Jelinek, 2016-10-04 09:43
Actions #1

Updated by Robert Jelinek about 8 years ago

Update of the patch: the original patch does not regard non extbase properties

Actions #2

Updated by Nicole Cordes about 8 years ago

  • Status changed from New to Needs Feedback

Hi Robert,

As I understand your issue correctly currently Extbase handles deleting items from B the same way the core does in the backend. If you delete the item in the backend the relations in your mm-table are still available as well. This is to support restoring the items with recycler.

As the uid should be auto-increment in your table B, how can you insert a new item with an uid which was already used by another item? Have you set the deleted field in your table B's ctrl section in your TCA?

If you want to remove the relation to B you should take care about that on your own in your controller.

Hope this helps to clear things up for you.

Actions #3

Updated by Robert Jelinek about 8 years ago

Hi Nicole,
for a deeper inspection of my problem I add some additional information about my database structure:

Table A has the following fields:
user -> n:1 to feuser
category -> 1:n to table B with cascaded remove ([remove tag in php code])
...

Table B has the following fields:
user -> m:n to feuser
admin -> m:n to feuser
...

As you see, there are many references to feuser. When I remove a row from table A, the categories (which are rows in table B) should be removed as well. This works correctly, but the intermediate tables for B:user and B:admin are still in the DB although the rows in table B are removed completely. Also if I remove a row from table B the intermediate tables rows still exist.

About "reusing UIDs": Table A contains a "project" in my extension, table B contains parts of this "project". If someone deletes all projects via the extension, all rows in A and B are deleted (but not the intermediates). Because table B is then empty, my database (mysql 5) starts with the UID 1 again (see description of auto_increment behaviour for innodb tables type http://dev.mysql.com/doc/refman/5.7/en/innodb-auto-increment-handling.html, topic server restart). So later an already used UID will be created which references the intermediate items. So I do not create the UID - the database does it.

Additionally I do not use the deleted field in the TCA (so removing an object is really a delete from the database) [see method removeEntity in Backend.php].

Actions #4

Updated by Nicole Cordes about 8 years ago

Hi Robert,

Thank you for your fast answer. Do you have any extension you can share for having a look at this issue?

Actions #5

Updated by Robert Jelinek about 8 years ago

Ok, here it is ... simply install and make a content element with this plugin.

Three tables:
A holds 1:n references to C (with cascade remove)
A holds 1:n references to B (with cascade remove)
B holds m:n references to C in field c1
B holds m:n references to C in field c2
C is only referenced by other tables.

Try to prepare data (action in plugin available) and delete entries from A or B.
The rest should be easy to understand...

Take a look at the tables tx_issue78128_tableb_c2_tablec_mm and tx_issue78128_tableb_tablec_mm when you delete rows from table b.

Actions #6

Updated by Nicole Cordes about 8 years ago

  • Status changed from Needs Feedback to Accepted
  • Assignee set to Nicole Cordes

Hi Robert!

Thank you very much for the provided information. I'm working on a fix right now.

Actions #7

Updated by Gerrit Code Review about 8 years ago

  • Status changed from Accepted 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/50103

Actions #8

Updated by Gerrit Code Review almost 8 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/50103

Actions #9

Updated by Gerrit Code Review almost 8 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/50103

Actions #10

Updated by Gerrit Code Review almost 8 years ago

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

Actions #11

Updated by Nicole Cordes almost 8 years ago

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

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF