Updating notification cache check
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 28 Aug 2019 12:33:56 +0000 (08:33 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 28 Aug 2019 12:33:56 +0000 (08:33 -0400)
Updating how to check for cached data.

setup/adminHooks.php

index 0016e81..01a291a 100644 (file)
@@ -80,18 +80,26 @@ if ( $serverstatsConfig['show_notifications'] && ( $user_is_admin || $user_is_ed
 
             $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
             $latest_data = unserialize( $latest );
+            // trigger_error( print_r( $latest_data, true ), E_USER_NOTICE );
 
             // check latest for time if too old then fetch latest and update time.
             $stale_time   = strtotime( '-' . GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT );
+            // trigger_error( '$stale_time: ' . $stale_time . ' $catched time: ' . $latest_data['cached'], E_USER_NOTICE );
             // If you have a cache then check to see if that cache is older than GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT.
             // If it is then set fetch_latest to true.
             if ( $latest ) {
-                if ( $latest_data['cached'] <= $stale_time ) {
+                if ( !empty( $latest_data['cached'] ) && $latest_data['cached'] <= $stale_time ) {
                     $fetch_latest = true;
+                    // trigger_error( '$latest found but expired', E_USER_NOTICE );
+                } else if ( empty( $latest_data['cached'] ) ) {
+                    $fetch_latest = true;
+                    // trigger_error( '$latest found but no cached time', E_USER_NOTICE );
                 }
             } else {
                 $fetch_latest = true;
+                // trigger_error( 'No $latest found', E_USER_NOTICE );
             }
+            // trigger_error( '$fetch_latest: ' . $fetch_latest, E_USER_NOTICE );
 
             // If fetch_latest then grab the newest from Relay.
             if ( $fetch_latest ) {
@@ -100,7 +108,7 @@ if ( $serverstatsConfig['show_notifications'] && ( $user_is_admin || $user_is_ed
                 $message_data = wp_remote_retrieve_body( $response );
                 $status       = wp_remote_retrieve_response_code( $response);
                 // Initialize variables
-                $title = $dashboard_message = $current_time = '';
+                $title = $dashboard_message = '';
                 $id    = $updated  = false;
 
                 // If we get a good response.
@@ -122,13 +130,16 @@ if ( $serverstatsConfig['show_notifications'] && ( $user_is_admin || $user_is_ed
                 } else {
                     $latest_version = false;
                 }
+                // trigger_error( '$latest_version: ' . $latest_version, E_USER_NOTICE );
+                // trigger_error( '$latest_data[version]: ' . $latest_data['version'], E_USER_NOTICE );
                 // Need to check the latest version with what we have cached.
                 // If our version is the same then we're ok. Don't delete the dismiss option.
-                if ( isset( $latest_data ) && isset( $latest_data['version'] ) && $latest_version == $latest_data['version'] ) {
+                if ( !empty( $latest_data ) && !empty( $latest_data['version'] ) && $latest_version == $latest_data['version'] ) {
                     // use the cached data
                 } else {
                     // If there's a new update then delete the dismiss option.
                     delete_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS );
+                    // trigger_error( "Delete option relay dismiss: " . GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS , E_USER_NOTICE );
                 }
 
                 $latest_data = array(