Division by zero error during 4.4.0 database update, causes PHP server process to crash
Closed this issue · 2 comments
zarino commented
I thought I’d try out the 4.4.0 release before our web server auto-upgraded to it tonight, and it brought PHP-FPM down with a division by zero error.
PHP Warning: Division by zero in /var/www/…/wp-content/plugins/helpful/core/helpers/class-stats.php on line 1298
I think this is happening during the process of Helpful updating its database after the plugin upgrade.
zarino commented
Just looking at that part of the code…
public static function get_single_post_stats( $post_id )
{
$post = get_post( $post_id );
$pro = self::get_pro( $post->ID ) ? self::get_pro( $post->ID ) : 0;
$contra = self::get_contra( $post->ID ) ? self::get_contra( $post->ID ) : 0;
$prop = self::get_pro( $post->ID, true );
$conp = self::get_contra( $post->ID, true );
$average = (int) ( $pro - $contra );
$total = (int) ( $pro + $contra );
$percentage = ( $pro / $total ) * 100;
$percentage = round( $percentage, 2 );
Is it possible that get_single_post_stats()
is being run on a post with no votes, meaning $pro
and $contra
are both 0
, and $percentage
is therefore ( 0 / 0 ) * 100
?