Skip to content

Commit 11b26aa

Browse files
authored
Merge pull request #997 from cloudinary/fix/vanilla-installation
Math does not allow you to divide by zero
2 parents 821a9fa + 50ba745 commit 11b26aa

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

php/sync/class-sync-queue.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,18 @@ public function get_total_synced_media() {
394394
$return = array(
395395
// Original sizes.
396396
'original_size' => $total_local_size,
397-
'original_size_percent' => '100%', // The original will always be 100%, as it's the comparison to optimized.
397+
'original_size_percent' => 0 !== $total_assets ? '100%' : '0%', // The original will always be 100%, as it's the comparison to optimized.
398398
'original_size_hr' => size_format( $total_local_size ),
399399

400400
// Optimized size. We use the `original_size` to determine the percentage between for the progress bar.
401401
'optimized_size' => $total_remote_size,
402-
'optimized_size_percent' => round( abs( $total_remote_size ) / abs( $total_local_size ) * 100 ) . '%', // This is the percentage difference.
403-
'optimized_diff_percent' => round( ( $total_local_size - $total_remote_size ) / $total_local_size * 100 ) . '%', // We use this for the "Size saved.." status text.
402+
'optimized_size_percent' => $total_local_size > 0 ? round( abs( $total_remote_size ) / abs( $total_local_size ) * 100 ) . '%' : '0%', // This is the percentage difference.
403+
'optimized_diff_percent' => $total_local_size > 0 ? round( ( $total_local_size - $total_remote_size ) / $total_local_size * 100 ) . '%' : '0%', // We use this for the "Size saved.." status text.
404404
'optimized_size_hr' => size_format( $total_remote_size ), // This is the formatted byte size.
405405

406406
// Optimized is the % optimized vs unoptimized.
407-
'optimized_percent' => round( $total_optimized / $total_assets, 4 ),
408-
'optimized_percent_hr' => round( $total_optimized / $total_assets * 100, 1 ) . '%',
407+
'optimized_percent' => $total_assets > 0 ? round( $total_optimized / $total_assets, 4 ) : 0,
408+
'optimized_percent_hr' => $total_assets > 0 ? round( $total_optimized / $total_assets * 100, 1 ) . '%' : '0%',
409409
'optimized_info' => __( 'Optimized assets', 'cloudinary' ),
410410

411411
// Error size: No mockups on what to display here.

0 commit comments

Comments
 (0)