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

Guard against accidental central storage deletion

Also fix and improve related test.
This commit is contained in:
lukinovec 2026-04-13 16:36:52 +02:00
parent a28593af17
commit 33c28405ad
2 changed files with 55 additions and 5 deletions

View file

@ -12,6 +12,13 @@ use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\File;
use Stancl\Tenancy\Contracts\Tenant;
/**
* Only delete the tenant storage if storage path suffixing is enabled
* and the tenant's storage path is different from the central storage path.
*
* This is to prevent accidental deletion of the central storage when
* a tenant's storage path is not properly suffixed.
*/
class DeleteTenantStorage implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -22,9 +29,18 @@ class DeleteTenantStorage implements ShouldQueue
public function handle(): void
{
// Skip storage deletion if path suffixing is disabled
if (config('tenancy.filesystem.suffix_storage_path') === false) {
return;
}
$centralPath = tenancy()->central(fn () => storage_path());
$path = tenancy()->run($this->tenant, fn () => storage_path());
if (is_dir($path)) {
// Skip storage deletion if tenant's storage path is the same as central storage path
$tenantPathIsCentral = realpath($path) === realpath($centralPath);
if (is_dir($path) && ! $tenantPathIsCentral) {
File::deleteDirectory($path);
}
}