mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:14:04 +00:00
disable new jobs/listeners by default, add CreateTenantStorage job
This commit is contained in:
parent
45aac1a718
commit
a7ad8287e6
3 changed files with 26 additions and 3 deletions
|
|
@ -28,14 +28,16 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
Jobs\CreateDatabase::class,
|
Jobs\CreateDatabase::class,
|
||||||
Jobs\MigrateDatabase::class,
|
Jobs\MigrateDatabase::class,
|
||||||
// Jobs\SeedDatabase::class,
|
// Jobs\SeedDatabase::class,
|
||||||
Jobs\CreateStorageSymlinks::class,
|
|
||||||
|
// Jobs\CreateStorageSymlinks::class,
|
||||||
|
|
||||||
// Your own jobs to prepare the tenant.
|
// Your own jobs to prepare the tenant.
|
||||||
// Provision API keys, create S3 buckets, anything you want!
|
// Provision API keys, create S3 buckets, anything you want!
|
||||||
|
|
||||||
])->send(function (Events\TenantCreated $event) {
|
])->send(function (Events\TenantCreated $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
||||||
|
|
||||||
|
// Listeners\CreateTenantStorage::class,
|
||||||
],
|
],
|
||||||
Events\SavingTenant::class => [],
|
Events\SavingTenant::class => [],
|
||||||
Events\TenantSaved::class => [],
|
Events\TenantSaved::class => [],
|
||||||
|
|
@ -53,7 +55,7 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
Events\TenantDeleted::class => [
|
Events\TenantDeleted::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
Jobs\DeleteDatabase::class,
|
Jobs\DeleteDatabase::class,
|
||||||
Jobs\RemoveStorageSymlinks::class,
|
// Jobs\RemoveStorageSymlinks::class,
|
||||||
])->send(function (Events\TenantDeleted $event) {
|
])->send(function (Events\TenantDeleted $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
|
||||||
|
|
|
||||||
18
src/Listeners/CreateTenantStorage.php
Normal file
18
src/Listeners/CreateTenantStorage.php
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,9 @@ class DeleteTenantStorage
|
||||||
{
|
{
|
||||||
public function handle(DeletingTenant $event): void
|
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()));
|
File::deleteDirectory($event->tenant->run(fn () => storage_path()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue