WildsideUK / Laravel-Userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created_by` and `updated_by` columns on your model, populated by the currently authenticated user in your application.
https://wildside.uk
MIT License
570 stars 64 forks source link

The 'update' events are getting fired on deletion #23

Closed mazyvan closed 5 years ago

mazyvan commented 6 years ago

I have this little issue.

I have a listener on the model updated event to send a mail. But I'm facing right now that the delete method first updated my record (to store the deleted_by field) and then proceed with the actual delete.

Check this logs for example

[2018-09-12 16:02:53] local.INFO: Model saving  
[2018-09-12 16:02:53] local.INFO: {"id":9,"total":"0.00","notas":null,"accepted_at":"2018-09-12 16:02:03","cotizable_id":0,"cotizable_type":"","cliente_id":null,"deleted_at":null,"deleted_by":1,"created_at":"2018-09-12 16:01:58","created_by":1,"updated_at":"2018-09-12 16:02:16","updated_by":1}  
[2018-09-12 16:02:53] local.INFO: Model updating  
[2018-09-12 16:02:53] local.INFO: {"id":9,"total":"0.00","notas":null,"accepted_at":"2018-09-12 16:02:03","cotizable_id":0,"cotizable_type":"","cliente_id":null,"deleted_at":null,"deleted_by":1,"created_at":"2018-09-12 16:01:58","created_by":1,"updated_at":"2018-09-12 16:02:16","updated_by":1}  
[2018-09-12 16:02:53] local.INFO: Model updated  
[2018-09-12 16:02:53] local.INFO: {"id":9,"total":"0.00","notas":null,"accepted_at":"2018-09-12 16:02:03","cotizable_id":0,"cotizable_type":"","cliente_id":null,"deleted_at":null,"deleted_by":1,"created_at":"2018-09-12 16:01:58","created_by":1,"updated_at":"2018-09-12 16:02:53","updated_by":1}  
[2018-09-12 16:02:53] local.INFO: Model saved  
[2018-09-12 16:02:53] local.INFO: {"id":9,"total":"0.00","notas":null,"accepted_at":"2018-09-12 16:02:03","cotizable_id":0,"cotizable_type":"","cliente_id":null,"deleted_at":null,"deleted_by":1,"created_at":"2018-09-12 16:01:58","created_by":1,"updated_at":"2018-09-12 16:02:53","updated_by":1}  
[2018-09-12 16:02:53] local.INFO: Model deleting  
[2018-09-12 16:02:53] local.INFO: {"id":9,"total":"0.00","notas":null,"accepted_at":"2018-09-12 16:02:03","cotizable_id":0,"cotizable_type":"","cliente_id":null,"deleted_at":null,"deleted_by":1,"created_at":"2018-09-12 16:01:58","created_by":1,"updated_at":"2018-09-12 16:02:53","updated_by":1}  
[2018-09-12 16:02:53] local.INFO: Model deleted  
[2018-09-12 16:02:53] local.INFO: {"id":9,"total":"0.00","notas":null,"accepted_at":"2018-09-12 16:02:03","cotizable_id":0,"cotizable_type":"","cliente_id":null,"deleted_at":"2018-09-12 16:02:53","deleted_by":1,"created_at":"2018-09-12 16:01:58","created_by":1,"updated_at":"2018-09-12 16:02:53","updated_by":1}  

I've look at the code and I have a solution that has not issues with this #7 or rather the prevention of future events from being fired AFAIK