App-WordPressTools
view release on metacpan or search on metacpan
script/wp-tools view on Meta::CPAN
$current_status->{'wpcli_std'} = _run_wpcli($nice_path, q{eval 'echo "ok";'});
chomp $current_status->{'wpcli_std'} if $current_status->{'wpcli_std'};
### npt "safe mode" status check
$current_status->{'wpcli_npt'} = _run_wpcli($nice_path, q{--skip-plugins --skip-themes eval 'echo "ok";'});
chomp $current_status->{'wpcli_npt'} if $current_status->{'wpcli_npt'};
### get url and current default page size/status code
$current_status->{'siteurl'} = _run_wpcli($nice_path, q{option get siteurl});;
$current_status->{'adminurl'} = "$current_status->{'siteurl'}/wp-admin";
my $resp = $http->head($current_status->{'siteurl'});
$current_status->{'code'} = $resp->{'status'};
$current_status->{'size'} = $resp->{'headers'}{'content-length'} || 1;
my $aresp = $http->head($current_status->{'adminurl'});
$current_status->{'admincode'} = $aresp->{'status'};
$current_status->{'adminsize'} = $aresp->{'headers'}{'content-length'} || 1;
}
elsif (-f "$args->{'path'}/wp-config.php") {
### get url and current default page size/status code
my $wp_configq = shell_quote("$args->{'path'}/wp-config.php");
my $username = `grep DB_USER <$wp_configq | grep -v '$definition_check_string' | cut -d \\' -f 4`;
my $password = `grep DB_PASSWORD <$wp_configq | grep -v '$definition_check_string' | cut -d \\' -f 4`;
my $database = `grep DB_NAME <$wp_configq | grep -v '$definition_check_string' | cut -d \\' -f 4`;
my $prefix = `grep table_prefix <$wp_configq | grep -v '$definition_check_string' | cut -d \\' -f 2` || 'wp_';
$prefix =~ s/[^\w_-]//g;
#disallow starting whitespace
$username =~ s/^[\r\n]+//;
$password =~ s/^[\r\n]+//;
$database =~ s/^[\r\n]+//;
chomp $username;
chomp $password;
chomp $database;
if ($username =~ /[\r\n]/ || $password =~ /[\r\n]/ || $database =~ /[\r\n]/) {
die "Multiple credentials found in $args->{'path'}/wp-config.php. Cannot determine which to use. Upgrade operation halted.";
}
if ($prefix =~ /[\r\n]/) {
die "Multiple database prefixes found in $args->{'path'}/wp-config.php. Cannot determine which to use. Upgrade operation halted.";
}
open (my $fh, '>', $defaults_file) or die "Cannot write to $defaults_file: $!";
close $fh;
chmod(0600, $defaults_file) or die "Cannot chmod $defaults_file: $!";
write_text($defaults_file,"[client]\nuser=$username\npassword=$password");
my $table = "${prefix}options";
my $databaseq = shell_quote($database);
my $siteurl_sql = qq{mysql -N -B -e --defaults-file=$defaults_file $databaseq "SELECT option_value FROM $table WHERE option_name = 'siteurl'"};
$current_status->{'siteurl'} = `$siteurl_sql`;
$current_status->{'adminurl'} = "$current_status->{'siteurl'}/wp-admin";
my $resp = $http->head($current_status->{'siteurl'});
$current_status->{'code'} = $resp->{'status'};
$current_status->{'size'} = $resp->{'headers'}{'content-length'} || 1;
my $aresp = $http->head($current_status->{'adminurl'});
$current_status->{'admincode'} = $aresp->{'status'};
$current_status->{'adminsize'} = $aresp->{'headers'}{'content-length'} || 1;
}
eval {
if ($components{'core'}) {
my $update = _run_wpcli($nice_path, ($args->{'force'} || !$plus3713) ? "core download --force 2>&1" : "core update 2>&1");
#try forcing errors
$update = _run_wpcli($nice_path, q{core download --force 2>&1}) if $?;
die "Upgrading WordPress core files exited with $? ($update)" if $?;
if (!$args->{'__skip_database'}) {
my $updatedb = _run_wpcli($nice_path, q{core update-db 2>&1});
#try harder
if ($?) {
$updatedb = _run_wpcli($nice_path, q{core update-db --skip-plugins --skip-themes 2>&1});
}
#allowable database failures
if ($updatedb !~ /(?:The site you have requested is not installed.)/) {
die "Upgrading WordPress core database exited with $? ($updatedb)" if $?;
}
}
}
my $pt_ok = qr/(?:Warning: Update package not available.|Error establishing a database connection)/;
if ($components{'plugin'}) {
my $plugins = _run_wpcli($nice_path, q{plugin update --all 2>&1});
if ($? && $plugins !~ /$pt_ok/gsm) {
die "Upgrading plugins exited with $? ($plugins)";
}
}
if ($components{'theme'}) {
my $themes = _run_wpcli($nice_path, q{theme update --all 2>&1});
if ($? && $themes !~ /$pt_ok/gsm) {
die "Upgrading themes exited with $? ($themes)" if $?;
}
}
};
if ($@) {
$args->{'failed'} = $@;
}
if (!$args->{'failed'} && $plus3713) {
### default wp-cli status check
if ($current_status->{'wpcli_std'} eq 'ok') {
my $test = _run_wpcli($nice_path, q{eval 'echo "ok";'});
chomp $test;
$args->{'failed'} = 'Failed standard WordPress check after update' if $test ne 'ok';
}
if (!$args->{'failed'} && $current_status->{'wpcli_npt'} eq 'ok') {
my $test = _run_wpcli($nice_path, q{--skip-plugins --skip-themes eval 'echo "ok";'});
chomp $test;
$args->{'failed'} = 'Failed safe mode WordPress check after update' if $test ne 'ok';
}
}
if (!$args->{'failed'} && $current_status->{'siteurl'}) {
### get current default page size and status
my $resp = $http->head($current_status->{'siteurl'});
my $after_size = $resp->{'headers'}{'content-length'} || 1;
my $average = ($current_status->{'size'} + $after_size) / 2;
my $div = $current_status->{'size'}/$after_size;
if ($div > 1.5 || $div < .5) {
$args->{'failed'} = 'Site download size changed by more than 50% after update (assuming failure).';
}
my $code = $resp->{'status'};
if (!$args->{'failed'} && $code ne $current_status->{'code'} && $code ne '200' && $current_status->{'code'} !~ /^(?:4|5)/) {
$args->{'failed'} = "Site download status changed from $current_status->{'code'} to $code (assuming failure)";
}
}
if (!$args->{'failed'} && $current_status->{'adminurl'}) {
### get current default page size and status
my $resp = $http->head($current_status->{'adminurl'});
my $after_size = $resp->{'headers'}{'content-length'} || 1;
my $average = ($current_status->{'adminsize'} + $after_size) / 2;
my $div = $current_status->{'adminsize'}/$after_size;
if ($div > 1.5 || $div < .5) {
$args->{'failed'} = 'Site admin download size changed by more than 50% after update (assuming failure).';
}
my $code = $resp->{'status'};
if (!$args->{'failed'} && $code ne $current_status->{'admincode'} && $code ne '200' && $current_status->{'admincode'} !~ /^(?:4|5)/) {
$args->{'failed'} = "Site admin download status changed from $current_status->{'admincode'} to $code (assuming failure)";
}
( run in 2.233 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )