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/Screen/HealthInfo.php +17 -114 4.3.05.3.5 View file →
@@ -6,11 +6,10 @@
6 6 */
7 7
8 8 namespace ElasticPress\Screen;
9 9
10 -use ElasticPress\Features as Features;
11 -use ElasticPress\IndexHelper;
12 -use ElasticPress\Utils as Utils;
10 +use ElasticPress\Features;
11 +use ElasticPress\Utils;
13 12
14 13 /**
15 14 * Health info screen Class.
16 15 */
@@ -19,9 +18,9 @@
19 18 /**
20 19 * Initialize class.
21 20 */
22 21 public function setup() {
23 - add_action( 'debug_information', [ $this, 'last_sync_health_info' ] );
22 + add_filter( 'debug_information', [ $this, 'last_sync_health_info' ] );
24 23 add_filter( 'debug_information', [ $this, 'epio_autosuggest_health_check_info' ] );
25 24 }
26 25
27 26 /**
@@ -30,92 +29,18 @@
30 29 * @param array $debug_info The debug info for site health screen.
31 30 * @return array The debug info for site health screen.
32 31 */
33 32 public function last_sync_health_info( $debug_info ) {
34 - $debug_info['ep_last_sync'] = array(
35 - 'label' => esc_html__( 'ElasticPress - Last Sync', 'elasticpress' ),
36 - 'fields' => [],
37 - );
33 + $last_sync_report = new \ElasticPress\StatusReport\LastSync();
38 34
39 - $sync_info = IndexHelper::factory()->get_last_index();
35 + $groups = $last_sync_report->get_groups();
36 + $first_group = reset( $groups );
40 37
41 - if ( empty( $sync_info ) ) {
42 - $debug_info['ep_last_sync']['fields']['not_available'] = [
43 - 'label' => esc_html__( 'Last Sync', 'elasticpress' ),
44 - 'value' => esc_html__( 'Last sync info not available.', 'elasticpress' ),
45 - 'private' => true,
46 - ];
47 - return $debug_info;
48 - }
49 -
50 - if ( ! empty( $sync_info['end_time_gmt'] ) ) {
51 - unset( $sync_info['end_time_gmt'] );
52 - }
53 -
54 - if ( ! empty( $sync_info['total_time'] ) ) {
55 - $sync_info['total_time'] = human_readable_duration( gmdate( 'H:i:s', ceil( $sync_info['total_time'] ) ) );
56 - }
57 -
58 - if ( ! empty( $sync_info['end_date_time'] ) ) {
59 - $sync_info['end_date_time'] = wp_date(
60 - 'Y/m/d g:i:s a',
61 - strtotime( $sync_info['end_date_time'] )
62 - );
63 - }
64 -
65 - if ( ! empty( $sync_info['start_date_time'] ) ) {
66 - $sync_info['start_date_time'] = wp_date(
67 - 'Y/m/d g:i:s a',
68 - strtotime( $sync_info['start_date_time'] )
69 - );
70 - }
71 -
72 - if ( ! empty( $sync_info['method'] ) ) {
73 - $methods = [
74 - 'web' => esc_html__( 'WP Dashboard', 'elasticpress' ),
75 - 'cli' => esc_html__( 'WP-CLI', 'elasticpress' ),
76 - ];
77 -
78 - $sync_info['method'] = $methods[ $sync_info['method'] ] ?? $sync_info['method'];
79 - }
80 -
81 - $labels = [
82 - 'total' => esc_html__( 'Total', 'elasticpress' ),
83 - 'synced' => esc_html__( 'Synced', 'elasticpress' ),
84 - 'skipped' => esc_html__( 'Skipped', 'elasticpress' ),
85 - 'failed' => esc_html__( 'Failed', 'elasticpress' ),
86 - 'errors' => esc_html__( 'Errors', 'elasticpress' ),
87 - 'method' => esc_html__( 'Method', 'elasticpress' ),
88 - 'end_date_time' => esc_html__( 'End Date Time', 'elasticpress' ),
89 - 'start_date_time' => esc_html__( 'Start Date Time', 'elasticpress' ),
90 - 'total_time' => esc_html__( 'Total Time', 'elasticpress' ),
38 + $debug_info['ep-last-sync'] = [
39 + 'label' => esc_html__( 'ElasticPress - Last Sync', 'elasticpress' ),
40 + 'fields' => $first_group['fields'] ?? [],
91 41 ];
92 42
93 - /**
94 - * Apply a custom order to the table rows.
95 - *
96 - * As some rows could be unavailable (if the last sync was done using an older version of the plugin, for example),
97 - * the usual `array_replace(array_flip())` strategy to reorder an array adds a wrong numeric value to the
98 - * non-existent row.
99 - */
100 - $preferred_order = [ 'method', 'start_date_time', 'end_date_time', 'total_time', 'total', 'synced', 'skipped', 'failed', 'errors' ];
101 - $ordered_sync_info = [];
102 - foreach ( $preferred_order as $field ) {
103 - if ( array_key_exists( $field, $sync_info ) ) {
104 - $ordered_sync_info[ $field ] = $sync_info[ $field ] ?? esc_html_x( 'N/A', 'Sync info not available', 'elasticpress' );
105 - unset( $sync_info[ $field ] );
106 - }
107 - }
108 - $sync_info = $ordered_sync_info + $sync_info;
109 -
110 - foreach ( $sync_info as $label => $value ) {
111 - $debug_info['ep_last_sync']['fields'][ sanitize_title( $label ) ] = [
112 - 'label' => $labels[ $label ] ?? $label,
113 - 'value' => $value,
114 - 'private' => true,
115 - ];
116 - }
117 -
118 43 return $debug_info;
119 44 }
120 45
121 46 /**
@@ -129,44 +54,22 @@
129 54 if ( ! Utils\is_epio() ) {
130 55 return $debug_info;
131 56 }
132 57
133 - $debug_info['epio_autosuggest'] = array(
134 - 'label' => esc_html__( 'ElasticPress.io - Autosuggest', 'elasticpress' ),
135 - 'fields' => [],
136 - );
58 + $feature = Features::factory()->get_registered_feature( 'autosuggest' );
137 59
138 - $autosuggest_feature = Features::factory()->get_registered_feature( 'autosuggest' );
139 - $allowed_params = $autosuggest_feature->epio_autosuggest_set_and_get();
140 -
141 - if ( empty( $allowed_params ) ) {
60 + if ( ! $feature || ! $feature->is_active() ) {
142 61 return $debug_info;
143 62 }
144 63
145 - $allowed_params = wp_parse_args(
146 - $allowed_params,
147 - [
148 - 'postTypes' => [],
149 - 'postStatus' => [],
150 - 'searchFields' => [],
151 - 'returnFields' => '',
152 - ]
153 - );
64 + $epio_report = new \ElasticPress\StatusReport\ElasticPressIo();
65 + $groups = $epio_report->get_groups();
66 + $first_group = reset( $groups );
154 67
155 - $fields = [
156 - 'Post Types' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['postTypes'] ),
157 - 'Post Status' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['postStatus'] ),
158 - 'Search Fields' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['searchFields'] ),
159 - 'Returned Fields' => wp_sprintf( esc_html( var_export( $allowed_params['returnFields'], true ) ) ), // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
68 + $debug_info['epio-autosuggest'] = [
69 + 'label' => esc_html__( 'ElasticPress.io - Autosuggest', 'elasticpress' ),
70 + 'fields' => $first_group['fields'],
160 71 ];
161 -
162 - foreach ( $fields as $label => $value ) {
163 - $debug_info['epio_autosuggest']['fields'][ sanitize_title( $label ) ] = [
164 - 'label' => $label,
165 - 'value' => $value,
166 - 'private' => true,
167 - ];
168 - }
169 72
170 73 return $debug_info;
171 74 }
172 75 }