From 07b76595691ac623c63fab8f0dfa16762173c3cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Jul 2023 00:16:39 +0000 Subject: [PATCH 01/22] Bump tough-cookie from 4.1.2 to 4.1.3 Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from 4.1.2 to 4.1.3. - [Release notes](https://github.com/salesforce/tough-cookie/releases) - [Changelog](https://github.com/salesforce/tough-cookie/blob/master/CHANGELOG.md) - [Commits](https://github.com/salesforce/tough-cookie/compare/v4.1.2...v4.1.3) --- updated-dependencies: - dependency-name: tough-cookie dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 34b597e..a1020a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17093,9 +17093,9 @@ } }, "node_modules/tough-cookie": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz", - "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", "dev": true, "dependencies": { "psl": "^1.1.33", From 0162237c7327148078f108ecae6d14f7b5f38859 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Jul 2023 01:39:20 +0000 Subject: [PATCH 02/22] Bump word-wrap from 1.2.3 to 1.2.4 Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 34b597e..44862c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18165,9 +18165,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", + "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==", "dev": true, "engines": { "node": ">=0.10.0" From 707f427756b0224f5a63f31ce3471d21867d54fa Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Mon, 21 Aug 2023 11:20:37 +0500 Subject: [PATCH 03/22] Add Addition Buttons (Explain queries & Query document from ES) --- classes/EP_Debug_Bar_ElasticPress.php | 1 + classes/QueryOutput.php | 101 ++++++++++++++++++++++++++ debug-bar-elasticpress.php | 31 ++++++++ 3 files changed, 133 insertions(+) diff --git a/classes/EP_Debug_Bar_ElasticPress.php b/classes/EP_Debug_Bar_ElasticPress.php index 9b21cea..61d3e5c 100755 --- a/classes/EP_Debug_Bar_ElasticPress.php +++ b/classes/EP_Debug_Bar_ElasticPress.php @@ -94,6 +94,7 @@ public function render() { render_buttons(); + $debug_bar_output->render_additional_buttons(); $debug_bar_output->render_queries(); } } diff --git a/classes/QueryOutput.php b/classes/QueryOutput.php index e1ca6a1..81b837c 100644 --- a/classes/QueryOutput.php +++ b/classes/QueryOutput.php @@ -298,4 +298,105 @@ protected function render_value( $value ) { return (string) $value; } + + /** + * Render the additional buttons. + * + * @since 3.1.0 + * @return void + */ + public function render_additional_buttons() { + $buttons = [ + $this->get_explain_query_button(), + $this->get_retrieve_raw_document_button(), + ]; + + /** + * Filter the additional buttons. + * + * @since 3.1.0 + * @hook ep_debug_bar_additional_buttons + * @param array $buttons Buttons. + * @return array + */ + apply_filters( 'ep_debug_bar_additional_buttons', $buttons ); + + $buttons = array_filter( $buttons ); + + if ( empty( $buttons ) ) { + return; + } + + ?> +
+ +
+ queries ) ) { + return ''; + } + + $button_link = add_query_arg( + [ + 'explain' => '1', + ], + isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '' + ); + + return sprintf( + ' + %s + ', + esc_url( $button_link ), + esc_html__( 'Explain queries', 'debug-bar-elasticpress' ) + ); + } + + /** + * Get the retrieve raw document button. + * + * @since 3.1.0 + * @return string + */ + public function get_retrieve_raw_document_button() : string { + if ( ! is_singular() ) { + return ''; + } + + $post_type = get_post_type(); + $post_indexable = \ElasticPress\Indexables::factory()->get( 'post' ); + + $indexable_post_types = $post_indexable->get_indexable_post_types(); + if ( ! in_array( $post_type, $indexable_post_types, true ) ) { + return ''; + } + + $button_link = add_query_arg( + [ + 'retrieve-raw-es-document' => '1', + ], + isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '' + ); + + return sprintf( + ' + %s + ', + esc_url( $button_link ), + esc_html__( 'Reload and retrieve raw ES document', 'debug-bar-elasticpress' ) + ); + } } diff --git a/debug-bar-elasticpress.php b/debug-bar-elasticpress.php index bafb669..25e9ef4 100755 --- a/debug-bar-elasticpress.php +++ b/debug-bar-elasticpress.php @@ -67,6 +67,8 @@ function setup() { add_filter( 'debug_bar_statuses', $n( 'add_debug_bar_stati' ) ); add_filter( 'ep_formatted_args', $n( 'add_explain_args' ), 10, 2 ); + add_action( 'wp', $n( 'retrieve_raw_document_from_es' ) ); + load_plugin_textdomain( 'debug-bar-elasticpress', false, basename( __DIR__ ) . '/lang' ); QueryLog::factory(); @@ -152,3 +154,32 @@ function admin_notice_min_ep_version() { get( 'post' ); + $indexable_post_types = $post_indexable->get_indexable_post_types(); + + if ( ! in_array( $post_type, $indexable_post_types, true ) ) { + return; + } + + $post_indexable->get( $id ); +} From c09c28c2d9b83f81c8a376109883ec75a1e55ef9 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 5 Sep 2023 14:16:00 -0300 Subject: [PATCH 04/22] Unify checks + Nonce verification + CSS --- assets/css/main.css | 24 +++++++++++++----------- classes/QueryOutput.php | 19 ++++++------------- debug-bar-elasticpress.php | 31 ++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/assets/css/main.css b/assets/css/main.css index 51ebf0e..1d27389 100755 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -43,7 +43,10 @@ } .ep-queries-buttons-wrapper { + align-items: center; clear: both; + display: flex; + gap: 10px; padding: 1em 0; } @@ -76,12 +79,10 @@ * override QM's important rules */ #debug-menu-target-EP_Debug_Bar_ElasticPress .button, -#debug-menu-target-EP_Debug_Bar_ElasticPress a.button, -#debug-menu-target-EP_Debug_Bar_ElasticPress button.ep-copy-button.button.qm-button { +#debug-menu-target-EP_Debug_Bar_ElasticPress a.button { background: #f6f7f7 !important; - border-color: #2271b1 !important; + border: 1px solid #2271b1 !important; border-radius: 3px !important; - border-width: 1px; /* Overriding some Debug Bar "important" rules */ color: #2271b1 !important; @@ -95,16 +96,18 @@ text-shadow: none; } -#debug-menu-target-EP_Debug_Bar_ElasticPress .button:hover { +#debug-menu-target-EP_Debug_Bar_ElasticPress .button:hover, +#query-monitor-main #qm-debug_bar_ep_debug_bar_elasticpress .button:hover { background: #f0f0f1; border-color: #0a4b78; - color: #0a4b78; - text-decoration: none; + color: #0a4b78 !important; + text-decoration: none !important; } -#debug-menu-target-EP_Debug_Bar_ElasticPress .button:active { - background: #f6f7f7; - border-color: #8c8f94; +#debug-menu-target-EP_Debug_Bar_ElasticPress .button:active, +#query-monitor-main #qm-debug_bar_ep_debug_bar_elasticpress .button:hover { + background: #f6f7f7 !important; + border-color: #8c8f94 !important; box-shadow: none; } @@ -119,7 +122,6 @@ background: #007cba !important; border: 1px solid #007cba !important; color: #fff !important; - margin-right: 5px !important; } #debug-menu-target-EP_Debug_Bar_ElasticPress a.button-primary:hover, diff --git a/classes/QueryOutput.php b/classes/QueryOutput.php index 81b837c..fc5888d 100644 --- a/classes/QueryOutput.php +++ b/classes/QueryOutput.php @@ -52,7 +52,7 @@ public function render_buttons() { -