1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 13:34:04 +00:00

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..
This commit is contained in:
lukinovec 2026-08-08 13:07:38 +02:00 committed by Samuel Stancl
parent 3cc7902377
commit 0bd58528d2
2 changed files with 26 additions and 13 deletions

View file

@ -327,4 +327,17 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
{ {
return app(static::class)->originalStoragePath; 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));
}
} }

View file

@ -10,8 +10,20 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant; 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 class DeleteTenantStorage implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -22,19 +34,7 @@ class DeleteTenantStorage implements ShouldQueue
public function handle(): void public function handle(): void
{ {
if (config('tenancy.filesystem.suffix_storage_path') === false) { $tenantStoragePath = FilesystemTenancyBootstrapper::getBoundTenantStoragePath($this->tenant);
// 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;
}
if (is_dir($tenantStoragePath)) { if (is_dir($tenantStoragePath)) {
File::deleteDirectory($tenantStoragePath); File::deleteDirectory($tenantStoragePath);