mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 22:44: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\MigrateDatabase::class,
|
||||
// Jobs\SeedDatabase::class,
|
||||
// Jobs\CreateTenantStorage::class,
|
||||
// Jobs\CreateStorageSymlinks::class,
|
||||
|
||||
// Your own jobs to prepare the tenant.
|
||||
|
|
@ -53,8 +54,6 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
])->send(function (Events\TenantCreated $event) {
|
||||
return $event->tenant;
|
||||
})->shouldBeQueued(false),
|
||||
|
||||
// Listeners\CreateTenantStorage::class,
|
||||
],
|
||||
Events\SavingTenant::class => [],
|
||||
Events\TenantSaved::class => [],
|
||||
|
|
@ -63,12 +62,11 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
Events\DeletingTenant::class => [
|
||||
JobPipeline::make([
|
||||
Jobs\DeleteDomains::class,
|
||||
// Jobs\DeleteTenantStorage::class,
|
||||
// Jobs\RemoveStorageSymlinks::class,
|
||||
])->send(function (Events\DeletingTenant $event) {
|
||||
return $event->tenant;
|
||||
})->shouldBeQueued(false),
|
||||
|
||||
// Listeners\DeleteTenantStorage::class,
|
||||
],
|
||||
Events\TenantDeleted::class => [
|
||||
JobPipeline::make([
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@
|
|||
|
||||
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.
|
||||
|
|
@ -13,11 +18,17 @@ use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
|||
*
|
||||
* 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";
|
||||
|
||||
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\RemoveStorageSymlinks;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Stancl\Tenancy\Listeners\DeleteTenantStorage;
|
||||
use Stancl\Tenancy\Jobs\DeleteTenantStorage;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||
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() {
|
||||
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());
|
||||
$tenantStoragePath = storage_path();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue