- Mise à jour VERSION vers 3.3.4 - Optimisations et révisions architecture API (deploy-api.sh, scripts de migration) - Ajout documentation Stripe Tap to Pay complète - Migration vers polices Inter Variable pour Flutter - Optimisations build Android et nettoyage fichiers temporaires - Amélioration système de déploiement avec gestion backups - Ajout scripts CRON et migrations base de données 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?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;
|
|
}
|