$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 );
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 );
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.
* 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
* @package glmServerStats
* @author Chuck Scott <cscott@gaslightmedia.com>
* @license http://www.gaslightmedia.com Gaslightmedia
- * @version 4.1.4
+ * @version 4.1.5
*/
// Check that we're being called by WordPress.
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');