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 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
6 changes: 3 additions & 3 deletions includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ protected function process_upgrade_sync_notice() {
}

if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
$html = esc_html__( 'Dashboard sync is disabled. The new version of ElasticPress requires that you to reindex using WP-CLI.', 'elasticpress' );
$html = esc_html__( 'Dashboard sync is disabled. The new version of ElasticPress requires that you delete all data and start a fresh sync using WP-CLI.', 'elasticpress' );
} else {
$html = sprintf( __( 'The new version of ElasticPress requires that you <a href="%s">run a sync</a>.', 'elasticpress' ), esc_url( $url ) );
$html = sprintf( __( 'The new version of ElasticPress requires that you <a href="%s">delete all data and start a fresh sync</a>.', 'elasticpress' ), esc_url( $url ) );
}

$notice = esc_html__( 'Please note that some ElasticPress functionality may be impaired and/or content may not be searchable until the reindex has been performed.', 'elasticpress' );
$notice = esc_html__( 'Please note that some ElasticPress functionality may be impaired and/or content may not be searchable until the full sync has been performed.', 'elasticpress' );

return [
'html' => '<span class="dashicons dashicons-warning"></span> ' . $html . ' ' . $notice,
Expand Down
59 changes: 59 additions & 0 deletions includes/classes/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function setup() {
} else {
update_option( 'ep_version', sanitize_text_field( EP_VERSION ) );
}

add_filter( 'ep_admin_notices', [ $this, 'resync_notice_4_0_0_instant_results' ] );
}

/**
Expand Down Expand Up @@ -166,6 +168,63 @@ public function upgrade_3_6_6() {
}
}

/**
* Adjust the upgrade sync notice to warn users about Instant Results.
*
* As 4.0.0 introduces this new feature and it requires a resync, admin users
* might want to enable the feature before the resync (and then resync only once.)
*
* @since 4.0.0
* @param array $notices All admin notices
* @return array
*/
public function resync_notice_4_0_0_instant_results( $notices ) {
if ( ! isset( $notices['upgrade_sync'] ) ) {
return $notices;
}

$instant_results = \ElasticPress\Features::factory()->get_registered_feature( 'instant-results' );
if ( $instant_results->is_active() ) {
return $notices;
}

$feature_status = $instant_results->requirements_status();
$appended_message = '';
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 = 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;

return $notices;
}

/**
* Check if a reindex is needed based on the version number.
*/
Expand Down
53 changes: 53 additions & 0 deletions tests/php/TestAdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,59 @@ public function testUpgradeSyncNoticeInAdmin() {
$this->assertTrue( ! empty( $notices['upgrade_sync'] ) );
}

/**
* Conditions:
*
* - In admin
* - Host set
* - Old version of ElasticPress
* - Upgrade sync is needed
* - Elasticsearch version within bounds
*
* Do: Show upgrade sync with complement related to Instant Results
*
* @group admin-notices
* @since 4.0.0
*/
public function testUpgradeSyncNoticeAndInstantResultsInAdmin() {
update_site_option( 'ep_last_sync', time() );
update_site_option( 'ep_need_upgrade_sync', true );
update_site_option( 'ep_version', '3.6.6' );
delete_site_option( 'ep_feature_auto_activated_sync' );

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( $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( $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( $available_full_text, $notices['upgrade_sync']['html'] );
}

/**
* Conditions:
*
Expand Down