Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whether a resync should be tried or not #3898

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions includes/classes/ElasticsearchErrorInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public function maybe_suggest_solution_for_es( $error ) {
}

if ( Utils\is_epio() ) {
if ( preg_match( '/you have reached the limit of indices your plan supports/', $error, $matches ) ) {
return [
'error' => $error,
'solution' => sprintf(
/* translators: ElasticPress.io Article URL */
__( 'Please refer to <a href="%s">this article</a> outlining how to address this issue.', 'elasticpress' ),
'https://elasticpress.zendesk.com/hc/en-us/articles/26165267320461'
),
];
}
return [
'error' => $error,
'solution' => sprintf(
Expand Down
16 changes: 14 additions & 2 deletions includes/classes/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,10 @@ protected function on_error_update_and_clean( $error, $context = 'sync' ) {
esc_html__( 'Mapping failed: %s', 'elasticpress' ),
Utils\get_elasticsearch_error_reason( $error['message'] )
);
$message .= "\n";
$message .= esc_html__( 'Mapping has failed, which will cause ElasticPress search results to be incorrect. Please click `Delete all Data and Start a Fresh Sync` to retry mapping.', 'elasticpress' );
if ( $this->should_suggest_retry( $message ) ) {
$message .= "\n";
$message .= esc_html__( 'Mapping has failed, which will cause ElasticPress search results to be incorrect. Please click `Delete all Data and Start a Fresh Sync` to retry mapping.', 'elasticpress' );
}
break;
default:
/* translators: Error message */
Expand Down Expand Up @@ -1523,6 +1525,16 @@ protected function maybe_apply_feature_settings() {
Features::factory()->apply_draft_feature_settings();
}

/**
* Whether to suggest retrying the sync or not.
*
* @param string $message The message returned by the hosting server
* @return boolean
*/
protected function should_suggest_retry( $message ) {
return ! preg_match( '/you have reached the limit of indices your plan supports/', $message );
}

/**
* Return singleton instance of class.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/php/TestElasticsearchErrorInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,23 @@ public function test_maybe_suggest_solution_for_es_limit_fields() {
$this->assertSame( 'Limit of total fields [???] in index [???] has been exceeded', $suggested['error'] );
$this->assertSame( $solution, $suggested['solution'] );
}

/**
* Test the `maybe_suggest_solution_for_es` method when the indices limit was reached on EP.io
*
* @since 5.1.0
* @group elasticsearch-error-interpreter
*/
public function test_maybe_suggest_solution_for_es_limit_of_indices() {
$this->force_epio();

$error_interpreter = new ElasticsearchErrorInterpreter();

$error = 'It seems you have reached the limit of indices your plan supports and we were not able to create a new index. Currently, you can have up to 3 indices.';
$solution = 'Please refer to <a href="https://elasticpress.zendesk.com/hc/en-us/articles/26165267320461">this article</a> outlining how to address this issue.';
$suggested = $error_interpreter->maybe_suggest_solution_for_es( $error );

$this->assertSame( $error, $suggested['error'] );
$this->assertSame( $solution, $suggested['solution'] );
}
}
9 changes: 9 additions & 0 deletions tests/php/includes/classes/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,13 @@ public function assertDecayDisabled( $query ) {
)
);
}

/**
* Forces tests to use EP.io
*
* @since 5.1.0
*/
protected function force_epio() {
update_site_option( 'ep_host', 'https://prefix.elasticpress.io/' );
}
}
Loading