mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
improve code
This commit is contained in:
parent
0a2bbc5a16
commit
f478038644
5 changed files with 15 additions and 49 deletions
|
|
@ -11,31 +11,16 @@ class Down extends DownCommand
|
||||||
{
|
{
|
||||||
use HasATenantsOption;
|
use HasATenantsOption;
|
||||||
|
|
||||||
/**
|
protected $signature = 'tenants:down
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'tenancy:down
|
|
||||||
{--redirect= : The path that users should be redirected to}
|
{--redirect= : The path that users should be redirected to}
|
||||||
{--retry= : The number of seconds after which the request may be retried}
|
{--retry= : The number of seconds after which the request may be retried}
|
||||||
{--refresh= : The number of seconds after which the browser may refresh}
|
{--refresh= : The number of seconds after which the browser may refresh}
|
||||||
{--secret= : The secret phrase that may be used to bypass maintenance mode}
|
{--secret= : The secret phrase that may be used to bypass maintenance mode}
|
||||||
{--status=503 : The status code that should be used when returning the maintenance mode response}';
|
{--status=503 : The status code that should be used when returning the maintenance mode response}';
|
||||||
|
|
||||||
/**
|
protected $description = 'Put tenants into maintenance mode.';
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Put tenants into maintenance';
|
|
||||||
|
|
||||||
/**
|
public function handle(): void
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
// The base down command is heavily used. Instead of saving the data inside a file,
|
// The base down command is heavily used. Instead of saving the data inside a file,
|
||||||
// the data is stored the tenant database, which means some Laravel features
|
// the data is stored the tenant database, which means some Laravel features
|
||||||
|
|
@ -52,12 +37,7 @@ class Down extends DownCommand
|
||||||
$this->comment('Tenants are now in maintenance mode.');
|
$this->comment('Tenants are now in maintenance mode.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the payload to be placed in the "down" file. */
|
||||||
/**
|
|
||||||
* Get the payload to be placed in the "down" file.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getDownDatabasePayload()
|
protected function getDownDatabasePayload()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
|
|
@ -11,30 +11,13 @@ class Up extends Command
|
||||||
{
|
{
|
||||||
use HasATenantsOption;
|
use HasATenantsOption;
|
||||||
|
|
||||||
/**
|
protected $signature = 'tenants:up';
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected $signature = 'tenancy:up';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Put tenants out of maintenance';
|
protected $description = 'Put tenants out of maintenance';
|
||||||
|
|
||||||
/**
|
public function handle(): void
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
{
|
||||||
// This runs for all tenants if no --tenants are specified
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
||||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
|
||||||
$this->line("Tenant: {$tenant['id']}");
|
$this->line("Tenant: {$tenant['id']}");
|
||||||
$tenant->bringUpFromMaintenance();
|
$tenant->bringUpFromMaintenance();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,12 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Database\Concerns;
|
namespace Stancl\Tenancy\Database\Concerns;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @mixin \Illuminate\Database\Eloquent\Model
|
||||||
|
*/
|
||||||
trait MaintenanceMode
|
trait MaintenanceMode
|
||||||
{
|
{
|
||||||
public function putDownForMaintenance($data = [])
|
public function putDownForMaintenance($data = []): void
|
||||||
{
|
{
|
||||||
$this->update([
|
$this->update([
|
||||||
'maintenance_mode' => [
|
'maintenance_mode' => [
|
||||||
|
|
@ -20,7 +23,7 @@ trait MaintenanceMode
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bringUpFromMaintenance()
|
public function bringUpFromMaintenance(): void
|
||||||
{
|
{
|
||||||
$this->update(['maintenance_mode' => null]);
|
$this->update(['maintenance_mode' => null]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
|
||||||
return $this->bypassResponse($data['secret']);
|
return $this->bypassResponse($data['secret']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version_compare($this->app->version(), '8.0.0') >= 0 && $this->hasValidBypassCookie($request, $data) ||
|
if (version_compare($this->app->version(), '8.0.0', '>=') && $this->hasValidBypassCookie($request, $data) ||
|
||||||
$this->inExceptArray($request)) {
|
$this->inExceptArray($request)) {
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,13 @@ test('tenant can be in maintenance mode from command', function() {
|
||||||
|
|
||||||
tenancy()->end(); // Flush stored tenant instance
|
tenancy()->end(); // Flush stored tenant instance
|
||||||
|
|
||||||
Artisan::call('tenancy:down');
|
Artisan::call('tenants:down');
|
||||||
|
|
||||||
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
Artisan::call('tenancy:up');
|
Artisan::call('tenants:up');
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue