| @@ -88,9 +88,9 @@ | ||
| 88 | 88 | * |
| 89 | 89 | * @param bool $should_filter_old Whether it should filter out old entries or not. Default to true, only return entries newer than the limit |
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | - public function get_logs( bool $should_filter_old = true ) : array { | |
| 92 | + public function get_logs( bool $should_filter_old = true ): array { | |
| 93 | 93 | $logs = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? |
| 94 | 94 | get_site_transient( self::CACHE_KEY, [] ) : |
| 95 | 95 | get_transient( self::CACHE_KEY, [] ); |
| 96 | 96 | |
| @@ -213,9 +213,9 @@ | ||
| 213 | 213 | * |
| 214 | 214 | * @param array $notices Current EP notices |
| 215 | 215 | * @return array |
| 216 | 216 | */ |
| 217 | - public function maybe_add_notice( array $notices ) : array { | |
| 217 | + public function maybe_add_notice( $notices ) { | |
| 218 | 218 | if ( ! current_user_can( Utils\get_capability() ) ) { |
| 219 | 219 | return $notices; |
| 220 | 220 | } |
| 221 | 221 | |
| @@ -232,20 +232,38 @@ | ||
| 232 | 232 | if ( empty( $logs ) ) { |
| 233 | 233 | return $notices; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $page = 'admin.php?page=elasticpress-status-report'; | |
| 236 | + $indices_comparison = Elasticsearch::factory()->get_indices_comparison(); | |
| 237 | + $present_indices = count( $indices_comparison['present_indices'] ); | |
| 237 | 238 | |
| 238 | - $status_report_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? | |
| 239 | - network_admin_url( $page ) : | |
| 240 | - admin_url( $page ); | |
| 239 | + if ( 0 === $present_indices ) { | |
| 240 | + $message = sprintf( | |
| 241 | + /* translators: %s: Sync page link. */ | |
| 242 | + esc_html__( 'Your site\'s content is not synced with your %1$s. Please %2$s.', 'elasticpress' ), | |
| 243 | + Utils\is_epio() ? __( 'ElasticPress.io account', 'elasticpress' ) : __( 'Elasticsearch server', 'elasticpress' ), | |
| 244 | + sprintf( | |
| 245 | + '<a href="%1$s">%2$s</a>', | |
| 246 | + esc_url( Utils\get_sync_url( true ) ), | |
| 247 | + esc_html__( 'sync your content', 'elasticpress' ) | |
| 248 | + ) | |
| 249 | + ); | |
| 250 | + } else { | |
| 251 | + $page = 'admin.php?page=elasticpress-status-report'; | |
| 241 | 252 | |
| 242 | - $notices['has_failed_queries'] = [ | |
| 243 | - 'html' => sprintf( | |
| 253 | + $status_report_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? | |
| 254 | + network_admin_url( $page ) : | |
| 255 | + admin_url( $page ); | |
| 256 | + | |
| 257 | + $message = sprintf( | |
| 244 | 258 | /* translators: Status Report URL */ |
| 245 | 259 | __( 'Some ElasticPress queries failed in the last 24 hours. Please visit the <a href="%s">Status Report page</a> for more details.', 'elasticpress' ), |
| 246 | 260 | $status_report_url . '#failed-queries' |
| 247 | - ), | |
| 261 | + ); | |
| 262 | + } | |
| 263 | + | |
| 264 | + $notices['has_failed_queries'] = [ | |
| 265 | + 'html' => $message, | |
| 248 | 266 | 'type' => 'warning', |
| 249 | 267 | 'dismiss' => true, |
| 250 | 268 | ]; |
| 251 | 269 | |
| @@ -258,9 +276,9 @@ | ||
| 258 | 276 | * @param array $query The failed query |
| 259 | 277 | * @param string $type The query type |
| 260 | 278 | * @return array |
| 261 | 279 | */ |
| 262 | - protected function format_log_entry( array $query, string $type ) : array { | |
| 280 | + protected function format_log_entry( array $query, string $type ): array { | |
| 263 | 281 | global $wp; |
| 264 | 282 | |
| 265 | 283 | $query_time = ( ! empty( $query['time_start'] ) && ! empty( $query['time_finish'] ) ) ? |
| 266 | 284 | ( $query['time_finish'] - $query['time_start'] ) * 1000 : |
| @@ -282,9 +300,18 @@ | ||
| 282 | 300 | $query['args']['headers']['X-ElasticPress-Request-ID'] : |
| 283 | 301 | null; |
| 284 | 302 | |
| 285 | 303 | $status = wp_remote_retrieve_response_code( $query['request'] ); |
| 286 | - $result = json_decode( wp_remote_retrieve_body( $query['request'] ), true ); | |
| 304 | + if ( is_wp_error( $query['request'] ) ) { | |
| 305 | + $result = [ | |
| 306 | + 'is_wp_error' => true, | |
| 307 | + 'code' => $query['request']->get_error_code(), | |
| 308 | + 'message' => $query['request']->get_error_message(), | |
| 309 | + 'data' => $query['request']->get_error_data(), | |
| 310 | + ]; | |
| 311 | + } else { | |
| 312 | + $result = json_decode( wp_remote_retrieve_body( $query['request'] ), true ); | |
| 313 | + } | |
| 287 | 314 | |
| 288 | 315 | $formatted_log = [ |
| 289 | 316 | 'wp_url' => home_url( add_query_arg( [ $_GET ], $wp->request ) ), // phpcs:ignore WordPress.Security.NonceVerification |
| 290 | 317 | 'es_req' => $query['args']['method'] . ' ' . $query['url'], |
| @@ -316,9 +343,9 @@ | ||
| 316 | 343 | * @param array $query The failed query |
| 317 | 344 | * @param string $type The query type |
| 318 | 345 | * @return boolean |
| 319 | 346 | */ |
| 320 | - protected function should_log_query_type( array $query, string $type ) : bool { | |
| 347 | + protected function should_log_query_type( array $query, string $type ): bool { | |
| 321 | 348 | /** |
| 322 | 349 | * Filter the array with a map from query types to callables. If the callable returns true, |
| 323 | 350 | * the query will be logged. |
| 324 | 351 | * |