[TYPO3-dev] Idea: add transaction support to t3lib_db

Christian Futterlieb christian at futterlieb.ch
Mon Mar 7 12:17:25 CET 2011


Hi,

On 03/07/2011 10:02 AM, Dmitry Dulepov wrote:
> That's the point of transaction: to keep database state consistent. If
> the transaction needs to be rolled back, that's for a reason. Would you
> prefer only half-data in the database? Surely not.
You are right, that's the meaning of transactions. So, at this point of 
the code:

$GLOBALS['TYPO3_DB']->commit();

I assume that the data in the database is consistent and stored persistent.

> Sorry, not going to work in TYPO3. Think of TCEmain hooks: you never
> know how they are called: from alt_doc or from a custom script as a part
> of much larger database activity. You may want to start transaction
> there if you change users and groups to keep them consistent. However
> the calling code may want to start the transaction as well because it
> may update several other record types and relation between them. How
> would you handle this? It could be two totally different extensions,
> written by different people, completely unrelated. You way in this case
> is ..? :)
>

Is it really good coding style to wrap as much code as possible with 
transactions under the flag of data consistency? I don't think so. I mean:
1. a calling script could commit its transaction before calling a hook 
(and guarantee the integrity of the passed data therefore) see below 
'Instead of'.
2. a calling/called script should be able to check wether a transaction 
has been started or not
3. a called script must not be essential for the calling script, but 
could break it's data saving (Ex: when I add a custom field to a 
fe_users record and fill it via hook, I could never change the username 
when the custom field saving fails).


Instead of:
<snip>
callingCode
     startTransaction();
     hookCode
         startTransaction();
         commit();
     commit();
</snip>

do it like this:
<snip>
callingCode
     startTransaction();
     commit();
     hookCode
         startTransaction();
         commit();
</snip>


I know, my argumentation means far more complex work to implement usage 
of transactions in TYPO3 core (which script calls which, when, under 
which conditions, etc, you surely know that better than me). But don't 
you agree, that a transaction implementation like this will lead to 
better code and prevent abuse of the transactions?


Regards, Christian




More information about the TYPO3-dev mailing list