Add ability to install multiple PHP extensions at once

This commit is contained in:
Ilia Ross
2025-10-19 20:44:56 +03:00
parent 5ed99dd7eb
commit f9373eacc2
2 changed files with 75 additions and 44 deletions

View File

@@ -7,63 +7,92 @@ require './phpini-lib.pl';
&error_setup($text{'imod_err'});
&can_php_config($in{'file'}) || &error($text{'list_ecannot'});
$access{'global'} || &error($text{'mods_ecannot'});
$in{'mod'} =~ /^\S+$/ || &error($text{'imod_emod'});
&trim($in{'mod'}) || &error($text{'imod_emod'});
my $filever = &get_php_ini_version($in{'file'});
my $ver = $filever || &get_php_binary_version($in{'file'});
$ver || &error(&text('mods_egetver', "<tt>".&html_escape($in{'file'})."</tt>"));
# Work out possible package names
@poss = &php_module_packages($in{'mod'}, $ver, $filever);
@poss || &error($text{'mods_eposs'});
my @mods = &unique(split /(?:\s*,\s*|\s+)/, ($in{'mod'}));
my %want = map { lc($_) => 1 } grep { length } @mods;
my @poss;
foreach my $mod (@mods) {
push(@poss,
{ mod => $mod,
packages => [&php_module_packages($mod, $ver, $filever)] });
}
(grep { @{ $_->{packages} } } @poss) or &error($text{'mods_eposs'});
# Is it already installed?
$inidir = &get_php_ini_dir($in{'file'});
($got) = grep { $_->{'mod'} eq $in{'mod'} } &list_php_ini_modules($inidir);
if ($got) {
my $already;
foreach my $pkg (@poss) {
my @pinfo = &software::package_info($pkg);
@pinfo = &software::virtual_package_info($pkg) if (!@pinfo);
$already++ if (@pinfo);
my @got = grep { $want{ lc($_->{'mod'}) } } &list_php_ini_modules($inidir);
my @already;
if (@got) {
foreach my $g (@got) {
my ($p) = grep { $_->{'mod'} eq $g->{'mod'} } @poss;
next unless $p && @{$p->{'packages'}};
foreach my $pkg (@{$p->{'packages'}}) {
my @pinfo = &software::package_info($pkg);
@pinfo = &software::virtual_package_info($pkg)
if (!@pinfo);
if (@pinfo) {
# Update list of modules to install
@mods = grep { lc($_) ne lc($g->{'mod'}) }
@mods;
push(@already, $g->{'mod'});
}
}
}
$already && &error(&text('imod_alreadygot',
"<tt>".&html_escape($in{'mod'})."</tt>"));
}
# Print header
&ui_print_unbuffered_header(
"<tt>".&html_escape($in{'file'})."</tt>",
$text{'imod_title'}, "");
if (@already) {
print &text('imod_skipwhy')."<br>\n";
print &text('imod_skipwhich', "<tt>".
&html_escape(join(", ", &unique(@already)))."</tt>",
$ver)."<p></p>\n";
}
# Try to install them
&ui_print_unbuffered_header("<tt>".&html_escape($in{'file'})."</tt>",
$text{'imod_title'}, "");
foreach my $mod (@mods) {
print &text('imod_alldoing', "<tt>".&html_escape($mod)."</tt>",
$ver),"<br>\n";
print &text('imod_alldoing', "<tt>".&html_escape($in{'mod'})."</tt>",
$ver),"<br>\n";
my $ok = 0;
foreach my $pkg (@poss) {
my @pinfo = &software::package_info($pkg);
@pinfo = &software::virtual_package_info($pkg) if (!@pinfo);
next if (@pinfo);
my ($out, $rs) = &capture_function_output(
\&software::update_system_install, $pkg);
@pinfo = &software::package_info($pkg);
@pinfo = &software::virtual_package_info($pkg) if (!@pinfo);
if (@pinfo && @$rs) {
($got) = grep { $_->{'mod'} eq $in{'mod'} }
&list_php_ini_modules($inidir);
if ($got) {
$ok = $pkg;
last;
my $ok = 0;
my ($p) = grep { $_->{'mod'} eq $mod } @poss;
next unless $p && @{$p->{'packages'}};
foreach my $pkg (@{$p->{'packages'}}) {
my @pinfo = &software::package_info($pkg);
@pinfo = &software::virtual_package_info($pkg) if (!@pinfo);
next if (@pinfo);
my ($out, $rs) = &capture_function_output(
\&software::update_system_install, $pkg);
@pinfo = &software::package_info($pkg);
@pinfo = &software::virtual_package_info($pkg) if (!@pinfo);
if (@pinfo && @$rs) {
($got) = grep { $_->{'mod'} eq $mod }
&list_php_ini_modules($inidir);
if ($got) {
$ok = $pkg;
last;
}
}
}
}
if ($ok) {
print &text('imod_alldone',
"<tt>".&html_escape($ok)."</tt>");
&graceful_apache_restart($in{'file'});
&webmin_log("imod", undef, $in{'file'}, { 'mod' => $in{'mod'} });
}
else {
print &text('imod_allfailed',
"<tt>".&html_escape(join(" ", @poss))."</tt>");
if ($ok) {
print &text('imod_alldone',
"<tt>".&html_escape($ok)."</tt>")."<p></p>\n";
&graceful_apache_restart($in{'file'});
&webmin_log("imod", undef, $in{'file'}, { 'mod' => $mod });
}
else {
print &text('imod_allfailed',
"<tt>".&html_escape(
join(" ", @{$p->{'packages'}}))."</tt>").
"<p></p>\n";
}
}
&ui_print_footer("edit_mods.cgi?file=".&urlize($in{'file'}),

View File

@@ -178,7 +178,7 @@ mods_enabled=Enabled?
mods_name=Extension name
mods_file=Config file
mods_pkg=Package
mods_idesc=PHP extensions that are not yet installed on this system can be installed from the configured software package repositories.
mods_idesc=PHP extensions that are not yet installed on this system can be added from the software package repositories using the extension names below in space-separated format.
mods_newpkg=Add PHP extension
mods_setup=Install Now
mods_err=Failed to save PHP extensions
@@ -191,7 +191,9 @@ imod_err=Failed to install PHP module
imod_emod=No PHP module entered
imod_alldoing=Installing PHP module $1 for PHP version $2 ..
imod_alreadygot=PHP module $1 is already installed
imod_alldone=.. the PHP module was successfully installed from package $1 and is now available for use.
imod_skipwhy=The following PHP modules will not be installed because they are already present ..
imod_skipwhich=.. skipped : $1
imod_alldone=.. the PHP module was successfully installed from package $1 and is now available for use
imod_allfailed=.. no software packages for the specified PHP module could be installed, despite trying $1
imod_missing=.. install completed, but the PHP module was not detected.