d2d.emegrendeles.hu/app/Console/Commands/CheckTestDb.php
2026-04-08 21:47:28 +02:00

59 lines
1.9 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CheckTestDb extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:check-test-db';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Ellenőrzi a pillanatnyi adatbázis kapcsolatot és az aktív environmentet.';
/**
* Execute the console command.
*/
public function handle()
{
$this->newLine();
$this->info('--- Adatbázis Kapcsolat Ellenőrzése ---');
$this->info('APP_ENV: ' . app()->environment());
$this->info('DB_CONNECTION: ' . config('database.default'));
$this->info('DB_DATABASE (config): ' . config('database.connections.mysql.database'));
$this->info('DB_DATABASE (env): ' . env('DB_DATABASE'));
try {
$dbName = DB::select('SELECT DATABASE() as db')[0]->db;
$this->info('TÉNYLEGES ADATBÁZIS (MySQL select): ' . $dbName);
if (app()->environment() === 'testing' && strtolower($dbName) !== strtolower('d2dTest')) {
$this->error('VIGYÁZAT: Teszt környezetben nem a d2dTest adatbázist használod! (Kapcsolódva: ' . $dbName . ')');
} elseif (app()->environment() === 'testing' && strtolower($dbName) === strtolower('d2dTest')) {
$this->success('Minden rendben: Teszt környezetben a d2dTest adatbázist használod.');
}
} catch (\Exception $e) {
$this->error('Hiba az adatbázishoz való csatlakozáskor: ' . $e->getMessage());
}
$this->newLine();
}
/**
* Success message override
*/
protected function success(string $message)
{
$this->line("<info>{$message}</info>");
}
}