Skip to content

Commit

Permalink
Add support for custom download server in WordPress install script
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Apr 28, 2024
1 parent b5110f6 commit 7e48650
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions scripts/wordpress.pl
Expand Up @@ -20,7 +20,7 @@ sub script_wordpress_longdesc
# script_wordpress_versions()
sub script_wordpress_versions
{
return ( "6.5.2" );
return ( "6.5.2", "6.4.4", "6.3.4", "6.2.5", "6.1.6", "6.0.8", "5.9.9", "5.8.9", "5.7.11", "5.6.13", "5.5.14", "5.4.15", "5.3.17", "5.2.20", "5.1.18", "5.0.21", "4.9.25", "4.8.24", "4.7.28", "4.6.28", "4.5.31", "4.4.32", "4.3.33", "4.2.37", "4.1.40", "4.0.38", "3.9.40" );
}

sub script_wordpress_category
Expand Down Expand Up @@ -67,7 +67,7 @@ sub script_wordpress_dbs

sub script_wordpress_release
{
return 8; # Fix regex for passmode
return 9; # Support fallback download servers: virtualmin.com or custom
}

sub script_wordpress_php_fullver
Expand All @@ -88,7 +88,17 @@ sub script_wordpress_params
my ($d, $ver, $upgrade) = @_;
my $rv;
my $hdir = public_html_dir($d, 1);
my $download_server = "virtualmin.com";
if ($config{'wp_download_server'}) {
$download_server = $config{'wp_download_server'};
$download_server =~ s/^.*:\/\///;
}
if ($upgrade) {
$rv .= &ui_table_row("Download WordPress source from",
&ui_radio("mirror",
$upgrade->{'opts'}->{'mirror'} || 0,
[ [ 0, "wordpress.org" ],
[ 1, $download_server ] ]));
# Options are fixed when upgrading
my ($dbtype, $dbname) = split(/_/, $upgrade->{'opts'}->{'db'}, 2);
$rv .= ui_table_row("Database for WordPress tables", $dbname);
Expand All @@ -97,6 +107,9 @@ sub script_wordpress_params
$rv .= ui_table_row("Install directory", $dir);
}
else {
$rv .= &ui_table_row("Download WordPress source from",
&ui_radio("mirror", 0, [ [ 0, "wordpress.org" ],
[ 1, $download_server ] ]));
# Show editable install options
my @dbs = domain_databases($d, [ "mysql" ]);
$rv .= ui_table_row("Database for WordPress tables",
Expand All @@ -119,7 +132,11 @@ sub script_wordpress_parse
{
my ($d, $ver, $in, $upgrade) = @_;
if ($upgrade) {
# Options are always the same
# Options are always the same except for the mirror
if (defined($in->{'mirror'})) {
$upgrade->{'opts'}->{'mirror'} =
$in->{'mirror'} ? 1 : 0;
}
return $upgrade->{'opts'};
}
else {
Expand All @@ -131,6 +148,7 @@ sub script_wordpress_parse
my $dir = $in{'dir_def'} ? $hdir : "$hdir/$in{'dir'}";
my ($newdb) = ($in->{'db'} =~ s/^\*//);
return { 'db' => $in->{'db'},
'mirror' => $in->{'mirror'} ? 1 : 0,
'newdb' => $newdb,
'dir' => $dir,
'noauto' => $in->{'noauto'},
Expand Down Expand Up @@ -208,12 +226,21 @@ sub script_wordpress_install
&copy_source_dest($files->{'cli'}, "$opts->{'dir'}/wp-cli.phar");
&set_permissions_as_domain_user($d, 0750, "$opts->{'dir'}/wp-cli.phar");

# Source URL
my $download_server = "http://scripts.virtualmin.com";
if ($config{'wp_download_server'}) {
$download_server = $config{'wp_download_server'};
$download_server = "http://$download_server" if ($download_server !~ /^.*:\/\//);
}
my $download_url = "--version=$version";
$download_url = "$download_server/wordpress-$version.zip"
if ($opts->{'mirror'});
# Install using cli
if (!$upgrade) {
my $err_continue = "<br>Installation can be continued manually at <a target=_blank href='${url}wp-admin'>$url</a>.";

# Start installation
my $out = &run_as_domain_user($d, "$wp core download --version=$version 2>&1");
my $out = &run_as_domain_user($d, "$wp core download $download_url 2>&1");
if ($? && $out !~ /Success:\s+WordPress\s+downloaded/i) {
return (-1, "\`wp core download\` failed` : $out");
}
Expand Down Expand Up @@ -285,7 +312,7 @@ sub script_wordpress_install
else {
# Do the upgrade
my $out = &run_as_domain_user($d,
"$wp core upgrade --version=$version 2>&1");
"$wp core upgrade $download_url 2>&1");
if ($?) {
return (-1, "\`wp core upgrade\` failed : $out");
}
Expand Down

7 comments on commit 7e48650

@jcameron
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this PR ... there is no need to support all those different Wordpress versions, as out general policy is to support only the newest version from each major release. Also this breaks detection for new versions, which you can see by running "virtualmin check-scripts --debug wordpress"

Also, instead of prompting the user for whether to use a mirror or not, we should just re-run wp download with the Virtualmin mirror URL if the first download fails.

Also also, I don't see the point of checking $config{'wp_download_server'} ?

@iliajie
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, instead of prompting the user for whether to use a mirror or not, we should just re-run wp download with the Virtualmin mirror URL if the first download fails.

Duh, you're right! Adding an extra option was overkill. Not sure why I didn't just make the script retry silently and only fail if both downloads failed! Alright, it's fixed now! Thanks!

Also also, I don't see the point of checking $config{'wp_download_server'} ?

I added the wp_aux_download_server option for users to be able to define a custom auxiliary download server for development purposes! It will be possible to define it later from the WordPress Kit.

there is no need to support all those different Wordpress versions, as out general policy is to support only the newest version from each major release.

Alright, I have fixed it to only have major releases listed.

Also this breaks detection for new versions, which you can see by running "virtualmin check-scripts --debug wordpress"

Hmm, I'm not sure I understand the logic or what's failing really? All those versions that were out there are legitimate releases that a user could use for development purposes. But it's okay to have only major releases in the main list, as I will make this later possible from inside WordPress Kit.

@jcameron
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! But can you also fix the script_wordpress_latest function to properly handle these new versions?

You can see that if you run virtualmin check-scripts --debug wordpress currently it will complain that version 5.9.9 (and others) are not the newest.

@iliajie
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this #795.

@jcameron
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That only works if we know for sure that 5.9.9 will be the final version in the 5.9 series, which for some scripts is not the case.

@iliajie
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in case of my patch it won't complain and only check the version 6? Ideally we should check for only the latest version from _versions func, though I'm not sure how it can be done from inside _latest?

@jcameron
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you're right, the latest patch is good!

Please sign in to comment.