The archive table format doesn't support transactions, so my existing solution could show history for an update that never occurred, as a result of the actual changes being rolled back.
I've thought of a way to solve this:
- Override CDbTransaction
- Add a private array to hold the outstanding history
- Add a method to append to the history array (called from the behavior)
- Override CDbTransaction::commit() to save all history after calling the parent implementation
- Update the behavior to log history to the active transaction if there is one, or output straight to the history table if not
This would enable the history to be logged only if the transaction completes successfully.
Unfortunately, the CDbTransaction class is hardcoded in CDbConnection::beginTransaction().
I'm intending to extend CDbConnection and override the beginTransaction() method, so that I can instantiate my new transaction class.
Is this the best way to approach this problem, or is there a more sensible option?