CakePHP-Audit-Log-Plugin icon indicating copy to clipboard operation
CakePHP-Audit-Log-Plugin copied to clipboard

Using Auditable with the Translate behavior

Open cdvrooman opened this issue 13 years ago • 4 comments
trafficstars

I just started using your plugin with my CakePHP 2.x installation and so far, so good.

Then I saved some translated data to the I18n table associated with the Translate behavior, but there was no corresponding entry in the audits table.

Both the primary and I18n models are set to $actAs = array('AuditLog.Auditable'); but only the primary model causes Auditable to store the corresponding data.

I'm not saying this is necessarily unexpected, just that it would be useful if there was something similar to the 'habtm' switch which could cause a table related via a behavior (perhaps not only Translate), to save its data as well.

I tried wrapping my head around using the 'afterAuditCreate' method to accomplish what I want, but since I am trying to make an associated model save its data from the primary model, I'm at a loss.

Perhaps you have run across this situation and can point me in the right direction?

cdvrooman avatar Oct 09 '12 02:10 cdvrooman

The callbacks are the right way to go, but can only work, of course, if the associated data is passed. I'm not sure that's the case. I'm somewhat loathe to allow an option to save arbitrary associated data in the log (the idea being that each model should be auditable in its own right), but the Translate bits are a bit of a unique scenario. I'll have to think about that. I'm not aware of any way to determine whether an association is behavior-driven, but maybe there's another way.

robwilkerson avatar Oct 18 '12 16:10 robwilkerson

Thanks for taking a shot at it and if I get any closer, I'll let you know.

cdvrooman avatar Oct 20 '12 14:10 cdvrooman

Rob, I ran into a case where the table associated with a behavior of a plugin I was using was not firing Auditable for edits although the table was actsAs Auditable. I found a way to make things work, which coincidentally may take care of this issue and another one, namely adding existing data in a table into the Audit table so subsequent changes will be added to the AuditDelta table.

I can understand if you're against what I'm proposing, because it involves a bit of manual work instead of just Cakey goodness; however, the existing unit tests are still all green.

Basically, I moved almost everything out of the afterSave method into a separate method so it can be called externally as well as internally. I also added a getter and setter method as well as a second 'original' property to hold existing data gathered prior to a save to make it possible to force an EDIT entry in the Audit table and correspoding entries in the AuditDelta table.

To be honest, my test case of the scenario in the previous paragraph works with the aforementioned plugin that was causing me grief but I still have to see if I can create a similar scenario as a bona fide Auditable test case.

I have to polish some things up and I want to get Translate working as well. However, when I've got everything together I'll post a pull request so you can scope it out.

cdvrooman avatar Nov 29 '12 04:11 cdvrooman

@xhs345 I guess we can close this due to inactivity and more, e.g. @robwilkerson closed the (partly?) related PR #15 due to inactivity. It looks, that @cdvrooman has long moved away from CakePHP, too.

ravage84 avatar Sep 20 '16 23:09 ravage84