52 lines
2.2 KiB
PHP
52 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CheckDevelopmentEnvironment extends Command
|
|
{
|
|
protected $signature = 'portal:dev-check';
|
|
|
|
protected $description = 'Verifica o arranque local sem alterar dados ou mostrar credenciais';
|
|
|
|
public function handle(): int
|
|
{
|
|
$checks = [
|
|
'PHP >= 8.4.1' => version_compare(PHP_VERSION, '8.4.1', '>='),
|
|
'Driver PostgreSQL activo' => extension_loaded('pdo_pgsql'),
|
|
'APP_KEY definida' => filled(config('app.key')),
|
|
'Base PostgreSQL configurada' => config('database.default') === 'pgsql',
|
|
'Cache de vistas gravável' => is_dir(config('view.compiled') ?: '') && is_writable(config('view.compiled') ?: ''),
|
|
'Sessões e logs graváveis' => is_writable(storage_path('framework/sessions')) && is_writable(storage_path('logs')),
|
|
'Dependências frontend instaladas' => is_file(base_path('node_modules/.bin/vp')) || is_file(base_path('node_modules/.bin/vp.cmd')),
|
|
];
|
|
|
|
if ($checks['Driver PostgreSQL activo'] && $checks['Base PostgreSQL configurada']) {
|
|
try {
|
|
DB::selectOne('SELECT 1');
|
|
$checks['Ligação à base de dados'] = true;
|
|
$checks['Extensão PostGIS instalada'] = (bool) DB::selectOne("SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'postgis') AS installed")->installed;
|
|
$checks['Tabelas principais instaladas'] = collect(['migrations', 'users', 'sectors', 'opportunities', 'sessions', 'cache', 'jobs'])
|
|
->every(fn (string $table): bool => Schema::hasTable($table));
|
|
} catch (\Throwable) {
|
|
$checks['Ligação à base de dados'] = false;
|
|
}
|
|
}
|
|
|
|
foreach ($checks as $label => $passed) {
|
|
$this->line(($passed ? '[OK] ' : '[FALHA] ').$label);
|
|
}
|
|
|
|
if (in_array(false, $checks, true)) {
|
|
$this->error('Arranque interrompido. Consulte deploy/local/README.md e corrija os itens acima.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|