From aa6bfb4079868d7070719a4a851c7808f77adfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 12 Jul 2024 01:53:15 +0200 Subject: [PATCH] make Create/DeleteTenantStorage listeners handle existing/missing directories gracefully --- src/Listeners/CreateTenantStorage.php | 7 +++++-- src/Listeners/DeleteTenantStorage.php | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Listeners/CreateTenantStorage.php b/src/Listeners/CreateTenantStorage.php index ac33bb52..73da89fc 100644 --- a/src/Listeners/CreateTenantStorage.php +++ b/src/Listeners/CreateTenantStorage.php @@ -11,8 +11,11 @@ class CreateTenantStorage public function handle(TenantCreated $event): void { $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/ - mkdir("$storage_path/framework/cache", 0777, true); // Create /framework/cache inside the tenant's storage (used for e.g. real-time facades) + if (! is_dir($cache_path)) { + // Create the tenant's storage directory and /framework/cache within (used for e.g. real-time facades) + mkdir($cache_path, 0777, true); + } } } diff --git a/src/Listeners/DeleteTenantStorage.php b/src/Listeners/DeleteTenantStorage.php index adbcd3db..25adc4f4 100644 --- a/src/Listeners/DeleteTenantStorage.php +++ b/src/Listeners/DeleteTenantStorage.php @@ -11,6 +11,10 @@ class DeleteTenantStorage { 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); + } } }