lorenzo / audit-stash

Flexible and rock solid audit log tracking for CakePHP 3
MIT License
78 stars 37 forks source link

Inserting stringifiable objects #38

Closed Ali1 closed 5 years ago

Ali1 commented 5 years ago

I use Chronos quite a lot and I'm in the habit of inserting dates using like this $entity->cancelled = Chronos::now() (without ->toDateTimeString()) because during marshalling, they are automatically converted to strings.

I've just realised that it's being audited as a json object string:

(Cake\ORM\Entity)
id 1855
type update
...
original {"cancelled":null}
changed {"cancelled":{"date":"2019-04-23 12:09:18.393806","timezone_type":3,"timezone":"Europe\/London"}}
...
created (Cake\I18n\Time)

You reckon changed properties could be forced into becoming strings in the audit log too to avoid the below? Or are there times when it's useful to have the whole object?

lorenzo commented 5 years ago

If you use FrozenTime::now(), you should get the date serialized as a string, if I remember correctly. FrozenTime is the subclass of Chronos that better integrates with the framework.

Ali1 commented 5 years ago

Yes works perfectly, a nice string now appears. Thank you!