1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 02:24: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) { ])->send(function (Events\DeletingTenant $event) {
return $event->tenant; return $event->tenant;
})->shouldBeQueued(false), })->shouldBeQueued(false),
// Listeners\DeleteTenantStorage::class,
], ],
Events\TenantDeleted::class => [ Events\TenantDeleted::class => [
JobPipeline::make([ JobPipeline::make([
@ -53,7 +55,6 @@ class TenancyServiceProvider extends ServiceProvider
])->send(function (Events\TenantDeleted $event) { ])->send(function (Events\TenantDeleted $event) {
return $event->tenant; return $event->tenant;
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production. })->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
// Listeners\DeleteTenantStorage::class,
], ],
// Domain events // Domain events

View file

@ -5,11 +5,11 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Listeners; namespace Stancl\Tenancy\Listeners;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Stancl\Tenancy\Events\TenantDeleted; use Stancl\Tenancy\Events\DeletingTenant;
class DeleteTenantStorage class DeleteTenantStorage
{ {
public function handle(TenantDeleted $event): void public function handle(DeletingTenant $event): void
{ {
File::deleteDirectory($event->tenant->run(fn () => storage_path())); 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\RedisTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
use Stancl\Tenancy\Events\TenantDeleted; use Stancl\Tenancy\Events\DeletingTenant;
use Stancl\Tenancy\Listeners\DeleteTenantStorage; use Stancl\Tenancy\Listeners\DeleteTenantStorage;
beforeEach(function () { beforeEach(function () {
@ -187,14 +187,14 @@ test('filesystem data is separated', function () {
expect($new_storage_path)->toEqual($expected_storage_path); 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([ config([
'tenancy.bootstrappers' => [ 'tenancy.bootstrappers' => [
FilesystemTenancyBootstrapper::class, FilesystemTenancyBootstrapper::class,
], ],
]); ]);
Event::listen(TenantDeleted::class, DeleteTenantStorage::class); Event::listen(DeletingTenant::class, DeleteTenantStorage::class);
tenancy()->initialize(Tenant::create()); tenancy()->initialize(Tenant::create());
$tenantStoragePath = storage_path(); $tenantStoragePath = storage_path();