-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: HABTM should also log additional changes #109
Comments
I agree, but without having looked at the code, I'm wondering why it does not do that already. 😕 That should certainly be possible. |
Right now the plugin only checks the IDs in HABTM models (see: https://github.com/robwilkerson/CakePHP-Audit-Log-Plugin/blob/master/Model/Behavior/AuditableBehavior.php#L335). Changing the association to Has Many through should work more reliable and it's the recommended setup for a structure like yours. Changing the HABTM code in the plugin to your use-case is probably not trivial, just because of the different unique options |
@ravage84 I guess @xhs345 comment answers your question. I tried modifying the plugin code to do that for me and ended up braking the plugin itself, so I reverted. 😞 @xhs345 I agree with your suggestion and can give it a try (have never before used
I'm sure it will save my data but I doubt it will log any changes(audit) in Meanwhile, I'll try and find out if my assumptions are correct. |
OK. Here's the update - I replaced https://github.com/robwilkerson/CakePHP-Audit-Log-Plugin/blob/master/Model/Behavior/AuditableBehavior.php#L369-L379 with Let me know if there is a possibility of accepting a PR, I can push the update. It will be easy, I will just check for an additional element, say |
@fr0z3nfyr it's not "my" repo, but I think the plugin should make it possible to save the additional data in HABTM associations. Personally I often use such a setup, too. I guess the best way in this case is a config option that let's the developer decide in each case how much data he wants to save. Can you display an example of how much data is saved now? We shouln't save too much data, though. |
Well, the data is a lot, see -
P.S: Ohh! there I realized that the HABTM data is json encoded twice, solution is to encode it in afterSave function rather than where I was doing. So,
Of course, again based on the config setting from setup (like you mentioned too). I'll fix it at my end. UPDATE: Corrected data for HABTM in
For
Pretty much same size of data for Note that these are just 2 products in 1 PurchaseOrder, in general case, there can be any number of HABTM entries, imagine the data size if there were 50...!! |
Now, thinking of going in reverse direction, instead of setting a boolean config, setting an array of specific columns from each |
@fr0z3nfyr thanks. Can you reformat the whole data with four backticks and proper indentation? It's barely readable like this. 😼 How about:
|
Updated - formatted JSON in code blocks and with proper indentation. 😌 I normally avoid formatting JSON to limit "vertical scroll" on post, if the string is very long. Take a look at http://jsonviewer.stack.hu/ it can format JSON very efficiently. About
Now, I'm also wondering whether there should be a way to set fields from both |
@fr0z3nfyr if data in such a post isn't readable, then it's losing its point 😼 Anyway, I agree we shouldn't overdo with the configuration. But since we are about to add more functionality, I prefer to do it in a flexible way. But I guess, let's hear @xhs345's opinion on that. |
Wow, lots of discussions happening all of a sudden. I like it :)
Almost. The 'typical way' would be
It's explained in more detail in the manual here. I tested it locally and it worked fine for me |
Of course I'm also happy if you could get it to work for HABTM associations and create a PR for it. And thank you @ravage84 for leading the discussion and all your input |
@xhs345 @ravage84 can you please throw some light on CakePHP-Audit-Log-Plugin/Model/Behavior/AuditableBehavior.php Lines 264 to 271 in 3596685
I just realized that I can use Anyways, my work on this issue is in progress, will soon make a PR. |
@xhs345 you are welcome! @fr0z3nfyr Those event callbacks seem to date back to 2010, when the initial commit was made by Rob. 59ca094#diff-a5728d8bda7296e6cd5a6907a113b619R182 I wonder, if we could even rip those out. That would mean, though, we would need to release a 2.x version of the plugin... @fr0z3nfyr if those event callbacks would be fired differently, would they be more useful to you? |
I haven't used the callbacks either, but I can see their use. I think just adding some documentation for then should be a good strategy for now |
I can think of cases where I'd want to trigger create/update/delete notifications to subscribed users or perform some other background tasks like updating inventory etc. I think I just posted hastily without checking |
Feature discussion ref: robwilkerson#109 Added: * additinal config settings - ``ignoreDeep``: boolean; used to ignore specified properties in `ignore` array from HABTM and join table data - ``deepLog``: boolean/Array; used to log all/specified properties of HABTM and join table data Edited: * _getModelData() function - manipulate log data according to config new settings * afterSave() function - `json_encode()` new/old values of a property if deepLog is configured
@xhs345 created a PR #110 just now. I have successfully tested it with my local test instance. Though, I noticed few issues, not related specifically to this PR using with cake-2.6.3. The issue was same as mentioned in this comment. I found a way to fix it by defining Another issue(not so much) I noticed was that the P.S: I can't develop feature in PR for cake 1.3 (I believe that 1.3 branch should be marked as deprecated anyway). I can look into 3.x branch but not immediately. Thanks @xhs345 @ravage84 for all the discussion on this thread. Cheers!! |
@fr0z3nfyr no need for any update on the CakePHP 1.x related branch. https://github.com/robwilkerson/CakePHP-Audit-Log-Plugin#cakephp-13x Could you please create a separate issue detailing the probem with older CakePHP versions? According to the documentation this seems to be intended: /**
* - ignore array, optional
* An array of property names to be ignored when records
* are created in the deltas table.
I understand, you would want to ignore fields when adding records to the Audit table, too? |
In case of HABTM model, the behavior should also log any changes made to additional fields in the HABTM join table.
For example, a
SalesOrder hasAndBelongsToMany Product
while the structure ofproducts_sales_orders
may be something like:and relationship setting be like:
One would definitely want to log any changes made to the associated products' extra fields like
description
,quantity
,discount
etc. Can you think of a way to achieve this with existing setup? Is the suggested enhancement too specific or difficult to include in plugin?The text was updated successfully, but these errors were encountered: