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

Display custom message when a last sync is not detected #2973

Merged
merged 2 commits into from
Aug 30, 2022
Merged
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
40 changes: 32 additions & 8 deletions includes/classes/Screen/HealthInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public function last_sync_health_info( $debug_info ) {

$sync_info = IndexHelper::factory()->get_last_index();

if ( empty( $sync_info ) ) {
$debug_info['ep_last_sync']['fields']['not_available'] = [
'label' => esc_html__( 'Last Sync', 'elasticpress' ),
'value' => esc_html__( 'Last sync info not available.', 'elasticpress' ),
'private' => true,
];
return $debug_info;
}

if ( ! empty( $sync_info['end_time_gmt'] ) ) {
unset( $sync_info['end_time_gmt'] );
}
Expand All @@ -60,12 +69,14 @@ public function last_sync_health_info( $debug_info ) {
);
}

$methods = [
'web' => esc_html__( 'WP Dashboard', 'elasticpress' ),
'cli' => esc_html__( 'WP-CLI', 'elasticpress' ),
];
if ( ! empty( $sync_info['method'] ) ) {
$methods = [
'web' => esc_html__( 'WP Dashboard', 'elasticpress' ),
'cli' => esc_html__( 'WP-CLI', 'elasticpress' ),
];

$sync_info['method'] = $methods[ $sync_info['method'] ] ?? $sync_info['method'];
$sync_info['method'] = $methods[ $sync_info['method'] ] ?? $sync_info['method'];
}

$labels = [
'total' => esc_html__( 'Total', 'elasticpress' ),
Expand All @@ -79,9 +90,22 @@ public function last_sync_health_info( $debug_info ) {
'total_time' => esc_html__( 'Total Time', 'elasticpress' ),
];

// Apply a custom order to the table rows
$preferred_order = [ 'method', 'start_date_time', 'end_date_time', 'total_time', 'total', 'synced', 'skipped', 'failed', 'errors' ];
$sync_info = array_replace( array_flip( $preferred_order ), $sync_info );
/**
* Apply a custom order to the table rows.
*
* As some rows could be unavailable (if the last sync was done using an older version of the plugin, for example),
* the usual `array_replace(array_flip())` strategy to reorder an array adds a wrong numeric value to the
* non-existent row.
*/
$preferred_order = [ 'method', 'start_date_time', 'end_date_time', 'total_time', 'total', 'synced', 'skipped', 'failed', 'errors' ];
$ordered_sync_info = [];
foreach ( $preferred_order as $field ) {
if ( array_key_exists( $field, $sync_info ) ) {
$ordered_sync_info[ $field ] = $sync_info[ $field ] ?? esc_html_x( 'N/A', 'Sync info not available', 'elasticpress' );
unset( $sync_info[ $field ] );
}
}
$sync_info = $ordered_sync_info + $sync_info;

foreach ( $sync_info as $label => $value ) {
$debug_info['ep_last_sync']['fields'][ sanitize_title( $label ) ] = [
Expand Down