@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PortalReadiness extends Command
|
||||
{
|
||||
protected $signature = 'portal:readiness';
|
||||
|
||||
protected $description = 'Verifica requisitos de publicação sem alterar dados nem revelar segredos';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$checks = [
|
||||
'PHP >= 8.4.1' => version_compare(PHP_VERSION, '8.4.1', '>='),
|
||||
'Driver PostgreSQL' => extension_loaded('pdo_pgsql'),
|
||||
'Ambiente production' => app()->isProduction(),
|
||||
'Debug desactivado' => ! config('app.debug'),
|
||||
'APP_KEY definida' => filled(config('app.key')),
|
||||
'APP_URL HTTPS' => str_starts_with(config('app.url'), 'https://'),
|
||||
'Cookies seguros' => (bool) config('session.secure'),
|
||||
'Assets compilados' => is_file(public_path('build/manifest.json')),
|
||||
'Sem ficheiro Vite hot' => ! is_file(public_path('hot')),
|
||||
'Storage gravável' => is_writable(storage_path()) && is_writable(base_path('bootstrap/cache')),
|
||||
'Gestores configurados' => count(config('portal.managers')) > 0,
|
||||
'Correio real configurado' => ! in_array(config('mail.default'), ['log', 'array'], true),
|
||||
];
|
||||
try {
|
||||
DB::select('select 1');
|
||||
$checks['Ligação à base de dados'] = true;
|
||||
$checks['PostGIS instalado'] = (bool) DB::selectOne("select exists(select 1 from pg_extension where extname = 'postgis') as installed")->installed;
|
||||
$checks['Migrations aplicadas'] = count(array_diff(
|
||||
array_keys(app('migrator')->getMigrationFiles(database_path('migrations'))),
|
||||
app('migration.repository')->getRan(),
|
||||
)) === 0;
|
||||
} catch (\Throwable) {
|
||||
$checks['Base de dados e migrations verificáveis'] = false;
|
||||
}
|
||||
if (config('portal.notifications_enabled')) {
|
||||
$checks['Destinatários válidos'] = count(config('portal.notification_recipients')) > 0
|
||||
&& collect(config()->array('portal.notification_recipients'))->every(fn ($email) => filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
|
||||
$checks['Fila database na mesma ligação'] = ! config('queue.connections.database.after_commit')
|
||||
&& (! config('queue.connections.database.connection') || config('queue.connections.database.connection') === config('database.default'));
|
||||
}
|
||||
foreach ($checks as $label => $passed) {
|
||||
$this->line(($passed ? '[OK] ' : '[PENDENTE] ').$label);
|
||||
}
|
||||
$this->line('Este diagnóstico não testa entrega de email, TLS externo, backups ou execução do worker.');
|
||||
|
||||
return in_array(false, $checks, true) ? self::FAILURE : self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user