Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Aug 9, 2021
2 parents bb81c2f + 0e98181 commit 2b04153
Show file tree
Hide file tree
Showing 11 changed files with 2,452 additions and 3,747 deletions.
25 changes: 18 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,46 @@

All notable changes to this project will be documented in this file, per [the Keep a Changelog standard](http://keepachangelog.com/).

## [2.0.0]
## [2.1.0] - 2021-08-09

### Added
* ElasticPress and Elasticsearch versions. Props to [@oscarssanchez](https://github.com/oscarssanchez) and [@felipeelia](https://github.com/felipeelia) via [#43](https://github.com/10up/debug-bar-elasticpress/pull/43)
* Log of bulk_index requests. Props [@felipeelia](https://github.com/felipeelia) via [#44](https://github.com/10up/debug-bar-elasticpress/pull/44)
* Warning when ElasticPress is indexing. Props [@nathanielks](https://github.com/nathanielks) and [@felipeelia](https://github.com/felipeelia) via [#45](https://github.com/10up/debug-bar-elasticpress/pull/45)

### Changed
* Only load CSS and JS files for logged-in users. Props [@cbratschi](https://github.com/cbratschi) and [@felipeelia](https://github.com/felipeelia) via [#47](https://github.com/10up/debug-bar-elasticpress/pull/47)

## [2.0.0] - 2021-04-19

This release drops the support for older versions of WordPress Core, ElasticPress and Debug Bar.

* Code refactoring. Props [@felipeelia](https://github.com/felipeelia)
* Fixed Query Logs in EP Dashboard [@felipeelia](https://github.com/felipeelia)
* Fixed typo from "clsas" to "class" in the query output. Props [@Rahmon](https://github.com/Rahmon)

## [1.4]
## [1.4] - 2019-03-01
* Support ElasticPress 3.0+

## [1.3]
## [1.3] - 2017-08-23
* Add query log

## [1.2]
## [1.2] - 2017-03-15
* Show query errors (i.e. cURL timeout)
* Add ?explain to query if GET param is set

## [1.1.1]
## [1.1.1] - 2016-12-13
* Only show query body if it exits

## [1.1]
## [1.1] - 2016-07-25
* Improve formatting
* Show original query args (EP 2.1+)

## [1.0]
## [1.0] - 2016-01-20
* Initial release

[Unreleased]: https://github.com/10up/debug-bar-elasticpress/compare/trunk...develop
[2.1.0]: https://github.com/10up/debug-bar-elasticpress/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/10up/debug-bar-elasticpress/compare/1.4...2.0.0
[1.4]: https://github.com/10up/debug-bar-elasticpress/compare/1.3...1.4
[1.3]: https://github.com/10up/debug-bar-elasticpress/compare/1.2...1.3
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following individuals are responsible for curating the list of issues, respo

Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc.

[Taylor Lovett (@tlovett1)](https://github.com/tlovett1), [Ivan Kristianto (@ivankristianto)](https://github.com/ivankristianto), [Allan Collins (@allan23)](https://github.com/allan23), [Eugene Manuilov (@eugene-manuilov)](https://github.com/eugene-manuilov), [Ricardo Moraleida (@moraleida)](https://github.com/moraleida), [Andreas Ek @ekandreas](https://github.com/ekandreas), [Nathaniel @nathanielks](https://github.com/nathanielks), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Felipe Elia (@felipeelia)](https://github.com/felipeelia), and [Ramon Ahnert @Rahmon](https://github.com/Rahmon).
[Taylor Lovett (@tlovett1)](https://github.com/tlovett1), [Ivan Kristianto (@ivankristianto)](https://github.com/ivankristianto), [Allan Collins (@allan23)](https://github.com/allan23), [Eugene Manuilov (@eugene-manuilov)](https://github.com/eugene-manuilov), [Ricardo Moraleida (@moraleida)](https://github.com/moraleida), [Andreas Ek (@ekandreas)](https://github.com/ekandreas), [Nathaniel (@nathanielks)](https://github.com/nathanielks), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Felipe Elia (@felipeelia)](https://github.com/felipeelia), [Ramon Ahnert (@Rahmon)](https://github.com/Rahmon), [Oscar Sanchez S. (@oscarssanchez)](https://github.com/oscarssanchez), [Nathaniel (@nathanielks)](https://github.com/nathanielks), and [Christoph Bratschi (@cbratschi)](https://github.com/cbratschi).

## Libraries

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> A WordPress plugin that adds a [Debug Bar](https://wordpress.org/plugins/debug-bar/) panel to examine ElasticPress queries.
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Release Version](https://img.shields.io/github/tag/10up/debug-bar-elasticpress.svg?label=release)](https://github.com/10up/debug-bar-elasticpress/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v5.7%20tested-success.svg) [![GPLv2 License](https://img.shields.io/github/license/10up/debug-bar-elasticpress.svg)](https://github.com/10up/debug-bar-elasticpress/blob/trunk/LICENSE.md)
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Release Version](https://img.shields.io/github/tag/10up/debug-bar-elasticpress.svg?label=release)](https://github.com/10up/debug-bar-elasticpress/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v5.8%20tested-success.svg) [![GPLv2 License](https://img.shields.io/github/license/10up/debug-bar-elasticpress.svg)](https://github.com/10up/debug-bar-elasticpress/blob/trunk/LICENSE.md)

## Requirements

Expand Down
7 changes: 7 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.ep-debug-bar-warning {
background-color: #ffffe0;
border: 1px solid #e6db55;
clear: both;
padding: 0.5em 10px;
}

.ep-queries-debug .dashicons {
cursor: pointer;
}
Expand Down
15 changes: 13 additions & 2 deletions classes/class-ep-debug-bar-elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public function init() {
* Enqueue scripts for front end and admin
*/
public function enqueue_scripts_styles() {
wp_enqueue_script( 'debug-bar-elasticpress', plugins_url( '../assets/js/main.js', __FILE__ ), array( 'wp-dom-ready' ), EP_DEBUG_VERSION, true );
wp_enqueue_style( 'debug-bar-elasticpress', plugins_url( '../assets/css/main.css', __FILE__ ), array(), EP_DEBUG_VERSION );
if ( ! is_user_logged_in() ) {
return;
}

wp_enqueue_script( 'debug-bar-elasticpress', EP_DEBUG_URL . 'assets/js/main.js', array( 'wp-dom-ready' ), EP_DEBUG_VERSION, true );
wp_enqueue_style( 'debug-bar-elasticpress', EP_DEBUG_URL . 'assets/css/main.css', array(), EP_DEBUG_VERSION );
}

/**
Expand Down Expand Up @@ -92,6 +96,13 @@ public function render() {
);
?>
</h2>

<?php if ( function_exists( '\ElasticPress\Utils\is_indexing' ) && \ElasticPress\Utils\is_indexing() ) : ?>
<div class="ep-debug-bar-warning">
<?php esc_html_e( 'ElasticPress is currently indexing.', 'debug-bar-elasticpress' ); ?>
</div>
<?php endif; ?>

<?php if ( empty( $queries ) ) : ?>
<ol class="wpd-queries">
<li><?php esc_html_e( 'No queries to show', 'debug-bar-elasticpress' ); ?></li>
Expand Down
11 changes: 10 additions & 1 deletion classes/class-ep-debug-bar-query-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ public static function render_query( $query, $type = '' ) {
<?php if ( ! empty( $query['args']['body'] ) ) : ?>
<div class="ep-query-body">
<strong><?php esc_html_e( 'Query Body:', 'debug-bar-elasticpress' ); ?> <div class="query-body-toggle dashicons"></div></strong>
<pre class="query-body"><?php echo esc_html( stripslashes( wp_json_encode( json_decode( $query['args']['body'], true ), JSON_PRETTY_PRINT ) ) ); ?></pre>
<?php
// Bulk indexes are not "valid" JSON, for example.
$body = json_decode( $query['args']['body'], true );
if ( json_last_error() === JSON_ERROR_NONE ) {
$body = wp_json_encode( $body, JSON_PRETTY_PRINT );
} else {
$body = $query['args']['body'];
}
?>
<pre class="query-body"><?php echo esc_html( stripslashes( $body ) ); ?></pre>
</div>
<?php endif; ?>

Expand Down
18 changes: 18 additions & 0 deletions classes/class-ep-query-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ public function is_query_error( $query ) {
return ( $response_code < 200 || $response_code > 299 );
}

/**
* Check the request body, as usually bulk indexing does not return a status error.
*
* @since 2.1.0
* @param array $query Remote request arguments
* @return boolean
*/
public function is_bulk_index_error( $query ) {
if ( $this->is_query_error( $query ) ) {
return true;
}

$request_body = json_decode( wp_remote_retrieve_body( $query['request'] ), true );
return ! empty( $request_body['errors'] );
}

/**
* Conditionally save a query to the log which is stored in options. This is a big performance hit so be careful.
*
Expand All @@ -143,13 +159,15 @@ public function log_query( $query, $type ) {
*
* @var array
* @since 1.3
* @since 2.1.0 Added `bulk_index`
*/
$allowed_log_types = apply_filters(
'ep_debug_bar_allowed_log_types',
array(
'put_mapping' => array( $this, 'is_query_error' ),
'delete_network_alias' => array( $this, 'is_query_error' ),
'create_network_alias' => array( $this, 'is_query_error' ),
'bulk_index' => array( $this, 'is_bulk_index_error' ),
'bulk_index_posts' => array( $this, 'is_query_error' ),
'delete_index' => array( $this, 'maybe_log_delete_index' ),
'create_pipeline' => array( $this, 'is_query_error' ),
Expand Down
39 changes: 36 additions & 3 deletions debug-bar-elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://wordpress.org/plugins/debug-bar-elasticpress
* Description: Extends the debug bar plugin for ElasticPress queries.
* Author: 10up
* Version: 2.0.0
* Version: 2.1.0
* Author URI: https://10up.com
* Requires PHP: 5.4
* License: GPLv2
Expand All @@ -13,7 +13,8 @@
* @package DebugBarElasticPress
*/

define( 'EP_DEBUG_VERSION', '2.0.0' );
define( 'EP_DEBUG_VERSION', '2.1.0' );
define( 'EP_DEBUG_URL', plugin_dir_url( __FILE__ ) );

/**
* Register panel
Expand All @@ -26,9 +27,41 @@ function ep_add_debug_bar_panel( $panels ) {
$panels[] = new EP_Debug_Bar_ElasticPress();
return $panels;
}

add_filter( 'debug_bar_panels', 'ep_add_debug_bar_panel' );

/**
* Register status
*
* @since 2.1.0
* @param array $stati Debug Bar Stati
* @return array
*/
function ep_add_debug_bar_stati( $stati ) {
$stati[] = array(
'ep_version',
esc_html__( 'ElasticPress Version', 'debug-bar-elasticpress' ),
defined( 'EP_VERSION' ) ? EP_VERSION : '',
);

$elasticsearch_version = '';
if (
class_exists( '\ElasticPress\Elasticsearch' ) &&
method_exists( \ElasticPress\Elasticsearch::factory(), 'get_elasticsearch_version' )
) {
$elasticsearch_version = \ElasticPress\Elasticsearch::factory()->get_elasticsearch_version();
}
if ( function_exists( '\ElasticPress\Utils\is_epio' ) && \ElasticPress\Utils\is_epio() ) {
$elasticsearch_version = esc_html__( 'ElasticPress.io Managed Platform', 'debug-bar-elasticpress' );
}
$stati[] = array(
'es_version',
esc_html__( 'Elasticsearch Version', 'debug-bar-elasticpress' ),
$elasticsearch_version,
);
return $stati;
}
add_filter( 'debug_bar_statuses', 'ep_add_debug_bar_stati' );

/**
* Add explain=true to elastic post query
*
Expand Down
Loading

0 comments on commit 2b04153

Please sign in to comment.