mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
clean
This commit is contained in:
parent
c90ae845e9
commit
b97f409ee3
4 changed files with 33 additions and 15 deletions
|
|
@ -5,9 +5,11 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Commands;
|
namespace Stancl\Tenancy\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Foundation\Console\DownCommand;
|
||||||
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
class Down extends Command
|
class Down extends DownCommand
|
||||||
{
|
{
|
||||||
use HasATenantsOption;
|
use HasATenantsOption;
|
||||||
|
|
||||||
|
|
@ -37,17 +39,34 @@ class Down extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
// 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
|
||||||
|
// are not available with tenants.
|
||||||
|
|
||||||
|
$payload = $this->getDownDatabasePayload();
|
||||||
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) use ($payload){
|
||||||
$this->line("Tenant: {$tenant['id']}");
|
$this->line("Tenant: {$tenant['id']}");
|
||||||
$tenant->putDownForMaintenance([
|
$tenant->putDownForMaintenance($payload);
|
||||||
'redirect' => $this->option('redirect'),
|
|
||||||
'retry' => $this->option('retry'),
|
|
||||||
'refresh' => $this->option('refresh'),
|
|
||||||
'secret' => $this->option('secret'),
|
|
||||||
'status' => $this->option('status'),
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$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.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getDownDatabasePayload()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'except' => $this->excludedPaths(),
|
||||||
|
'redirect' => $this->redirectPath(),
|
||||||
|
'retry' => $this->getRetryTime(),
|
||||||
|
'refresh' => $this->option('refresh'),
|
||||||
|
'secret' => $this->option('secret'),
|
||||||
|
'status' => (int) $this->option('status', 503),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ trait MaintenanceMode
|
||||||
{
|
{
|
||||||
$this->update([
|
$this->update([
|
||||||
'maintenance_mode' => [
|
'maintenance_mode' => [
|
||||||
|
'except' => $data['except'] ?? null,
|
||||||
'redirect' => $data['redirect'] ?? null,
|
'redirect' => $data['redirect'] ?? null,
|
||||||
'retry' => $data['retry'] ?? null,
|
'retry' => $data['retry'] ?? null,
|
||||||
'refresh' => $data['refresh'] ?? null,
|
'refresh' => $data['refresh'] ?? null,
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,13 @@ class CheckTenantForMaintenanceMode extends CheckForMaintenanceMode
|
||||||
if (isset($data['template'])) {
|
if (isset($data['template'])) {
|
||||||
return response(
|
return response(
|
||||||
$data['template'],
|
$data['template'],
|
||||||
(int) $data['status'] ?? 503,
|
(int) ($data['status'] ?? 503),
|
||||||
$this->getHeaders($data)
|
$this->getHeaders($data)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
(int) $data['status'] ?? 503,
|
(int) ($data['status'] ?? 503),
|
||||||
'Service Unavailable',
|
'Service Unavailable',
|
||||||
null,
|
null,
|
||||||
$this->getHeaders($data)
|
$this->getHeaders($data)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ test('tenant can be in maintenance mode', function () {
|
||||||
$tenant->putDownForMaintenance();
|
$tenant->putDownForMaintenance();
|
||||||
|
|
||||||
pest()->expectException(HttpException::class);
|
pest()->expectException(HttpException::class);
|
||||||
pest()->withoutExceptionHandling()
|
pest()->get('http://acme.localhost/foo');
|
||||||
->get('http://acme.localhost/foo');
|
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
|
|
@ -60,8 +59,7 @@ test('tenant can be in maintenance mode from command', function() {
|
||||||
Artisan::call('tenancy:down');
|
Artisan::call('tenancy:down');
|
||||||
|
|
||||||
pest()->expectException(HttpException::class);
|
pest()->expectException(HttpException::class);
|
||||||
pest()->withoutExceptionHandling()
|
pest()->get('http://acme.localhost/foo');
|
||||||
->get('http://acme.localhost/foo');
|
|
||||||
|
|
||||||
tenancy()->end();
|
tenancy()->end();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue