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

disable new jobs/listeners by default, add CreateTenantStorage job

This commit is contained in:
Samuel Štancl 2022-12-02 19:43:20 +01:00
parent 45aac1a718
commit a7ad8287e6
3 changed files with 26 additions and 3 deletions

View file

@ -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.

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Listeners;
use Stancl\Tenancy\Events\TenantCreated;
class CreateTenantStorage
{
public function handle(TenantCreated $event): void
{
$storage_path = $event->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)
}
}

View file

@ -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()));
}
}