@@ -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+ }
0 commit comments