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

Dmitry Dulepov dmitry.dulepov at gmail.com
Fri Mar 4 14:25:31 CET 2011


Hi!

I propose to add several new functions to t3lib_db:

public function startTransaction();
public function commit();
public function rollback();
public function hasFailedTransactions();

Why it is necessary? Quite often you need to make changes to various 
tables. If a single change fails, that may leave the system in the 
corrupted state. Transactions solve that. Currently you can just use a 
simple way:

$GLOBALS['TYPO3_DB']->sql_query('START TRANSACTION');

However if your code is complex, transactions may be started multiple times 
by the code on various levels. Imagine something like that:

updateUser -> start transaction
	updateGroups -> start trasaction / commit
	updateMediaAssets -> start trasaction / commit
	...
		TCEmainHook::processDatamap() -> start trasaction / commit
	...
	-> commit

Here we have a major issue: transactions cannot be nested (it is a error). 
Thus we need a way to track that transaction is already started and not to 
issue another START TRANSACTION call. Also we need to watch amount of 
COMMIT statements and COMMIT only when it matches the number of START 
TRANSACTION calls. On the other hand, ROLLBACK should be possible from any 
point. So the first three new functions will handle that. The last function 
would tell if the transaction is rolled back by any inner levels or a error 
happened during execution.

I could simply make and RFC but I want this to be discussed first. Also I 
would like to know Xavier's opinion because that affects DBAL. DBAL has its 
own methods like this, which I would copy from the MySQL driver. But still 
I would like to know what people think.

P.S. I know that transactions do not work in MyISAM :)

-- 
Dmitry Dulepov
TYPO3 core&security team member
E-mail: dmitry.dulepov at typo3.org
Web: http://dmitry-dulepov.com/




More information about the TYPO3-dev mailing list