From 949f8beaf5e6fabf5bb5be2dc3a5355b5239faf3 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Thu, 3 Mar 2022 11:09:39 -0300 Subject: [PATCH 1/4] Add placeholder messages regarding resyncs and Instant Results --- includes/classes/Upgrades.php | 38 +++++++++++++++++++++++++++++ tests/php/TestAdminNotices.php | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/includes/classes/Upgrades.php b/includes/classes/Upgrades.php index 45c4490924..9a077f4e89 100644 --- a/includes/classes/Upgrades.php +++ b/includes/classes/Upgrades.php @@ -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' ] ); } /** @@ -166,6 +168,42 @@ 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 + * @todo Replace texts + * @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 ) { + $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' ); + } else { + $appended_message = esc_html__( 'PLACEHOLDER: Instant Results available via custom proxy', 'elasticpress' ); + } + + $notices['upgrade_sync']['html'] .= '

' . $appended_message; + + return $notices; + } + /** * Check if a reindex is needed based on the version number. */ diff --git a/tests/php/TestAdminNotices.php b/tests/php/TestAdminNotices.php index 740d766e8d..23cac17033 100644 --- a/tests/php/TestAdminNotices.php +++ b/tests/php/TestAdminNotices.php @@ -375,6 +375,50 @@ 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. + 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'] ); + + // 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'] ); + 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'] ); + } + /** * Conditions: * From 50ebe2f6ba06fc5c86ee65832874546b71566b27 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 7 Mar 2022 14:25:44 -0300 Subject: [PATCH 2/4] Set message about Instant Results and version upgrade resyncs --- includes/classes/Upgrades.php | 32 +++++++++++++++++++++++++++----- tests/php/TestAdminNotices.php | 15 ++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/includes/classes/Upgrades.php b/includes/classes/Upgrades.php index 9a077f4e89..59ab71a0bb 100644 --- a/includes/classes/Upgrades.php +++ b/includes/classes/Upgrades.php @@ -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: tag (Zendesk article); 2. ; 3: tag (link to Features screen); 4. ; */ + __( '%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' ), + '', + '', + '', + '' + ) + ); } else { - $appended_message = esc_html__( 'PLACEHOLDER: Instant Results available via custom proxy', 'elasticpress' ); + $appended_message = wp_kses_post( + sprintf( + /* translators: 1: tag (Zendesk article about Instant Results); 2. ; 3: tag (Zendesk article about self hosted Elasticsearch setups); 4. ; */ + __( '%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' ), + '', + '', + '', + '' + ) + ); } $notices['upgrade_sync']['html'] .= '

' . $appended_message; diff --git a/tests/php/TestAdminNotices.php b/tests/php/TestAdminNotices.php index 23cac17033..807180b512 100644 --- a/tests/php/TestAdminNotices.php +++ b/tests/php/TestAdminNotices.php @@ -398,17 +398,26 @@ public function testUpgradeSyncNoticeAndInstantResultsInAdmin() { ElasticPress\Screen::factory()->set_current_screen( null ); // Instant Results not available. + $not_available_full_text = 'Instant Results 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 install and configure a PHP proxy.'; 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 = 'Instant Results is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, click here 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. @@ -416,7 +425,7 @@ public function testUpgradeSyncNoticeAndInstantResultsInAdmin() { 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'] ); } /** From 51e274c0fe4e99c69d0007856222fa717299b5a4 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 7 Mar 2022 14:27:52 -0300 Subject: [PATCH 3/4] Adjust main resync warning --- includes/classes/AdminNotices.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/AdminNotices.php b/includes/classes/AdminNotices.php index 77ea89852d..9f7e42ed53 100644 --- a/includes/classes/AdminNotices.php +++ b/includes/classes/AdminNotices.php @@ -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 run a sync.', 'elasticpress' ), esc_url( $url ) ); + $html = sprintf( __( 'The new version of ElasticPress requires that you delete all data and start a fresh sync.', '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' => ' ' . $html . ' ' . $notice, From 420657c23992cfd53e96feeb0886fcf499ac9b32 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Mon, 7 Mar 2022 16:34:46 -0300 Subject: [PATCH 4/4] Remove `@todo` --- includes/classes/Upgrades.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/classes/Upgrades.php b/includes/classes/Upgrades.php index 59ab71a0bb..4913737f17 100644 --- a/includes/classes/Upgrades.php +++ b/includes/classes/Upgrades.php @@ -175,7 +175,6 @@ public function upgrade_3_6_6() { * might want to enable the feature before the resync (and then resync only once.) * * @since 4.0.0 - * @todo Replace texts * @param array $notices All admin notices * @return array */