mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-07 11:54:04 +00:00
Change tenant storage listeners into jobs
Also move the commented jobs to the JobPipelines and update FilesystemTenancyBootstrapperTest accordingly.
This commit is contained in:
parent
c4960b76cb
commit
bf42a12894
5 changed files with 55 additions and 31 deletions
|
|
@ -46,6 +46,7 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
Jobs\CreateDatabase::class,
|
Jobs\CreateDatabase::class,
|
||||||
Jobs\MigrateDatabase::class,
|
Jobs\MigrateDatabase::class,
|
||||||
// Jobs\SeedDatabase::class,
|
// Jobs\SeedDatabase::class,
|
||||||
|
// Jobs\CreateTenantStorage::class,
|
||||||
// Jobs\CreateStorageSymlinks::class,
|
// Jobs\CreateStorageSymlinks::class,
|
||||||
|
|
||||||
// Your own jobs to prepare the tenant.
|
// Your own jobs to prepare the tenant.
|
||||||
|
|
@ -53,8 +54,6 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
])->send(function (Events\TenantCreated $event) {
|
])->send(function (Events\TenantCreated $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(false),
|
})->shouldBeQueued(false),
|
||||||
|
|
||||||
// Listeners\CreateTenantStorage::class,
|
|
||||||
],
|
],
|
||||||
Events\SavingTenant::class => [],
|
Events\SavingTenant::class => [],
|
||||||
Events\TenantSaved::class => [],
|
Events\TenantSaved::class => [],
|
||||||
|
|
@ -63,12 +62,11 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
Events\DeletingTenant::class => [
|
Events\DeletingTenant::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
Jobs\DeleteDomains::class,
|
Jobs\DeleteDomains::class,
|
||||||
|
// Jobs\DeleteTenantStorage::class,
|
||||||
// Jobs\RemoveStorageSymlinks::class,
|
// Jobs\RemoveStorageSymlinks::class,
|
||||||
])->send(function (Events\DeletingTenant $event) {
|
])->send(function (Events\DeletingTenant $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->shouldBeQueued(false),
|
})->shouldBeQueued(false),
|
||||||
|
|
||||||
// Listeners\DeleteTenantStorage::class,
|
|
||||||
],
|
],
|
||||||
Events\TenantDeleted::class => [
|
Events\TenantDeleted::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Listeners;
|
namespace Stancl\Tenancy\Jobs;
|
||||||
|
|
||||||
use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to manually create framework directories in the tenant storage when storage_path() is scoped.
|
* Can be used to manually create framework directories in the tenant storage when storage_path() is scoped.
|
||||||
|
|
@ -13,11 +18,17 @@ use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
||||||
*
|
*
|
||||||
* Generally not needed anymore as the directory is also created by the FilesystemTenancyBootstrapper.
|
* Generally not needed anymore as the directory is also created by the FilesystemTenancyBootstrapper.
|
||||||
*/
|
*/
|
||||||
class CreateTenantStorage
|
class CreateTenantStorage implements ShouldQueue
|
||||||
{
|
{
|
||||||
public function handle(TenantEvent $event): void
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public Tenant $tenant,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$storage_path = tenancy()->run($event->tenant, fn () => storage_path());
|
$storage_path = tenancy()->run($this->tenant, fn () => storage_path());
|
||||||
$cache_path = "$storage_path/framework/cache";
|
$cache_path = "$storage_path/framework/cache";
|
||||||
|
|
||||||
if (! is_dir($cache_path)) {
|
if (! is_dir($cache_path)) {
|
||||||
31
src/Jobs/DeleteTenantStorage.php
Normal file
31
src/Jobs/DeleteTenantStorage.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
|
class DeleteTenantStorage implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public Tenant $tenant,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$path = tenancy()->run($this->tenant, fn () => storage_path());
|
||||||
|
|
||||||
|
if (is_dir($path)) {
|
||||||
|
File::deleteDirectory($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Listeners;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
|
||||||
|
|
||||||
class DeleteTenantStorage
|
|
||||||
{
|
|
||||||
public function handle(TenantEvent $event): void
|
|
||||||
{
|
|
||||||
$path = tenancy()->run($event->tenant, fn () => storage_path());
|
|
||||||
|
|
||||||
if (is_dir($path)) {
|
|
||||||
File::deleteDirectory($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -13,7 +13,7 @@ use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
use Stancl\Tenancy\Jobs\CreateStorageSymlinks;
|
use Stancl\Tenancy\Jobs\CreateStorageSymlinks;
|
||||||
use Stancl\Tenancy\Jobs\RemoveStorageSymlinks;
|
use Stancl\Tenancy\Jobs\RemoveStorageSymlinks;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
use Stancl\Tenancy\Listeners\DeleteTenantStorage;
|
use Stancl\Tenancy\Jobs\DeleteTenantStorage;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||||
use function Stancl\Tenancy\Tests\pest;
|
use function Stancl\Tenancy\Tests\pest;
|
||||||
|
|
@ -185,7 +185,11 @@ test('create and delete storage symlinks jobs work', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenant storage can get deleted after the tenant when DeletingTenant listens to DeleteTenantStorage', function() {
|
test('tenant storage can get deleted after the tenant when DeletingTenant listens to DeleteTenantStorage', function() {
|
||||||
Event::listen(DeletingTenant::class, DeleteTenantStorage::class);
|
Event::listen(DeletingTenant::class,
|
||||||
|
JobPipeline::make([DeleteTenantStorage::class])->send(function (DeletingTenant $event) {
|
||||||
|
return $event->tenant;
|
||||||
|
})->shouldBeQueued(false)->toListener()
|
||||||
|
);
|
||||||
|
|
||||||
tenancy()->initialize(Tenant::create());
|
tenancy()->initialize(Tenant::create());
|
||||||
$tenantStoragePath = storage_path();
|
$tenantStoragePath = storage_path();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue