spatie / laravel-backup

A package to backup your Laravel app
https://spatie.be/docs/laravel-backup
MIT License
5.64k stars 763 forks source link

Disable notifications prevents BackupWasSuccessful event from firing #1826

Open Aghanimo opened 3 months ago

Aghanimo commented 3 months ago

Describe the bug

When running php artisan backup:run --disable-notifications, the BackupWasSuccessful event does not fire, preventing listeners from executing. Without the flag, the event fires correctly.

Steps to Reproduce

  1. Set up an event listener for Spatie\Backup\Events\BackupWasSuccessful in EventServiceProvider.
  2. Run php artisan backup:run --disable-notifications.
  3. Observe that the listener does not execute.

Expected behavior

The BackupWasSuccessful event should fire regardless of the --disable-notifications flag.

Environment

Additional context

Here is the relevant setup in EventServiceProvider:

protected $listen = [
    Spatie\Backup\Events\BackupWasSuccessful::class => [
        App\Listeners\BackupCompletedListener::class,
    ],
];

public function boot()
{
    parent::boot();

    Event::listen(Spatie\Backup\Events\BackupWasSuccessful::class, function ($event) {
        Log::info('BackupWasSuccessful event fired.');
    });
}

This bug occurs when I want to call backup in code like this:

    $backupJob = BackupJobFactory::createFromArray(config('backup'));
    $backupJob->disableNotifications();

    $backupJob->run();

Thanks To Spatie Team