Bug #17043
closedHook processDatamap_afterDatabaseOperations bug with inline relations?
0%
Description
i am using the hook processDatamap_afterDatabaseOperations to process a field in a custom table, where i have an inline relation with another table.
the value of this calculated field is based on the NUMBER of linked (by inline relations) records.
the problem is this:
whenever i add or remove an inline relationed record, and save the form, my calculated field is wrong: my function (which counts the linked records with a simple query) gets the PREVIUOS count of linkied records...
it seems that the inline relationschip db updates happen AFTER the hook is called...
the proof is that if i RE-SAVE the form, the field gets a correct value.
i looked into class.t3lib_tcemain.php and i think that the problem is in the loop around all the tables to be updated... i think that the main table gets updated first... so it call my hook/function.. then it updated the inline relationed table
any comment/ideas?
(issue imported from #M5074)
Files
Updated by Oliver Hader over 17 years ago
Hi Stefano, could you please attach your extension or a reduced test extension to find the bug faster? Thanks in advance.
Updated by Oliver Hader over 17 years ago
The attached file 0005074.patch should solve this issue for the mentioned hook. In future it could be necessary also to consider the processDatamap_postProcessFieldArray hook - but this could lead to some problems.
For the moment, I just took care of the processDatamap_afterDatabaseOperations hook.
I didn't test it, so please tell me if it works.
Updated by Stefano Cecere over 17 years ago
Ciao Oliver
i did try your patch (on RC2).. but it 1) doesn't work 2) inline creation of new records doesn't work anymore...
maybe i did some errors applying the diff?
could you please attach here the whole new class.t3lib_tcemain.php so i can test it better?
thanks
stefano
Updated by Pardon Niels over 17 years ago
Hello Oliver,
I discovered the same problem. I applied you're patch and the problem is solved for me.
Greets,
Niels
Updated by Oliver Hader over 17 years ago
The patch file I attached was untested. But now I tested it and had no problems at all. Please consider that fieldArray is only filled if the value to be written to the database changed.
@Stefano Cecere: I'm going to add the whole class.t3lib_tcemain.php so you can test easily.
Updated by Stefano Cecere over 17 years ago
thanks Oliver
now it works well when i ADD new inline records.
but if i delete them, i have to save twice to have the hooked function calculate well the number of linked records.
Updated by Oliver Hader over 17 years ago
Sorry, I cannot reproduce this on removing child records. I've tested direct relations (1:n) with comma-separated-list and foreign_field and with the disposal of an intermediate table (m:n). You can send me your extension/configuration directly via e-mail to "oh [at] inpublica [dot] de" and I'll have a closer look at it.
Updated by Oliver Hader over 17 years ago
Stefano, did you experience further errors of the hook? I've sent you a patch for your extension some days ago via e-mail...
Updated by Oliver Hader over 17 years ago
Any news on this? Did someone experience further problems using the patch? If nobody objects I'm going to publish this on the Core-List.
Updated by Stefano Cecere over 17 years ago
hi Oliver
yes, now it works (with your little modification to my ext)
as i wrote in the email, we shoudl explain that an INSERT new (inline) records is a bit "slower" than an UPDATE query
so the COUNT of the inline records can't be done with a simple SELECT, but should be done using the code:
$count = $fieldArray['objects_to_count'];
right?
ciao
Updated by Stefano Cecere over 17 years ago
ops.. sorry
i made some deeper tests, and it doesn't work perfectly...
tomorrow i'll do better tests
Updated by Niels Pardon over 17 years ago
Last update was over a month ago. When will the patch be included in the core? Would be nice if the next release of TYPO3 4.1 includes this patch!
Updated by Oliver Hader over 17 years ago
The patch was published on the Core-List as RFC and needs approval by other Core-Devs. But I think it will be available in TYPO3 4.1.2
Updated by Oliver Hader over 17 years ago
Committed to SVN (TYPO3_4-1 and Trunk)
- TYPO3_4-1 - new rev. 2335
http://svn.t3.digitaldistrict.de/cgi-bin/trac.cgi/changeset/12523 - Trunk - new rev. 2336
http://svn.t3.digitaldistrict.de/cgi-bin/trac.cgi/changeset/12524