mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 15:14:03 +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:
parent
3cc7902377
commit
0bd58528d2
2 changed files with 26 additions and 13 deletions
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue