PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/QueryLogger.php +54 -12 4.4.05.3.5 View file →
@@ -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
@@ -177,8 +177,10 @@
177 177 $logs[0]['result'] = '(removed due to its size)';
178 178 }
179 179 }
180 180
181 + \ElasticPress\Utils\delete_option( 'ep_hide_has_failed_queries_notice' );
182 +
181 183 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
182 184 set_site_transient( self::CACHE_KEY, $logs_json_str, DAY_IN_SECONDS );
183 185 } else {
184 186 set_transient( self::CACHE_KEY, $logs_json_str, DAY_IN_SECONDS );
@@ -211,31 +213,57 @@
211 213 *
212 214 * @param array $notices Current EP notices
213 215 * @return array
214 216 */
215 - public function maybe_add_notice( array $notices ) : array {
217 + public function maybe_add_notice( $notices ) {
218 + if ( ! current_user_can( Utils\get_capability() ) ) {
219 + return $notices;
220 + }
221 +
216 222 $current_ep_screen = \ElasticPress\Screen::factory()->get_current_screen();
217 223 if ( 'status-report' === $current_ep_screen ) {
218 224 return $notices;
219 225 }
220 226
227 + if ( \ElasticPress\Utils\get_option( 'ep_hide_has_failed_queries_notice' ) ) {
228 + return $notices;
229 + }
230 +
221 231 $logs = $this->get_logs();
222 232 if ( empty( $logs ) ) {
223 233 return $notices;
224 234 }
225 235
226 - $page = 'admin.php?page=elasticpress-status-report';
236 + $indices_comparison = Elasticsearch::factory()->get_indices_comparison();
237 + $present_indices = count( $indices_comparison['present_indices'] );
227 238
228 - $status_report_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ?
229 - network_admin_url( $page ) :
230 - 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';
231 252
232 - $notices['has_failed_queries'] = [
233 - '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(
234 258 /* translators: Status Report URL */
235 259 __( 'Some ElasticPress queries failed in the last 24 hours. Please visit the <a href="%s">Status Report page</a> for more details.', 'elasticpress' ),
236 260 $status_report_url . '#failed-queries'
237 - ),
261 + );
262 + }
263 +
264 + $notices['has_failed_queries'] = [
265 + 'html' => $message,
238 266 'type' => 'warning',
239 267 'dismiss' => true,
240 268 ];
241 269
@@ -248,9 +276,9 @@
248 276 * @param array $query The failed query
249 277 * @param string $type The query type
250 278 * @return array
251 279 */
252 - protected function format_log_entry( array $query, string $type ) : array {
280 + protected function format_log_entry( array $query, string $type ): array {
253 281 global $wp;
254 282
255 283 $query_time = ( ! empty( $query['time_start'] ) && ! empty( $query['time_finish'] ) ) ?
256 284 ( $query['time_finish'] - $query['time_start'] ) * 1000 :
@@ -267,14 +295,28 @@
267 295 $body = wp_json_encode( $json_body );
268 296 }
269 297 }
270 298
299 + $request_id = ( ! empty( $query['args']['headers'] ) && ! empty( $query['args']['headers']['X-ElasticPress-Request-ID'] ) ) ?
300 + $query['args']['headers']['X-ElasticPress-Request-ID'] :
301 + null;
302 +
271 303 $status = wp_remote_retrieve_response_code( $query['request'] );
272 - $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 + }
273 314
274 315 $formatted_log = [
275 316 'wp_url' => home_url( add_query_arg( [ $_GET ], $wp->request ) ), // phpcs:ignore WordPress.Security.NonceVerification
276 317 'es_req' => $query['args']['method'] . ' ' . $query['url'],
318 + 'request_id' => $request_id ?? '',
277 319 'timestamp' => current_time( 'timestamp' ),
278 320 'query_time' => $query_time,
279 321 'wp_args' => $query['query_args'] ?? [],
280 322 'status_code' => $status,
@@ -301,9 +343,9 @@
301 343 * @param array $query The failed query
302 344 * @param string $type The query type
303 345 * @return boolean
304 346 */
305 - protected function should_log_query_type( array $query, string $type ) : bool {
347 + protected function should_log_query_type( array $query, string $type ): bool {
306 348 /**
307 349 * Filter the array with a map from query types to callables. If the callable returns true,
308 350 * the query will be logged.
309 351 *