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:
parent
080b271bb3
commit
3f60c4a652
5 changed files with 43 additions and 0 deletions
|
|
@ -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 => [],
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/Events/TenantMaintenanceModeDisabled.php
Normal file
10
src/Events/TenantMaintenanceModeDisabled.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class TenantMaintenanceModeDisabled extends Contracts\TenantEvent
|
||||
{
|
||||
//
|
||||
}
|
||||
10
src/Events/TenantMaintenanceModeEnabled.php
Normal file
10
src/Events/TenantMaintenanceModeEnabled.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Events;
|
||||
|
||||
class TenantMaintenanceModeEnabled extends Contracts\TenantEvent
|
||||
{
|
||||
//
|
||||
}
|
||||
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue