Fix issues in new PHP package manager

This commit is contained in:
Ilia Ross
2025-05-25 17:13:11 +03:00
parent 8ff86fd7f8
commit 8cce264953
4 changed files with 75 additions and 17 deletions

View File

@@ -12,7 +12,7 @@ my @d = split(/\0/, $in{'d'});
my $vmap = &get_virtualmin_php_map();
# Find all packages and check that they can be safely removed
my @pkgs = &list_php_base_packages();
my @pkgs = &list_any_php_base_packages();
my @delpkgs;
foreach my $name (@d) {
($pkg) = grep { $_->{'name'} eq $name } @pkgs;

View File

@@ -7,7 +7,7 @@ $access{'global'} || &error($text{'pkgs_ecannot'});
&ui_print_header(undef, $text{'pkgs_title'}, "");
my @pkgs = &list_php_base_packages();
my @pkgs = &list_any_php_base_packages();
my %got;
if (@pkgs) {
my $vmap = &get_virtualmin_php_map();
@@ -51,13 +51,21 @@ else {
print "<b>$text{'pkgs_none'}</b> <p>\n";
}
if (&foreign_installed("package-updates")) {
my @newpkgs = grep { !$got{$_->{'name'}} } &list_any_available_php_packages();
if (@newpkgs && &foreign_installed("package-updates")) {
# Show form to install a new version
@newpkgs = grep { !$got{$_->{'name'}} } &list_available_php_packages();
print &ui_hr();
print &ui_form_start(
&get_webprefix()."/package-updates/update.cgi", "post");
print "$text{'pkgs_newver'}&nbsp;\n";
# Always install -cli package, along with the common package
foreach my $pkg (@newpkgs) {
if ($pkg->{'name'} =~ /-common$/) {
my $pkg_cli = $pkg->{'name'};
$pkg_cli =~ s/-common$/-cli/;
$pkg->{'name'} .= " $pkg_cli";
}
}
print &ui_select("u", undef,
[ map { [ $_->{'name'},
"PHP $_->{'shortver'}" ] } @newpkgs ]);

View File

@@ -866,7 +866,7 @@ else {
return @poss;
}
# list_php_base_packages()
# list_php_base_packages([common])
# Returns a list of hash refs, one per PHP version installed, with the
# following keys :
# name - Package name
@@ -875,13 +875,19 @@ return @poss;
# phpver - PHP version
sub list_php_base_packages
{
my ($common) = @_;
&foreign_require("software");
my $n = &software::list_packages();
my @rv;
my %done;
for(my $i=0; $i<$n; $i++) {
my $name = $software::packages{$i,'name'};
next if ($name !~ /^(php\d*)(-php|-runtime)?$/);
if ($common) {
next if ($name !~ /^(php(?:\d+(?:\.\d+)?)?(?:-php)?-common)$/);
}
else {
next if ($name !~ /^php(\d*)$/);
}
$name = $1;
my $phpver = $software::packages{$i,'version'};
$phpver =~ s/\-.*$//;
@@ -914,19 +920,33 @@ for(my $i=0; $i<$n; $i++) {
return sort { &compare_version_numbers($a->{'ver'}, $b->{'ver'}) } @rv;
}
# list_any_php_base_packages()
# Returns a list of all PHP base packages, either common or full,
# sorted by version number. If no common packages are available, the
# full PHP packages are used instead, mainly for non-Linux systems
sub list_any_php_base_packages
{
my @rv = &list_php_base_packages(1);
if (!@rv) {
# If no common packages, then use the full PHP packages
@rv = &list_php_base_packages();
}
return sort { &compare_version_numbers($a->{'ver'}, $b->{'ver'}) } @rv;
}
# list_all_php_module_packages(base-package)
# Returns all install packages for PHP extensions of a given base package
sub list_all_php_module_packages
{
my ($base) = @_;
$base =~ s/(-php|-runtime)$//;
$base =~ s/-common$//;
my @rv;
&foreign_require("software");
my $n = &software::list_packages();
for(my $i=0; $i<$n; $i++) {
my $name = $software::packages{$i,'name'};
next if ($name !~ /^\Q$base\E-/);
push(@rv, { 'name' => $software::packages{$i,'name'},
push(@rv, { 'name' => $name,
'system' => $software::packages{$i,'system'},
'ver' => $software::packages{$i,'version'},
});
@@ -934,7 +954,7 @@ for(my $i=0; $i<$n; $i++) {
return @rv;
}
# list_available_php_packages()
# list_available_php_packages([common])
# Returns a list of hash refs, one per PHP version available, with the
# following keys :
# name - Package name
@@ -942,15 +962,23 @@ return @rv;
# phpver - PHP version
sub list_available_php_packages
{
my ($common) = @_;
&foreign_require("package-updates");
my @rv;
foreach my $pkg (&package_updates::list_available()) {
my $name = $pkg->{'name'};
next if ($name !~ /^php(\d*)$/);
if ($common) {
next if ($name !~ /^(php(?:\d+(?:\.\d+)?)?(?:-php)?-common)$/);
}
else {
next if ($name !~ /^php(\d*)$/);
}
my $phpver = $pkg->{'version'};
$phpver =~ s/\-.*$//;
my $shortver = $phpver;
$shortver =~ s/^(\d+\.\d+).*$/$1/;
# Avoid overwriting system PHP provided by default repositories
next if (grep { $_->{'shortver'} eq $shortver } @rv);
if ($shortver =~ /^5\./) {
$shortver = "5";
}
@@ -963,6 +991,20 @@ foreach my $pkg (&package_updates::list_available()) {
return sort { &compare_version_numbers($a->{'ver'}, $b->{'ver'}) } @rv;
}
# list_any_available_php_packages()
# Returns a list of all available PHP packages, either common or standard,
# sorted by version number. If no common packages are available, the
# full PHP packages are used instead, mainly for non-Linux systems
sub list_any_available_php_packages
{
my @rv = &list_available_php_packages(1);
if (!@rv) {
# If no common packages, then use the full PHP packages
@rv = &list_available_php_packages();
}
return sort { &compare_version_numbers($a->{'ver'}, $b->{'ver'}) } @rv;
}
# get_virtualmin_php_map()
# Return a hash mapping PHP versions like 5 or 7.2 to a list of domains, or
# undef if Virtualmin isn't installed
@@ -992,8 +1034,8 @@ my ($pkg) = @_;
my @rv = map { $_->{'name'} }
&list_all_php_module_packages($pkg->{'name'});
my $base = $pkg->{'name'};
$base =~ s/-php$//;
my @poss = ( @modpkgs, $base."-php", $base."-runtime", $base );
$base =~ s/-common$//;
my @poss = ( $base."-runtime", $base );
foreach my $p (@poss) {
my @info = &software::package_info($p, $pkg->{'ver'});
next if (!@info);