1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 21:54:03 +00:00

make Create/DeleteTenantStorage listeners handle existing/missing directories gracefully

This commit is contained in:
Samuel Štancl 2024-07-12 01:53:15 +02:00
parent ac8a30d782
commit aa6bfb4079
2 changed files with 10 additions and 3 deletions

View file

@ -11,8 +11,11 @@ class CreateTenantStorage
public function handle(TenantCreated $event): void public function handle(TenantCreated $event): void
{ {
$storage_path = tenancy()->run($event->tenant, fn () => storage_path()); $storage_path = tenancy()->run($event->tenant, fn () => storage_path());
$cache_path = "$storage_path/framework/cache";
mkdir("$storage_path", 0777, true); // Create the tenant's folder inside storage/ if (! is_dir($cache_path)) {
mkdir("$storage_path/framework/cache", 0777, true); // Create /framework/cache inside the tenant's storage (used for e.g. real-time facades) // Create the tenant's storage directory and /framework/cache within (used for e.g. real-time facades)
mkdir($cache_path, 0777, true);
}
} }
} }

View file

@ -11,6 +11,10 @@ class DeleteTenantStorage
{ {
public function handle(DeletingTenant $event): void public function handle(DeletingTenant $event): void
{ {
File::deleteDirectory(tenancy()->run($event->tenant, fn () => storage_path())); $path = tenancy()->run($event->tenant, fn () => storage_path());
if (is_dir($path)) {
File::deleteDirectory($path);
}
} }
} }