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 +18 -67 4.7.05.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
@@ -107,9 +107,9 @@
107 107 * Return the output of a button to clear the logged queries
108 108 *
109 109 * @return string
110 110 */
111 - public function get_actions() : array {
111 + public function get_actions(): array {
112 112 global $wp;
113 113
114 114 $logs = $this->query_logger->get_logs( false );
115 115
@@ -131,9 +131,9 @@
131 131 /**
132 132 * If a nonce is present, clear the logs
133 133 */
134 134 protected function maybe_clear_logs() {
135 - if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_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' ) ) {
136 136 return;
137 137 }
138 138
139 139 $this->query_logger->clear_logs();
@@ -154,12 +154,19 @@
154 154 * @param array $log The log
155 155 * @return array The error in index 0, solution in index 1
156 156 */
157 157 public function analyze_log( $log ) {
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 + ];
163 + }
164 +
158 165 $error = Utils\get_elasticsearch_error_reason( $log );
159 166
160 167 $solution = ( ! empty( $error ) ) ?
161 - $this->maybe_suggest_solution_for_es( $error ) :
168 + ( new \ElasticPress\ElasticsearchErrorInterpreter() )->maybe_suggest_solution_for_es( $error )['solution'] :
162 169 '';
163 170
164 171 return [ $error, $solution ];
165 172 }
@@ -164,72 +171,16 @@
164 171 return [ $error, $solution ];
165 172 }
166 173
167 174 /**
168 - * Given an Elasticsearch error, try to suggest a solution
175 + * DEPRECATED. Given an Elasticsearch error, try to suggest a solution
169 176 *
177 + * @deprecated 5.0.0
170 178 * @param string $error The error
171 179 * @return string
172 180 */
173 181 protected function maybe_suggest_solution_for_es( $error ) {
174 - $sync_url = Utils\get_sync_url();
182 + _deprecated_function( __METHOD__, '5.0.0', '\ElasticPress\ElasticsearchErrorInterpreter::maybe_suggest_solution_for_es()' );
175 183
176 - if ( preg_match( '/no such index \[(.*?)\]/', $error, $matches ) ) {
177 - return sprintf(
178 - /* translators: 1. Index name; 2. Sync Page URL */
179 - __( 'It seems the %1$s index is missing. <a href="%2$s">Delete all data and sync</a> to fix the issue.', 'elasticpress' ),
180 - '<code>' . $matches[1] . '</code>',
181 - $sync_url
182 - );
183 - }
184 -
185 - if ( preg_match( '/No mapping found for \[(.*?)\] in order to sort on/', $error, $matches ) ) {
186 - return sprintf(
187 - /* translators: 1. Index name; 2. Sync Page URL */
188 - __( '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' ),
189 - '<code>' . $matches[1] . '</code>',
190 - $sync_url
191 - );
192 - }
193 -
194 - /* translators: 1. Field name; 2. Sync Page URL */
195 - $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' );
196 -
197 - if ( preg_match( '/Fielddata is disabled on text fields by default. Set fielddata=true on \[(.*?)\]/', $error, $matches ) ) {
198 - return sprintf( $field_type_solution, $matches[1], $sync_url );
199 - }
200 -
201 - if ( preg_match( '/field \[(.*?)\] is of type \[(.*?)\], but only numeric types are supported./', $error, $matches ) ) {
202 - return sprintf( $field_type_solution, $matches[1], $sync_url );
203 - }
204 -
205 - if ( preg_match( '/Alternatively, set fielddata=true on \[(.*?)\] in order to load field data by uninverting the inverted index./', $error, $matches ) ) {
206 - return sprintf( $field_type_solution, $matches[1], $sync_url );
207 - }
208 -
209 - if ( preg_match( '/Limit of total fields \[(.*?)\] in index \[(.*?)\] has been exceeded/', $error, $matches ) ) {
210 - return sprintf(
211 - /* translators: Elasticsearch or ElasticPress.io; 2. Link to article; 3. Link to article */
212 - __( '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' ),
213 - Utils\is_epio() ? __( 'ElasticPress.io', 'elasticpress' ) : __( 'Elasticsearch', 'elasticpress' ),
214 - 'https://elasticpress.zendesk.com/hc/en-us/articles/360051401212-I-get-the-error-Limit-of-total-fields-in-index-has-been-exceeded-',
215 - 'https://elasticpress.zendesk.com/hc/en-us/articles/360052019111'
216 - );
217 - }
218 -
219 - // field limit
220 -
221 - if ( Utils\is_epio() ) {
222 - return sprintf(
223 - /* translators: ElasticPress.io My Account URL */
224 - __( 'We did not recognize this error. Please open an ElasticPress.io <a href="%s">support ticket</a> so we can troubleshoot further.', 'elasticpress' ),
225 - 'https://www.elasticpress.io/my-account/'
226 - );
227 - }
228 -
229 - return sprintf(
230 - /* translators: New GitHub issue URL */
231 - __( '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' ),
232 - 'https://github.com/10up/ElasticPress/issues/new/choose'
233 - );
184 + return ( new \ElasticPress\ElasticsearchErrorInterpreter() )->maybe_suggest_solution_for_es( $error )['solution'];
234 185 }
235 186 }