Skip to content

Commit

Permalink
Respect the selected PHP versions when installing a script
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed May 16, 2021
1 parent 7835256 commit f3e0bfe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion install-script.pl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ package virtual_server;
# Check PHP version
if (&indexof("php", @{$script->{'uses'}}) >= 0) {
&$first_print("Checking PHP version ..");
$phpver = &setup_php_version($d, [5], $opts->{'path'});
$phpver = &setup_php_version($d, $script, $ver, $opts->{'path'});
if (!$phpver) {
&$second_print(".. no PHP version found!");
exit(1);
Expand Down
3 changes: 2 additions & 1 deletion mass_scripts.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ if ($in{'confirm'}) {
# Check if we have PHP
local $phpver;
if (&indexof("php", @{$script->{'uses'}}) >= 0) {
$phpver = &setup_php_version($d, [5], $opts->{'path'});
$phpver = &setup_php_version($d, $script, $ver,
$opts->{'path'});
if (!$phpver) {
&$second_print($text{'scripts_ephpvers2'});
next;
Expand Down
2 changes: 1 addition & 1 deletion script_install.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ $merr = &making_changes();

# Setup PHP version
if (&indexof("php", @{$script->{'uses'}}) >= 0) {
$phpver = &setup_php_version($d, [5], $opts->{'path'});
$phpver = &setup_php_version($d, $script, $ver, $opts->{'path'});
if (!$phpver) {
&error($text{'scripts_ephpvers2'});
}
Expand Down
30 changes: 22 additions & 8 deletions scripts-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ sub get_script
'php_mods_func' => "script_${name}_php_modules",
'php_opt_mods_func' => "script_${name}_php_optional_modules",
'php_fullver_func' => "script_${name}_php_fullver",
'php_maxver_func' => "script_${name}_php_maxver",
'pear_mods_func' => "script_${name}_pear_modules",
'perl_mods_func' => "script_${name}_perl_modules",
'perl_opt_mods_func' => "script_${name}_opt_perl_modules",
Expand Down Expand Up @@ -908,15 +909,28 @@ sub expand_php_versions
return sort { $b <=> $a } &unique(@rv);
}

# setup_php_version(&domain, &versions, path)
# setup_php_version(&domain, &script, version, path)
# Checks if one of the given PHP versions is available for the domain.
# If not, sets up a per-directory version if possible.
sub setup_php_version
{
local ($d, $vers, $path) = @_;
$vers = [ &expand_php_versions($d, $vers) ];
local ($d, $script, $scriptver, $path) = @_;

# Find the best matching directory
# Figure out which PHP versions the script supports
my @vers = map { &get_php_version($_->[0]) } &list_available_php_versions($d);
my $minfunc = $script->{'php_fullver_func'};
my $maxfunc = $script->{'php_maxver_func'};
if (defined(&$minfunc)) {
my $minver = &$minfunc($d, $scriptver);
@vers = grep { &compare_versions($_, $minver) >= 0 } @vers;
}
if (defined(&$maxfunc)) {
my $maxver = &$maxfunc($d, $scriptver);
@vers = grep { &compare_versions($_, $maxver) < 0 } @vers;
}
return undef if (!@vers);

# Find the best matching directory with a PHP version set
local $dirpath = &public_html_dir($d).$path;
local @dirs = &list_domain_php_directories($d);
local $bestdir;
Expand All @@ -928,16 +942,16 @@ sub setup_php_version
}
$bestdir || &error("Could not find PHP version for $dirpath");

if (&indexof($bestdir->{'version'}, @$vers) >= 0) {
if (&indexof($bestdir->{'version'}, @vers) >= 0) {
# The best match dir supports one of the PHP versions .. so we are OK!
return $bestdir->{'version'};
}

# Need to add a directory, or fix one. Use the lowest PHP version that
# is supported.
$vers = [ sort { $a <=> $b } @$vers ];
local $err = &save_domain_php_directory($d, $dirpath, $vers->[0]);
return $err ? undef : $vers->[0];
@vers = sort { &compare_versions($a, $b) } @vers;
local $err = &save_domain_php_directory($d, $dirpath, $vers[0]);
return $err ? undef : $vers[0];
}

# clear_php_version(&domain, &sinfo)
Expand Down
3 changes: 2 additions & 1 deletion virtual-server-lib-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7810,7 +7810,8 @@ sub create_virtual_server
# Check PHP version
local $phpver;
if (&indexof("php", @{$script->{'uses'}}) >= 0) {
$phpver = &setup_php_version($dom, [5],$opts->{'path'});
$phpver = &setup_php_version($dom, $script, $ver,
$opts->{'path'});
if (!$phpver) {
&$second_print($text{'scripts_ephpvers2'});
next;
Expand Down

0 comments on commit f3e0bfe

Please sign in to comment.