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

Add maintenance mode events (#979)

This commit is contained in:
Jori Stein 2022-10-17 13:48:24 -04:00 committed by GitHub
parent 080b271bb3
commit 3f60c4a652
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 0 deletions

View file

@ -58,6 +58,8 @@ class TenancyServiceProvider extends ServiceProvider
return $event->tenant;
})->shouldBeQueued(false), // `false` by default, but you probably want to make this `true` for production.
],
Events\TenantMaintenanceModeEnabled::class => [],
Events\TenantMaintenanceModeDisabled::class => [],
// Domain events
Events\CreatingDomain::class => [],

View file

@ -3,6 +3,8 @@
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Events\TenantMaintenanceModeDisabled;
use Stancl\Tenancy\Events\TenantMaintenanceModeEnabled;
/**
* @mixin \Illuminate\Database\Eloquent\Model
@ -21,10 +23,14 @@ trait MaintenanceMode
'status' => $data['status'] ?? 503,
],
]);
event(new TenantMaintenanceModeEnabled($this));
}
public function bringUpFromMaintenance(): void
{
$this->update(['maintenance_mode' => null]);
event(new TenantMaintenanceModeDisabled($this));
}
}

View file

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenantMaintenanceModeDisabled extends Contracts\TenantEvent
{
//
}

View file

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Events;
class TenantMaintenanceModeEnabled extends Contracts\TenantEvent
{
//
}

View file

@ -3,6 +3,7 @@
declare(strict_types=1);
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Database\Concerns\MaintenanceMode;
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Middleware\CheckTenantForMaintenanceMode;
@ -32,6 +33,20 @@ test('tenants can be in maintenance mode', function () {
pest()->get('http://acme.localhost/foo')->assertStatus(200);
});
test('maintenance mode events are fired', function () {
$tenant = MaintenanceTenant::create();
Event::fake();
$tenant->putDownForMaintenance();
Event::assertDispatched(\Stancl\Tenancy\Events\TenantMaintenanceModeEnabled::class);
$tenant->bringUpFromMaintenance();
Event::assertDispatched(\Stancl\Tenancy\Events\TenantMaintenanceModeDisabled::class);
});
test('tenants can be put into maintenance mode using artisan commands', function() {
Route::get('/foo', function () {
return 'bar';