1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 18:14:04 +00:00

Move tenant storage deletion to the DeletingTenant event

This commit is contained in:
lukinovec 2022-09-20 16:02:13 +02:00
parent 1b31bdb56b
commit 608c28cf33
3 changed files with 7 additions and 6 deletions

View file

@ -46,6 +46,8 @@ class TenancyServiceProvider extends ServiceProvider
])->send(function (Events\DeletingTenant $event) {
return $event->tenant;
})->shouldBeQueued(false),
// Listeners\DeleteTenantStorage::class,
],
Events\TenantDeleted::class => [
JobPipeline::make([
@ -53,7 +55,6 @@ class TenancyServiceProvider extends ServiceProvider
])->send(function (Events\TenantDeleted $event) {
return $event->tenant;
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
// Listeners\DeleteTenantStorage::class,
],
// Domain events

View file

@ -5,11 +5,11 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Listeners;
use Illuminate\Support\Facades\File;
use Stancl\Tenancy\Events\TenantDeleted;
use Stancl\Tenancy\Events\DeletingTenant;
class DeleteTenantStorage
{
public function handle(TenantDeleted $event): void
public function handle(DeletingTenant $event): void
{
File::deleteDirectory($event->tenant->run(fn () => storage_path()));
}

View file

@ -22,7 +22,7 @@ use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
use Stancl\Tenancy\Events\TenantDeleted;
use Stancl\Tenancy\Events\DeletingTenant;
use Stancl\Tenancy\Listeners\DeleteTenantStorage;
beforeEach(function () {
@ -187,14 +187,14 @@ test('filesystem data is separated', function () {
expect($new_storage_path)->toEqual($expected_storage_path);
});
test('tenant storage can get deleted after the tenant when TenantDeleted listens to DeleteTenantStorage', function () {
test('tenant storage can get deleted after the tenant when DeletingTenant listens to DeleteTenantStorage', function () {
config([
'tenancy.bootstrappers' => [
FilesystemTenancyBootstrapper::class,
],
]);
Event::listen(TenantDeleted::class, DeleteTenantStorage::class);
Event::listen(DeletingTenant::class, DeleteTenantStorage::class);
tenancy()->initialize(Tenant::create());
$tenantStoragePath = storage_path();