diff --git a/assets/TenancyServiceProvider.stub.php b/assets/TenancyServiceProvider.stub.php index 3092c428..6735b37f 100644 --- a/assets/TenancyServiceProvider.stub.php +++ b/assets/TenancyServiceProvider.stub.php @@ -28,14 +28,16 @@ class TenancyServiceProvider extends ServiceProvider Jobs\CreateDatabase::class, Jobs\MigrateDatabase::class, // Jobs\SeedDatabase::class, - Jobs\CreateStorageSymlinks::class, + + // Jobs\CreateStorageSymlinks::class, // Your own jobs to prepare the tenant. // Provision API keys, create S3 buckets, anything you want! - ])->send(function (Events\TenantCreated $event) { return $event->tenant; })->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production. + + // Listeners\CreateTenantStorage::class, ], Events\SavingTenant::class => [], Events\TenantSaved::class => [], @@ -53,7 +55,7 @@ class TenancyServiceProvider extends ServiceProvider Events\TenantDeleted::class => [ JobPipeline::make([ Jobs\DeleteDatabase::class, - Jobs\RemoveStorageSymlinks::class, + // Jobs\RemoveStorageSymlinks::class, ])->send(function (Events\TenantDeleted $event) { return $event->tenant; })->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production. diff --git a/src/Listeners/CreateTenantStorage.php b/src/Listeners/CreateTenantStorage.php new file mode 100644 index 00000000..51fa9d23 --- /dev/null +++ b/src/Listeners/CreateTenantStorage.php @@ -0,0 +1,18 @@ +tenant->run(fn () => storage_path()); + + 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) + } +} diff --git a/src/Listeners/DeleteTenantStorage.php b/src/Listeners/DeleteTenantStorage.php index ce1a4203..9cc1daae 100644 --- a/src/Listeners/DeleteTenantStorage.php +++ b/src/Listeners/DeleteTenantStorage.php @@ -11,6 +11,9 @@ class DeleteTenantStorage { public function handle(DeletingTenant $event): void { + // todo@lukas since this is using the 'File' facade instead of low-level PHP functions, Tenancy might affect this? + // Therefore, when Tenancy is initialized, this might look INSIDE the tenant's storage, instead of the main storage dir? + // The DeletingTenant event will be fired in the central context in 99% of cases, but sometimes it might run in the tenant context (from another tenant) so we want to make sure this works well in all contexts. File::deleteDirectory($event->tenant->run(fn () => storage_path())); } }