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/StatusReport/FailedQueries.php +27 -74 4.4.15.3.5 View file →
@@ -7,10 +7,10 @@
7 7 */
8 8
9 9 namespace ElasticPress\StatusReport;
10 10
11 -use \ElasticPress\QueryLogger;
12 -use \ElasticPress\Utils;
11 +use ElasticPress\QueryLogger;
12 +use ElasticPress\Utils;
13 13
14 14 defined( 'ABSPATH' ) || exit;
15 15
16 16 /**
@@ -40,9 +40,9 @@
40 40 * Return the report title
41 41 *
42 42 * @return string
43 43 */
44 - public function get_title() : string {
44 + public function get_title(): string {
45 45 return __( 'Failed Queries', 'elasticpress' );
46 46 }
47 47
48 48 /**
@@ -49,9 +49,9 @@
49 49 * Return the report fields
50 50 *
51 51 * @return array
52 52 */
53 - public function get_groups() : array {
53 + public function get_groups(): array {
54 54 $this->maybe_clear_logs();
55 55
56 56 $logs = $this->query_logger->get_logs( false );
57 57
@@ -57,8 +57,9 @@
57 57
58 58 $labels = [
59 59 'wp_url' => esc_html__( 'Page URL', 'elasticpress' ),
60 60 'es_req' => esc_html__( 'Elasticsearch Request', 'elasticpress' ),
61 + 'request_id' => esc_html__( 'Request ID', 'elasticpress' ),
61 62 'timestamp' => esc_html__( 'Time', 'elasticpress' ),
62 63 'query_time' => esc_html__( 'Time Spent (ms)', 'elasticpress' ),
63 64 'wp_args' => esc_html__( 'WP Query Args', 'elasticpress' ),
64 65 'status_code' => esc_html__( 'HTTP Status Code', 'elasticpress' ),
@@ -106,9 +107,9 @@
106 107 * Return the output of a button to clear the logged queries
107 108 *
108 109 * @return string
109 110 */
110 - public function get_actions() : array {
111 + public function get_actions(): array {
111 112 global $wp;
112 113
113 114 $logs = $this->query_logger->get_logs( false );
114 115
@@ -130,13 +131,22 @@
130 131 /**
131 132 * If a nonce is present, clear the logs
132 133 */
133 134 protected function maybe_clear_logs() {
134 - if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'ep-clear-logged-queries' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
135 + if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'ep-clear-logged-queries' ) ) {
135 136 return;
136 137 }
137 138
138 139 $this->query_logger->clear_logs();
140 +
141 + if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
142 + $redirect_url = network_admin_url( 'admin.php?page=elasticpress-status-report' );
143 + } else {
144 + $redirect_url = admin_url( 'admin.php?page=elasticpress-status-report' );
145 + }
146 +
147 + wp_safe_redirect( $redirect_url );
148 + exit();
139 149 }
140 150
141 151 /**
142 152 * Given a log, try to find the error and its solution
@@ -144,20 +154,19 @@
144 154 * @param array $log The log
145 155 * @return array The error in index 0, solution in index 1
146 156 */
147 157 public function analyze_log( $log ) {
148 - $error = '';
149 -
150 - if ( ! empty( $log['result']['error'] ) && ! empty( $log['result']['error']['root_cause'][0]['reason'] ) ) {
151 - $error = $log['result']['error']['root_cause'][0]['reason'];
158 + if ( is_array( $log['result'] ) && ! empty( $log['result']['is_wp_error'] ) ) {
159 + return [
160 + $log['result']['message'],
161 + __( 'It seems WordPress was not able to complete the request. Review the error message and your configuration.', 'elasticpress' ),
162 + ];
152 163 }
153 164
154 - if ( ! empty( $log['result']['errors'] ) && ! empty( $log['result']['items'] ) && ! empty( $log['result']['items'][0]['index']['error']['reason'] ) ) {
155 - $error = $log['result']['items'][0]['index']['error']['reason'];
156 - }
165 + $error = Utils\get_elasticsearch_error_reason( $log );
157 166
158 167 $solution = ( ! empty( $error ) ) ?
159 - $this->maybe_suggest_solution_for_es( $error ) :
168 + ( new \ElasticPress\ElasticsearchErrorInterpreter() )->maybe_suggest_solution_for_es( $error )['solution'] :
160 169 '';
161 170
162 171 return [ $error, $solution ];
163 172 }
@@ -162,72 +171,16 @@
162 171 return [ $error, $solution ];
163 172 }
164 173
165 174 /**
166 - * Given an Elasticsearch error, try to suggest a solution
175 + * DEPRECATED. Given an Elasticsearch error, try to suggest a solution
167 176 *
177 + * @deprecated 5.0.0
168 178 * @param string $error The error
169 179 * @return string
170 180 */
171 181 protected function maybe_suggest_solution_for_es( $error ) {
172 - $sync_url = Utils\get_sync_url();
182 + _deprecated_function( __METHOD__, '5.0.0', '\ElasticPress\ElasticsearchErrorInterpreter::maybe_suggest_solution_for_es()' );
173 183
174 - if ( preg_match( '/no such index \[(.*?)\]/', $error, $matches ) ) {
175 - return sprintf(
176 - /* translators: 1. Index name; 2. Sync Page URL */
177 - __( 'It seems the %1$s index is missing. <a href="%2$s">Delete all data and sync</a> to fix the issue.', 'elasticpress' ),
178 - '<code>' . $matches[1] . '</code>',
179 - $sync_url
180 - );
181 - }
182 -
183 - if ( preg_match( '/No mapping found for \[(.*?)\] in order to sort on/', $error, $matches ) ) {
184 - return sprintf(
185 - /* translators: 1. Index name; 2. Sync Page URL */
186 - __( 'The field %1$s was not found. Make sure it is added to the list of indexed fields and run <a href="%2$s">a new sync</a> to fix the issue.', 'elasticpress' ),
187 - '<code>' . $matches[1] . '</code>',
188 - $sync_url
189 - );
190 - }
191 -
192 - /* translators: 1. Field name; 2. Sync Page URL */
193 - $field_type_solution = __( 'It seems you saved a post without doing a full sync first because <code>%1$s</code> is missing the correct mapping type. <a href="%2$s">Delete all data and sync</a> to fix the issue.', 'elasticpress' );
194 -
195 - if ( preg_match( '/Fielddata is disabled on text fields by default. Set fielddata=true on \[(.*?)\]/', $error, $matches ) ) {
196 - return sprintf( $field_type_solution, $matches[1], $sync_url );
197 - }
198 -
199 - if ( preg_match( '/field \[(.*?)\] is of type \[(.*?)\], but only numeric types are supported./', $error, $matches ) ) {
200 - return sprintf( $field_type_solution, $matches[1], $sync_url );
201 - }
202 -
203 - if ( preg_match( '/Alternatively, set fielddata=true on \[(.*?)\] in order to load field data by uninverting the inverted index./', $error, $matches ) ) {
204 - return sprintf( $field_type_solution, $matches[1], $sync_url );
205 - }
206 -
207 - if ( preg_match( '/Limit of total fields \[(.*?)\] in index \[(.*?)\] has been exceeded/', $error, $matches ) ) {
208 - return sprintf(
209 - /* translators: Elasticsearch or ElasticPress.io; 2. Link to article; 3. Link to article */
210 - __( 'Your website content has more public custom fields than %1$s is able to store. Check our articles about <a href="%2$s">Elasticsearch field limitations</a> and <a href="%3$s">how to index just the custom fields you need</a> and sync again.', 'elasticpress' ),
211 - Utils\is_epio() ? __( 'ElasticPress.io', 'elasticpress' ) : __( 'Elasticsearch', 'elasticpress' ),
212 - 'https://elasticpress.zendesk.com/hc/en-us/articles/360051401212-I-get-the-error-Limit-of-total-fields-in-index-has-been-exceeded-',
213 - 'https://elasticpress.zendesk.com/hc/en-us/articles/360052019111'
214 - );
215 - }
216 -
217 - // field limit
218 -
219 - if ( Utils\is_epio() ) {
220 - return sprintf(
221 - /* translators: ElasticPress.io My Account URL */
222 - __( 'We did not recognize this error. Please open an ElasticPress.io <a href="%s">support ticket</a> so we can troubleshoot further.', 'elasticpress' ),
223 - 'https://www.elasticpress.io/my-account/'
224 - );
225 - }
226 -
227 - return sprintf(
228 - /* translators: New GitHub issue URL */
229 - __( 'We did not recognize this error. Please consider opening a <a href="%s">GitHub Issue</a> so we can add it to our list of supported errors. ', 'elasticpress' ),
230 - 'https://github.com/10up/ElasticPress/issues/new/choose'
231 - );
184 + return ( new \ElasticPress\ElasticsearchErrorInterpreter() )->maybe_suggest_solution_for_es( $error )['solution'];
232 185 }
233 186 }