-
Notifications
You must be signed in to change notification settings - Fork 22
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
Need to find wich field changed or data inserted #9
Comments
Hi @ronisaha do you have an example for saving old_data / new_data as json or something similar? |
You can check sample implementation to store the changed data. You can create your own entity event resolver following that sample. |
@ronisaha with the example it throw
So then I change it to
and I got this error
|
The class definition was not the reason for previous error. The previous error happen if there is problem in yaml formating. The class namespace should use \ instead of /. And the service definition must be under the services block |
The service definition is under service block in service.yml file. And i try both / and . |
Do you have sample project that i can check? Another thing, if you are using autowire configuration with latest version of symfony, you may need to add services: audit_trail.entity_event_resolver: class: MyProject\Bundle\MyBundle\Resolver\EntityEventResolver public: true calls: - [ setContainer, [ "@service_container" ] ] |
@ronisaha with that change and writing |
Check the code here. By calling this function you can get the change set. And in the sample event resolver you can see the exta fields. you have to add some more field in you audit log entity to store the data. You havve the full control how you can save the data, in single field or in separate field. You have to do two thing:
Thats it. |
@ronisaha I got one more question: how do I get the data when created, because $changesMetaData came empty |
On create operation there is no change set, the full object data is new. if you like to store that also you can store the full data by accessing the entity object :) |
can you give me an example? Sorry i'm new on symfony |
Its nothing to do with symfony or this library, you can store serialize string of the entity object. you can implement your serialize method, __toString method, or jms serializer library to get the object data as string and store it in a field. |
Hi @ronisaha , Regarding this topic, the method of saving object - to created and updated events - (or the changeSets - to updated events) data as string in another field of my auditLog entity (called, for example: changeSets), that I'm using is other: only the serialize() php method. What do you think about it in terms of possible problems/advantages/disadvantages? Inside getEventLogInfo() method I have:
Thanks for your view |
Hi @pribeirojtm , I think there is no problem using php serialize for change set. even the example i've provided used serialize function to convert change set to string. But if you want to store whole entity object reference then serialize/unserialize may have some side effect for reference value. Happy coding. |
Thanks for your view @ronisaha , Indeed, I want also to store original entity data when creating new entities or when deleting existent one. Other thing I've stepped in is that sometimes, actions fails... for example, deleting an entity that has its PK present as FK in other entity and it has onDelete restrict, and it fails to delete the parent entity record. Thanks in advance, |
Hi @pribeirojtm , Could you please create another issue with the delete functionality. I'll try to look into that. It would be helpful if you could provide a sample code repository to reproduce the bug. Thanks. |
hello
i want to find when i updated entity,which fields changed with changed value , like this
Table1 and Field1 This Value V1 Changed to V2
(parameter: Table1,Field1,V1,V2)
and when i inserted a data in table this log:
Table1 and Field1 This Value V1 Inserted,Field2 This Value V2 Insertet
(parameter: Table1,Field1,Field2,V1,V2)
for each field in table all of them in one string stored in a row in audit_log table
thank you
The text was updated successfully, but these errors were encountered: