From 3557c2b9b273d6982c859426540e4c7a4428a7fd Mon Sep 17 00:00:00 2001 From: Josh Eaton Date: Fri, 10 Oct 2014 15:27:50 -0400 Subject: [PATCH] Move clear_url_cache to a separate static function so it can be called from other plugins. --- class-clear-url-cache.php | 62 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/class-clear-url-cache.php b/class-clear-url-cache.php index 89a3fa1..34a6859 100644 --- a/class-clear-url-cache.php +++ b/class-clear-url-cache.php @@ -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 $url" ); + 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'] ) ) @@ -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 $url" ); - wp_redirect( admin_url( '/tools.php?page=cftp_clear_url' ) ); - exit; } // CALLBACKS