Skip to content

Move clear_url_cache to a separate static function #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions class-clear-url-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ function load_tools_page(){

$url = esc_url( $_POST[ 'cached_url' ] );

// A lot of the following code is cribbed from
self::clear_url_cache( $url );

$this->set_admin_notice( "Issued a cache clearance for <var>$url</var>" );
wp_redirect( admin_url( '/tools.php?page=cftp_clear_url' ) );
exit;
}

public static function clear_url_cache( $url ) {
// A lot of the following code is cribbed from
// the WpeCommon::purge_varnish_cache method. A LOT.

$post_parts = parse_url( $url );
$post_uri = $post_parts['path'];
if ( ! empty( $post_parts['query'] ) )
Expand All @@ -100,39 +108,35 @@ function load_tools_page(){
// Hostname appears to be required without the protocol prefix, e.g.
// no 'http://'.
$hostname = $post_parts[ 'host' ];
// Purge Varnish cache.
if ( WPE_CLUSTER_TYPE == "pod" )
$wpe_varnish_servers = array( "localhost" );
else if ( ! isset( $wpe_varnish_servers ) ) {
if ( WPE_CLUSTER_TYPE == "pod" )
$lbmaster = "localhost";
else if ( ! defined( 'WPE_CLUSTER_ID' ) || ! WPE_CLUSTER_ID )
$lbmaster = "lbmaster";
else if ( WPE_CLUSTER_ID >= 4 )
$lbmaster = "localhost"; // so the current user sees the purge
else
$lbmaster = "lbmaster-" . WPE_CLUSTER_ID;
$wpe_varnish_servers = array( $lbmaster );
}

// Debugging
if ( false ) {
$msg_key = rand();
$msg = "Varnishes # $msg_key:\n" . "\nHostname:\n" . var_export( $hostname, true ) . "\nPath:\n" . var_export( $path, true );

// Purge Varnish cache.
if ( WPE_CLUSTER_TYPE == "pod" )
$wpe_varnish_servers = array( "localhost" );
else if ( ! isset( $wpe_varnish_servers ) ) {
if ( WPE_CLUSTER_TYPE == "pod" )
$lbmaster = "localhost";
else if ( ! defined( 'WPE_CLUSTER_ID' ) || ! WPE_CLUSTER_ID )
$lbmaster = "lbmaster";
else if ( WPE_CLUSTER_ID >= 4 )
$lbmaster = "localhost"; // so the current user sees the purge
else
$lbmaster = "lbmaster-" . WPE_CLUSTER_ID;
$wpe_varnish_servers = array( $lbmaster );
}

// Debugging
if ( false ) {
$msg_key = rand();
$msg = "Varnishes # $msg_key:\n" . "\nHostname:\n" . var_export( $hostname, true ) . "\nPath:\n" . var_export( $path, true );
var_dump( $wpe_varnish_servers );
var_dump( $hostname );
var_dump( $path );
}
var_dump( $hostname );
var_dump( $path );
}
// SW/CFTP: Assume we're not using EC…
foreach ( $wpe_varnish_servers as $varnish ) {
error_log( "CFTP: PURGE, $varnish, 9002, $hostname, $path, array( ), 0" );
WpeCommon::http_request_async( "PURGE", $varnish, 9002, $hostname, $path, array( ), 0 );
}

$this->set_admin_notice( "Issued a cache clearance for <var>$url</var>" );
wp_redirect( admin_url( '/tools.php?page=cftp_clear_url' ) );
exit;
}

// CALLBACKS
Expand Down