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;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'tenancy:down
|
||||
protected $signature = 'tenants:down
|
||||
{--redirect= : The path that users should be redirected to}
|
||||
{--retry= : The number of seconds after which the request may be retried}
|
||||
{--refresh= : The number of seconds after which the browser may refresh}
|
||||
{--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}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Put tenants into maintenance';
|
||||
protected $description = 'Put tenants into maintenance mode.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
// 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
|
||||
|
|
@ -52,12 +37,7 @@ class Down extends DownCommand
|
|||
$this->comment('Tenants are now in maintenance mode.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the payload to be placed in the "down" file.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
/** Get the payload to be placed in the "down" file. */
|
||||
protected function getDownDatabasePayload()
|
||||
{
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -11,30 +11,13 @@ class Up extends Command
|
|||
{
|
||||
use HasATenantsOption;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'tenants:up';
|
||||
|
||||
protected $signature = 'tenancy:up';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Put tenants out of maintenance';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): void
|
||||
{
|
||||
// This runs for all tenants if no --tenants are specified
|
||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
||||
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']}");
|
||||
$tenant->bringUpFromMaintenance();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Database\Concerns;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
trait MaintenanceMode
|
||||
{
|
||||
public function putDownForMaintenance($data = [])
|
||||
public function putDownForMaintenance($data = []): void
|
||||
{
|
||||
$this->update([
|
||||
'maintenance_mode' => [
|
||||
|
|
@ -20,7 +23,7 @@ trait MaintenanceMode
|
|||
]);
|
||||
}
|
||||
|
||||
public function bringUpFromMaintenance()
|
||||
public function bringUpFromMaintenance(): void
|
||||
{
|
||||
$this->update(['maintenance_mode' => null]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
|
|||
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)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,13 +55,13 @@ test('tenant can be in maintenance mode from command', function() {
|
|||
|
||||
tenancy()->end(); // Flush stored tenant instance
|
||||
|
||||
Artisan::call('tenancy:down');
|
||||
Artisan::call('tenants:down');
|
||||
|
||||
pest()->get('http://acme.localhost/foo')->assertStatus(503);
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
Artisan::call('tenancy:up');
|
||||
Artisan::call('tenants:up');
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue