owen-it / laravel-auditing

Record the change log from models in Laravel
https://laravel-auditing.com
MIT License
2.94k stars 383 forks source link

Model's all logs are deleted after v13.6.5 when Threshold is more 0 #950

Closed giolaza closed 6 days ago

giolaza commented 6 days ago

PHP Version

8.1

Laravel Version

9.52.16

Package Version

13.6.7

Description

Default installation used. On version 13.6.5 was working good, but after updating project to 13.6.7 logs stopped. Downgrade helped

Steps To Reproduce

Basic install. Use 13.6.5 - all is good Use 13.6.7 - no logs

Possible Solutions

No response

willpower232 commented 6 days ago

are you able to try 13.6.6 as well? are you able to share your config file?

giolaza commented 6 days ago

checked 13.6.6 same problem config file - audit.php is not published (default used)

additionally i see: log created for model in 13.6.5 is deleted for some reason

willpower232 commented 6 days ago

As per #947 this behaviour happens when the audit.threshold value is higher than 0. Is your code definitely not changing that one value at any point even if the config file isn't used? Can you output the value from php artisan tinker to confirm what it is?

giolaza commented 6 days ago

image

giolaza commented 6 days ago

found issue in vendor/owen-it/laravel-auditing/src/Drivers/Database.php here is db log: \Illuminate\Support\Facades\DB::enableQueryLog(); $model->audits() ->latest() ->offset($threshold)->limit(PHP_INT_MAX) ->delete() > 0; $queries = \Illuminate\Support\Facades\DB::getQueryLog(); dd($queries); delete fromauditswhereaudits.auditable_type= ? andaudits.auditable_id= ? andaudits.auditable_idis not null order bycreated_atdesc limit 9223372036854775807

image image

delete method is ignoring offset method. this is reason why logs are removing("not creating")

giolaza commented 6 days ago

https://github.com/owen-it/laravel-auditing/pull/951

parallels999 commented 6 days ago

If audit.threshold = 0, that delete should never be executed https://github.com/owen-it/laravel-auditing/blob/22682dd5c800aab90ef261530098625e26a66709/src/Drivers/Database.php#L25 unless you have the auditThreshold property on that model, on that case, this would be a duplicate of #947 https://github.com/owen-it/laravel-auditing/blob/22682dd5c800aab90ef261530098625e26a66709/src/Auditable.php#L616-L619

giolaza commented 6 days ago

checked, forgot that in model I set limit for rows 1000000

erikn69 commented 6 days ago

Hi, test new changes on #948