From: Steve Sutton Date: Tue, 1 Oct 2019 15:54:57 +0000 (-0400) Subject: Delete old notices. X-Git-Tag: v4.1.5^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=baf2fb4ea11cb894d88d59edcc8bd67e5eeb7429;p=WP-Plugins%2Fglm-serverstats.git Delete old notices. Notices not found from gaslight site should be deleted. --- diff --git a/classes/GlmServerStats.php b/classes/GlmServerStats.php index 694babd..bb7df65 100644 --- a/classes/GlmServerStats.php +++ b/classes/GlmServerStats.php @@ -155,7 +155,7 @@ class GlmServerStats $notices = array(); $response = \wp_remote_get( $fetchUrl ); $message_data = \wp_remote_retrieve_body( $response ); - $status = \wp_remote_retrieve_response_code( $response); + $status = \wp_remote_retrieve_response_code( $response ); if ( $status == 200 ) { $notices = json_decode( $message_data, true ); @@ -163,6 +163,9 @@ class GlmServerStats set_transient( 'ServerStatCacheUpdate', true, 20 * MINUTE_IN_SECONDS ); + // Delete any old ones no longer existing. + $this->deletOldNotices(); + if ( !empty( $notices ) ) { if ( GLM_SERVERSTATS_PLUGIN_DEBUG ) { trigger_error( 'updating cache', E_USER_NOTICE ); @@ -175,10 +178,44 @@ class GlmServerStats trigger_error( 'no new ones found', E_USER_NOTICE ); } } + } } + public function deletOldNotices() + { + $fetchUrl = GLM_SERVERSTATS_PLUGIN_RELAY_URL . '&option=active'; + $notices = array(); + $response = \wp_remote_get( $fetchUrl ); + $message_data = \wp_remote_retrieve_body( $response ); + $status = \wp_remote_retrieve_response_code( $response ); + + if ( $status == 200 ) { + $notices = json_decode( $message_data, true ); + + $activeIds = array(); + if ( $notices ) { + foreach ( $notices as $notice ) { + $activeIds[] = $notice['id']; + } + } + + if ( !empty( $activeIds ) ) { + // Delete any not found. + $this->wpdb->query( "DELETE FROM {$this->prefix}{$this->cacheTableName} WHERE id NOT IN (" . implode( ',', $activeIds ) . ")" ); + if ( GLM_SERVERSTATS_PLUGIN_DEBUG ) { + trigger_error( 'Delete where not in ' . implode( ',', $activeIds ), E_USER_NOTICE ); + } + } else { + $this->wpdb->query( "DELETE FROM {$this->prefix}{$this->cacheTableName}" ); + if ( GLM_SERVERSTATS_PLUGIN_DEBUG ) { + trigger_error( 'Delete all', E_USER_NOTICE ); + } + } + } + } + public function cacheNotice( $notice ) { // Check to see if the notice is already cached. diff --git a/index.php b/index.php index ccacc43..caa49e9 100755 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM Bandwidth * Plugin URI: http://www.gaslightmedia.com/ * Description: Gaslight Media Website Bandwidth Display and Reporting - * Version: 4.1.4 + * Version: 4.1.5 * Author: Gaslight Media * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,7 +19,7 @@ * @package glmServerStats * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 4.1.4 + * @version 4.1.5 */ // Check that we're being called by WordPress. @@ -28,7 +28,7 @@ if (!defined('ABSPATH')) { die(); } -define('GLM_SERVERSTATS_PLUGIN_VERSION', '4.1.4'); +define('GLM_SERVERSTATS_PLUGIN_VERSION', '4.1.5'); define('GLM_SERVERSTATS_PLUGIN_DB_VERSION', '0.0.1'); diff --git a/readme.txt b/readme.txt index a000eaa..efa95c2 100755 --- a/readme.txt +++ b/readme.txt @@ -29,6 +29,10 @@ e.g. 1. Activate the plugin through the 'Plugins' menu in WordPress == Changelog == += 4.1.5 = +* Delete any old notices not found on main relay plugin when doing updates to + cache. + = 4.1.4 = * Fixed forced cookie pop-up not showing if cookie pop-up was off for site.