From 97e856616cde8e4fb447047cac8384064e1fe10a Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 20 Apr 2026 09:05:26 +0200 Subject: [PATCH] Add deprecated listener versions of the storage jobs Without this, updating Tenancy in existing projects would break TenancyServiceProvider. The logic of the deprecated versions is up-to-date with the changes made in the jobs up until now. --- src/Listeners/CreateTenantStorage.php | 24 ++++++++++++++++++++ src/Listeners/DeleteTenantStorage.php | 32 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/Listeners/CreateTenantStorage.php create mode 100644 src/Listeners/DeleteTenantStorage.php diff --git a/src/Listeners/CreateTenantStorage.php b/src/Listeners/CreateTenantStorage.php new file mode 100644 index 00000000..3210a050 --- /dev/null +++ b/src/Listeners/CreateTenantStorage.php @@ -0,0 +1,24 @@ +run($event->tenant, fn () => storage_path()); + $cache_path = "$storage_path/framework/cache"; + + 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, 0750, true); + } + } +} diff --git a/src/Listeners/DeleteTenantStorage.php b/src/Listeners/DeleteTenantStorage.php new file mode 100644 index 00000000..c32e14ba --- /dev/null +++ b/src/Listeners/DeleteTenantStorage.php @@ -0,0 +1,32 @@ +central(fn () => storage_path()); + $path = tenancy()->run($event->tenant, fn () => storage_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); + } + } +}