- 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>
146 lines
4.1 KiB
PHP
Executable File
146 lines
4.1 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Script de listage des secteurs d'une opération
|
|
* Usage: ./list-sectors <environment> --operation=<id>
|
|
*/
|
|
|
|
require_once __DIR__ . '/../lib/CryptoService.php';
|
|
require_once __DIR__ . '/../lib/DatabaseConnection.php';
|
|
require_once __DIR__ . '/../lib/helpers.php';
|
|
|
|
// Vérifier les arguments
|
|
if ($argc < 3) {
|
|
error("Usage: " . basename($argv[0]) . " <environment> --operation=<id>");
|
|
error("Exemple: " . basename($argv[0]) . " dev --operation=123");
|
|
exit(1);
|
|
}
|
|
|
|
$environment = strtoupper($argv[1]);
|
|
|
|
// Parser les options
|
|
$operationId = null;
|
|
|
|
for ($i = 2; $i < $argc; $i++) {
|
|
if (preg_match('/^--operation=(\d+)$/', $argv[$i], $matches)) {
|
|
$operationId = (int)$matches[1];
|
|
} else {
|
|
error("Option invalide: " . $argv[$i]);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if ($operationId === null) {
|
|
error("Le paramètre --operation=<id> est obligatoire");
|
|
exit(1);
|
|
}
|
|
|
|
try {
|
|
// Ouvrir le tunnel SSH si nécessaire
|
|
$tunnelScript = __DIR__ . '/_ssh-tunnel.sh';
|
|
exec("$tunnelScript open $environment 2>&1", $output, $exitCode);
|
|
|
|
if ($exitCode !== 0) {
|
|
error("Impossible d'ouvrir le tunnel SSH");
|
|
exit(1);
|
|
}
|
|
|
|
// Connexion à la base de données
|
|
$db = new DatabaseConnection($environment);
|
|
$pdo = $db->connect();
|
|
|
|
info("Environnement: $environment");
|
|
info("Opération: #$operationId\n");
|
|
|
|
// Vérifier que l'opération existe
|
|
$stmtOp = $pdo->prepare("SELECT libelle FROM operations WHERE id = :operation_id");
|
|
$stmtOp->execute(['operation_id' => $operationId]);
|
|
$operation = $stmtOp->fetch();
|
|
|
|
if (!$operation) {
|
|
error("Opération #$operationId introuvable");
|
|
exit(1);
|
|
}
|
|
|
|
info("Libellé opération: " . $operation['libelle'] . "\n");
|
|
|
|
// Récupérer les secteurs avec le nombre d'utilisateurs et de passages
|
|
$stmt = $pdo->prepare("
|
|
SELECT
|
|
s.id,
|
|
s.libelle,
|
|
s.color,
|
|
s.chk_active,
|
|
s.created_at,
|
|
COUNT(DISTINCT us.fk_user) as nb_users,
|
|
COUNT(DISTINCT p.id) as nb_passages
|
|
FROM ope_sectors s
|
|
LEFT JOIN ope_users_sectors us ON us.fk_sector = s.id AND us.chk_active = 1
|
|
LEFT JOIN ope_pass p ON p.fk_sector = s.id AND p.chk_active = 1
|
|
WHERE s.fk_operation = :operation_id
|
|
GROUP BY s.id
|
|
ORDER BY s.id
|
|
");
|
|
|
|
$stmt->execute(['operation_id' => $operationId]);
|
|
$sectors = $stmt->fetchAll();
|
|
|
|
if (empty($sectors)) {
|
|
warning("\nAucun secteur trouvé pour cette opération");
|
|
exit(0);
|
|
}
|
|
|
|
// Préparer les données pour le tableau
|
|
$sectorsData = [];
|
|
|
|
foreach ($sectors as $sector) {
|
|
$sectorsData[] = [
|
|
'id' => $sector['id'],
|
|
'libelle' => truncate($sector['libelle'], 40),
|
|
'color' => $sector['color'],
|
|
'users' => $sector['nb_users'],
|
|
'passages' => $sector['nb_passages'],
|
|
'actif' => $sector['chk_active'] ? '✓' : '✗',
|
|
'created' => date('d/m/Y', strtotime($sector['created_at'])),
|
|
];
|
|
}
|
|
|
|
// Affichage
|
|
title("SECTEURS - Opération #$operationId - " . count($sectorsData) . " secteur(s)");
|
|
|
|
table(
|
|
[
|
|
'id' => 'ID',
|
|
'libelle' => 'Libellé',
|
|
'color' => 'Couleur',
|
|
'users' => 'Users',
|
|
'passages' => 'Passages',
|
|
'actif' => 'Actif',
|
|
'created' => 'Créé le',
|
|
],
|
|
$sectorsData,
|
|
true
|
|
);
|
|
|
|
success("Secteurs listés avec succès");
|
|
|
|
// Afficher les statistiques globales
|
|
$totalUsers = array_sum(array_column($sectorsData, 'users'));
|
|
$totalPassages = array_sum(array_column($sectorsData, 'passages'));
|
|
$activeSectors = count(array_filter($sectorsData, fn($s) => $s['actif'] === '✓'));
|
|
|
|
echo "\n";
|
|
echo color("Statistiques:\n", 'bold');
|
|
display("Secteurs actifs", "$activeSectors / " . count($sectorsData));
|
|
display("Total utilisateurs", (string)$totalUsers);
|
|
display("Total passages", (string)$totalPassages);
|
|
echo "\n";
|
|
|
|
} catch (Exception $e) {
|
|
error("Erreur: " . $e->getMessage());
|
|
exit(1);
|
|
}
|