- Corrige l'erreur SQL 'Unknown column fk_operation in users' - L'opération active est récupérée depuis operations.chk_active = 1 - Jointure avec users pour filtrer par entité de l'admin créateur - Query: SELECT o.id FROM operations o INNER JOIN users u ON u.fk_entite = o.fk_entite WHERE u.id = ? AND o.chk_active = 1
49 lines
1.4 KiB
PHP
Executable File
49 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Initialisation de la connexion base de données
|
|
* Gère automatiquement les tunnels SSH ou connexion VPN directe
|
|
*/
|
|
|
|
require_once __DIR__ . '/../config/database.php';
|
|
require_once __DIR__ . '/DatabaseConnection.php';
|
|
require_once __DIR__ . '/helpers.php';
|
|
|
|
/**
|
|
* Initialise la connexion pour un environnement
|
|
* Ouvre le tunnel SSH si nécessaire (mode non-VPN)
|
|
*
|
|
* @param string $environment Environnement (DEV, REC, PROD)
|
|
* @return DatabaseConnection Connexion initialisée
|
|
* @throws RuntimeException Si la connexion échoue
|
|
*/
|
|
function initConnection(string $environment): DatabaseConnection {
|
|
$db = new DatabaseConnection($environment);
|
|
|
|
// Si on utilise le VPN, pas besoin de tunnel SSH
|
|
if ($db->usesVpn()) {
|
|
info("Mode VPN détecté - connexion directe à la base");
|
|
return $db;
|
|
}
|
|
|
|
// Mode tunnel SSH
|
|
info("Mode tunnel SSH - ouverture du tunnel...");
|
|
|
|
$tunnelScript = __DIR__ . '/../bin/_ssh-tunnel.sh';
|
|
exec("$tunnelScript open $environment 2>&1", $output, $exitCode);
|
|
|
|
if ($exitCode !== 0) {
|
|
error("Impossible d'ouvrir le tunnel SSH");
|
|
if (!empty($output)) {
|
|
foreach ($output as $line) {
|
|
error(" " . $line);
|
|
}
|
|
}
|
|
throw new RuntimeException("Échec de l'ouverture du tunnel SSH");
|
|
}
|
|
|
|
return $db;
|
|
}
|