-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
LogsActivity::$changesPipes should be cleared #1292
Comments
I'm not sure but that sounds more like a PHPUnit |
On horizon it's also booted once as far as I see |
Okay, so after all it comes down to a PHPUnit "problem". As listening for the |
Hello, just debugged the same issue, I've made a quick workaround: <?php
declare(strict_types=1);
namespace App\ActivityLog;
use App\ActivityLog\Pipes\ExcludeUnchangedAttributesPipe;
use Spatie\Activitylog\Contracts\LoggablePipe;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
trait LogsActivityTrait
{
use LogsActivity;
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()->logAll();
}
protected static function bootLogsActivityTrait(): void
{
static::addLogChange(new ExcludeUnchangedAttributesPipe());
}
public static function addLogChange(LoggablePipe $pipe): void
{
static::$changesPipes[$pipe::class] = $pipe; // <<< THE FIX
}
} This ensures that even if a log change pipe is added multiple times, it will still only be added to the pipes array once. |
@Gummibeer Setting the value of @Jacobs63 Nice solution! |
We have a multitenant octane application and are having an issue with this. Our custom trait looks like this: use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity as BaseLogsActivity;
trait LogsActivity
{
use BaseLogsActivity;
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnlyDirty()
->logAll()
->dontSubmitEmptyLogs();
} We're adding the log change before making changes to the model. I think this functionality should be refactored to not be static? |
Looks like this still uses a static property from the pre-Octane days. A new (major?) version should probably rely on the Laravel container with |
Describe the bug
While writing tests we discovered that
LogsActivity::$changesPipes
contains the values of the previous tests. The pipes are added in thebooted()
like in the doc.There is also an Observer registered for the model in the EventServiceProvider which causes the boot.
LogsActivity::$changesPipes
is static and never cleared so with every test the value is incremented with every boot.Creating a model instance in the test also causes this problem.
To Reproduce
Add pipe in model's booted method:
Execute the test:
Dumps:
Expected behavior
LogsActivity::$changesPipes
must be cleared before boot.Versions (please complete the following information)
The text was updated successfully, but these errors were encountered: