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

Add messages regarding resyncs and Instant Results #2628

Merged
merged 5 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Set message about Instant Results and version upgrade resyncs
  • Loading branch information
felipeelia committed Mar 7, 2022
commit 50ebe2f6ba06fc5c86ee65832874546b71566b27
32 changes: 27 additions & 5 deletions includes/classes/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,34 @@ public function resync_notice_4_0_0_instant_results( $notices ) {

$feature_status = $instant_results->requirements_status();
$appended_message = '';
if ( 1 < $feature_status->code ) {
$appended_message = esc_html__( 'PLACEHOLDER: Instant Results not available', 'elasticpress' );
} elseif ( \ElasticPress\Utils\is_epio() ) {
$appended_message = esc_html__( 'PLACEHOLDER: Instant Results available via EP.io', 'elasticpress' );
if ( 1 >= $feature_status->code ) {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$features_url = admin_url( 'network/admin.php?page=elasticpress' );
} else {
$features_url = admin_url( 'admin.php?page=elasticpress' );
}

$appended_message = wp_kses_post(
sprintf(
/* translators: 1: <a> tag (Zendesk article); 2. </a>; 3: <a> tag (link to Features screen); 4. </a>; */
__( '%1$sInstant Results%2$s is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, click %3$shere%4$s to activate the feature and start your sync.', 'elasticpress' ),
'<a href="https://elasticpress.zendesk.com/hc/en-us/articles/360050447492#instant-results">',
'</a>',
'<a href="' . $features_url . '">',
'</a>'
)
);
} else {
$appended_message = esc_html__( 'PLACEHOLDER: Instant Results available via custom proxy', 'elasticpress' );
$appended_message = wp_kses_post(
sprintf(
/* translators: 1: <a> tag (Zendesk article about Instant Results); 2. </a>; 3: <a> tag (Zendesk article about self hosted Elasticsearch setups); 4. </a>; */
__( '%1$sInstant Results%2$s is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, since you are not using ElasticPress.io, you will also need to %3$sinstall and configure a PHP proxy%4$s.', 'elasticpress' ),
'<a href="https://elasticpress.zendesk.com/hc/en-us/articles/360050447492#instant-results">',
'</a>',
'<a href="https://elasticpress.zendesk.com/hc/en-us/articles/4413938931853-Considerations-for-self-hosted-Elasticsearch-setups">',
'</a>'
)
);
}

$notices['upgrade_sync']['html'] .= '<br><br>' . $appended_message;
Expand Down
15 changes: 12 additions & 3 deletions tests/php/TestAdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,25 +398,34 @@ public function testUpgradeSyncNoticeAndInstantResultsInAdmin() {
ElasticPress\Screen::factory()->set_current_screen( null );

// Instant Results not available.
$not_available_full_text = '<a href="https://elasticpress.zendesk.com/hc/en-us/articles/360050447492#instant-results">Instant Results</a> is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, since you are not using ElasticPress.io, you will also need to <a href="https://elasticpress.zendesk.com/hc/en-us/articles/4413938931853-Considerations-for-self-hosted-Elasticsearch-setups">install and configure a PHP proxy</a>.';
ElasticPress\AdminNotices::factory()->process_notices();
$notices = ElasticPress\AdminNotices::factory()->get_notices();
$this->assertTrue( ! empty( $notices['upgrade_sync'] ) );
$this->assertContains( 'PLACEHOLDER: Instant Results not available', $notices['upgrade_sync']['html'] );
$this->assertContains( $not_available_full_text, $notices['upgrade_sync']['html'] );

// Instant Results available.
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$features_url = admin_url( 'network/admin.php?page=elasticpress' );
} else {
$features_url = admin_url( 'admin.php?page=elasticpress' );
}
$available_full_text = '<a href="https://elasticpress.zendesk.com/hc/en-us/articles/360050447492#instant-results">Instant Results</a> is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, click <a href="' . $features_url . '">here</a> to activate the feature and start your sync.';

// Instant Results available via custom proxy.
add_filter( 'ep_instant_results_available', '__return_true' );
ElasticPress\AdminNotices::factory()->process_notices();
$notices = ElasticPress\AdminNotices::factory()->get_notices();
$this->assertTrue( ! empty( $notices['upgrade_sync'] ) );
$this->assertContains( 'PLACEHOLDER: Instant Results available via custom proxy', $notices['upgrade_sync']['html'] );
$this->assertContains( $available_full_text, $notices['upgrade_sync']['html'] );
remove_filter( 'ep_instant_results_available', '__return_true' );

// Instant Results available via EP.io.
update_site_option( 'ep_host', 'https://prefix.elasticpress.io/' );
ElasticPress\AdminNotices::factory()->process_notices();
$notices = ElasticPress\AdminNotices::factory()->get_notices();
$this->assertTrue( ! empty( $notices['upgrade_sync'] ) );
$this->assertContains( 'PLACEHOLDER: Instant Results available via EP.io', $notices['upgrade_sync']['html'] );
$this->assertContains( $available_full_text, $notices['upgrade_sync']['html'] );
}

/**
Expand Down