Skip to content

Commit

Permalink
Merge pull request #2973 from 10up/fix/last-sync-empty-report
Browse files Browse the repository at this point in the history
Display custom message when a last sync is not detected
  • Loading branch information
felipeelia authored Aug 30, 2022
2 parents 686a40b + 66b07a5 commit 965cbf3
Showing 1 changed file with 32 additions and 8 deletions.
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

0 comments on commit 965cbf3

Please sign in to comment.