Skip to content

Commit 2cc321d

Browse files
author
Gemini CLI
committed
UI: aggregate health check install commands into a single command
1 parent 345572a commit 2cc321d

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

controler/functions/health_check.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,46 @@ function get_package_install_help(string $type, string $pkg_key, string $distro)
6161
return $d['pref'] . $d['ext_prefix'] . ($exts[$pkg_key] ?? $pkg_key);
6262
}
6363

64+
/**
65+
* Retourne une commande d'installation groupée pour plusieurs paquets
66+
*/
67+
function get_aggregated_install_command(array $packages): string
68+
{
69+
$distro = get_linux_distro_info();
70+
$commands = [
71+
'debian' => ['pref' => 'sudo apt-get install -y ', 'ext_prefix' => 'php-'],
72+
'fedora' => ['pref' => 'sudo dnf install -y ', 'ext_prefix' => 'php-'],
73+
'arch' => ['pref' => 'sudo pacman -S --noconfirm ', 'ext_prefix' => 'php-'],
74+
'unknown' => ['pref' => 'sudo apt-get install ', 'ext_prefix' => 'php-']
75+
];
76+
77+
$d = $commands[$distro] ?? $commands['unknown'];
78+
79+
$bins = [
80+
'ghostscript' => 'ghostscript',
81+
'imagemagick' => 'imagemagick'
82+
];
83+
84+
$exts = [
85+
'imagick' => ($distro === 'fedora' ? 'pecl-imagick' : 'imagick'),
86+
'gd' => 'gd',
87+
'sqlite3' => ($distro === 'arch' ? 'sqlite' : 'sqlite3'),
88+
'mbstring' => 'mbstring',
89+
'xml' => 'xml'
90+
];
91+
92+
$resolved_pkgs = [];
93+
foreach ($packages as $pkg) {
94+
if ($pkg['type'] === 'bin') {
95+
$resolved_pkgs[] = $bins[$pkg['key']] ?? $pkg['key'];
96+
} else {
97+
$resolved_pkgs[] = $d['ext_prefix'] . ($exts[$pkg['key']] ?? $pkg['key']);
98+
}
99+
}
100+
101+
return $d['pref'] . implode(' ', array_unique($resolved_pkgs));
102+
}
103+
64104
/**
65105
* Vérifie les dépendances critiques du système
66106
*
@@ -166,3 +206,27 @@ function check_system_dependencies(): array
166206

167207
return $results;
168208
}
209+
210+
/**
211+
* Calculer la commande d'installation globale basée sur les résultats du diagnostic
212+
*/
213+
function get_global_install_command(array $health_check_results): ?string
214+
{
215+
$missing_pkgs = [];
216+
217+
foreach ($health_check_results['dependencies'] as $key => $dep) {
218+
if (!$dep['status'] && $dep['critical']) {
219+
$missing_pkgs[] = ['type' => 'bin', 'key' => $key];
220+
}
221+
}
222+
223+
foreach ($health_check_results['php_extensions'] as $key => $ext) {
224+
if (!$ext['status'] && $ext['critical']) {
225+
$missing_pkgs[] = ['type' => 'ext', 'key' => $key];
226+
}
227+
}
228+
229+
if (empty($missing_pkgs)) return null;
230+
231+
return get_aggregated_install_command($missing_pkgs);
232+
}

models/accueil.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ function Action(){
2121
$result['show_mailing_list'] = $result_setting ? $result_setting->setting_value : '1';
2222

2323
// Exécuter le diagnostic de santé
24-
$result['health_check'] = check_system_dependencies();
24+
$health_check = check_system_dependencies();
25+
$result['health_check'] = $health_check;
26+
$result['global_install_command'] = get_global_install_command($health_check);
2527

2628
return template("../view/accueil.html.php",$result);
2729
}

view/accueil.html.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
<div class="alert alert-danger" style="margin-top: 20px; border-radius: 10px; box-shadow: 0 4px 10px rgba(220,53,69,0.2);">
1010
<h4 style="margin-top: 0;"><i class="fa fa-exclamation-triangle"></i> <?php _e('accueil.health.critical_error_title', [], true); ?></h4>
1111
<p><?php _e('accueil.health.critical_error_desc', [], true); ?></p>
12+
13+
<?php if (isset($global_install_command)): ?>
14+
<div style="background: rgba(0,0,0,0.05); padding: 15px; border-radius: 8px; margin-bottom: 20px; border: 1px dashed rgba(220,53,69,0.5);">
15+
<p style="margin-bottom: 8px; font-weight: bold;"><i class="fa fa-terminal"></i> Commande d'installation groupée :</p>
16+
<div class="input-group">
17+
<input type="text" class="form-control" value="<?= htmlspecialchars($global_install_command) ?>" readonly id="global-install-cmd">
18+
<span class="input-group-btn">
19+
<button class="btn btn-default" type="button" onclick="navigator.clipboard.writeText('<?= addslashes($global_install_command) ?>'); alert('Copié !')">
20+
<i class="fa fa-copy"></i>
21+
</button>
22+
</span>
23+
</div>
24+
</div>
25+
<?php endif; ?>
26+
1227
<ul style="margin-bottom: 10px;">
1328
<?php foreach ($health_check['dependencies'] as $dep): ?>
1429
<?php if (!$dep['status'] && $dep['critical']): ?>

0 commit comments

Comments
 (0)