From 0bd58528d28c20d4e42e98ba156d79661fae7ac3 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sat, 8 Aug 2026 13:07:38 +0200 Subject: [PATCH] Make DeleteTenantStorage delete the tenant storage directory regardless of suffix_storage_path The job depended on storage_path(), which is only suffixed when suffix_storage_path is enabled, so with it disabled the tenant's files were left behind. It now uses the bootstrapper's own suffix logic via a new getBoundTenantStoragePath() method.. --- .../FilesystemTenancyBootstrapper.php | 13 ++++++++++ src/Jobs/DeleteTenantStorage.php | 26 +++++++++---------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Bootstrappers/FilesystemTenancyBootstrapper.php b/src/Bootstrappers/FilesystemTenancyBootstrapper.php index 1574ea4b..a00c93c3 100644 --- a/src/Bootstrappers/FilesystemTenancyBootstrapper.php +++ b/src/Bootstrappers/FilesystemTenancyBootstrapper.php @@ -327,4 +327,17 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper { return app(static::class)->originalStoragePath; } + + /** + * Get the storage path of the passed tenant (independent of the current context). + * + * This is the directory the bootstrapper scopes disks, cache and sessions to, + * regardless of suffix_storage_path (that config option only affects the storage_path() helper). + */ + public static function getBoundTenantStoragePath(Tenant $tenant): string + { + $bootstrapper = app(static::class); + + return $bootstrapper->tenantStoragePath($bootstrapper->suffix($tenant)); + } } diff --git a/src/Jobs/DeleteTenantStorage.php b/src/Jobs/DeleteTenantStorage.php index 36a0d326..5dab4dcd 100644 --- a/src/Jobs/DeleteTenantStorage.php +++ b/src/Jobs/DeleteTenantStorage.php @@ -10,8 +10,20 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\File; +use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; +/** + * Delete the tenant's storage directory. + * + * Requires FilesystemTenancyBootstrapper to be enabled, since the deleted directory + * is the one the bootstrapper scopes disks, cache and sessions to. + * + * The job does not depend on the tenancy.filesystem.suffix_storage_path config, + * since it doesn't use the storage_path() helper. + * + * @see Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper + */ class DeleteTenantStorage implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -22,19 +34,7 @@ class DeleteTenantStorage implements ShouldQueue public function handle(): void { - if (config('tenancy.filesystem.suffix_storage_path') === false) { - // Skip storage deletion if path suffixing is disabled - return; - } - - $centralStoragePath = tenancy()->central(fn () => storage_path()); - $tenantStoragePath = tenancy()->run($this->tenant, fn () => storage_path()); - - if ($tenantStoragePath === $centralStoragePath) { - // Check again to ensure the tenant storage path is distinct from the central storage path - // to avoid any accidental central storage path deletion - return; - } + $tenantStoragePath = FilesystemTenancyBootstrapper::getBoundTenantStoragePath($this->tenant); if (is_dir($tenantStoragePath)) { File::deleteDirectory($tenantStoragePath);