Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
76
app/Console/Commands/SiteMaintenanceCommand.php
Normal file
76
app/Console/Commands/SiteMaintenanceCommand.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Support\Maintenance;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Toggles maintenance for the public site from the CLI, for use in deploy
|
||||
* scripts.
|
||||
*
|
||||
* Note this is *not* `artisan down`: the panel and the admin API stay up
|
||||
* throughout, which is the point.
|
||||
*/
|
||||
class SiteMaintenanceCommand extends Command
|
||||
{
|
||||
protected $signature = 'site:maintenance
|
||||
{--up : Bring the public site back}
|
||||
{--message= : Notice shown to visitors, in the default locale}
|
||||
{--until= : When it lifts automatically, e.g. "+2 hours"}
|
||||
{--status : Only report the current state}';
|
||||
|
||||
protected $description = 'Put the public site into maintenance, or bring it back (the panel stays up)';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
if ($this->option('status')) {
|
||||
return $this->reportStatus();
|
||||
}
|
||||
|
||||
if ($this->option('up')) {
|
||||
Maintenance::disable();
|
||||
|
||||
$this->components->info('The public site is back.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$message = $this->option('message');
|
||||
$until = $this->option('until');
|
||||
|
||||
Maintenance::enable(
|
||||
message: filled($message) ? [config('locales.default') => $message] : null,
|
||||
until: filled($until) ? CarbonImmutable::parse($until) : null,
|
||||
);
|
||||
|
||||
$this->components->warn('The public site is now in maintenance.');
|
||||
$this->components->bulletList(array_filter([
|
||||
'Visitors get 503 with the notice; the panel and admin API are unaffected.',
|
||||
filled($until) ? 'Lifts automatically at '.Maintenance::until()?->toDateTimeString() : null,
|
||||
'The team can still see the real site via the preview token or a trusted IP.',
|
||||
]));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
protected function reportStatus(): int
|
||||
{
|
||||
if (! Maintenance::isEnabled()) {
|
||||
$this->components->info('The public site is up.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->components->warn('The public site is in maintenance.');
|
||||
|
||||
$this->components->twoColumnDetail('Since', Maintenance::startedAt()?->diffForHumans() ?? '—');
|
||||
$this->components->twoColumnDetail('Lifts at', Maintenance::until()?->toDateTimeString() ?? 'manually');
|
||||
$this->components->twoColumnDetail('Notice', Maintenance::message());
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user