Hello guys,
I need some help. I need to create a log for sql operations for audit control. Which should occur permanently.
I tried behaviors + before delete / update but I found some problem with delete operations (eg. deleteAll). Whereas some operations do not trigger the beforeDelete, etc …
I tried to use the Audit Trail 2 extension and also still fails. It did not work the way I need.
Anyone have any idea how to have a AuditTrail features with deleteAll register?
I don’t want Debug the application. I need to save operations as AuditTrail but there are operations like deleteall I need to write to log.
Any ideas?
Thank you in advance for help.
You can override deleteAll() or use delete() in foreach.
Also you can create some DB triggers to log operation.
Default implementation uses simple sql query (DELETE FROM … WHERE …), so no AR, behaviors etc is involved.
I was thinking, has some parts of the application using Yii::app()->db->createCommand($sql), which would be a problem since it would not use deleteAll. So it would be better to try to implement the trigger.
But, is there any way to intercept the sql command that runs through Yii::app()->db->createCommand($sql)->execute? I prefer to try to keep the whole implementation in Yii / php.
Any idea how this could be done?
Thank you in advance for help.
I think you can try to extend db component and override createCommand.
Havent tried it by myself though.
(you need to set a ‘class’ property in component config under ‘components’ section of config/main.php, like this: ‘class’=>‘MyOwnDbClass’)