diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index f77a2c1..0c3fe61 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -165,11 +165,13 @@ public function getRankingInfo() { // nodes. 'on' => "ces.entity_id = i.sid AND ces.entity_type = 'node' AND ces.field_name = 'comment'", ), - // Inverse law that maps the highest reply count on the site to 1 and 0 - // to 0. Note that the CAST here is necessary for PostgreSQL, because the - // PostgreSQL PDO driver sometimes puts values in as strings instead of - // numbers in complex expressions like this. - 'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (CAST (:comment_scale AS DECIMAL(10, 4))))', + // Inverse law that maps the highest view count on the site to 1 and 0 + // to 0. Note that the ROUND here is necessary for PostgreSQL and SQLite + // in order to ensure that the :statistics_scale argument is treated as + // a numeric type, because the PostgreSQL PDO driver sometimes puts + // values in as strings instead of numbers in complex expressions like + // this. + 'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (ROUND(:comment_scale, 4)))', 'arguments' => array(':comment_scale' => \Drupal::state()->get('comment.node_comment_statistics_scale') ?: 0), ), ); diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index e235aca..57e8ffc 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -169,9 +169,11 @@ function statistics_ranking() { 'on' => 'node_counter.nid = i.sid', ), // Inverse law that maps the highest view count on the site to 1 and 0 - // to 0. Note that the CAST here is necessary for PostgreSQL, because - // the PostgreSQL PDO driver sometimes puts values in as strings - // instead of numbers in complex expressions like this. + // to 0. Note that the ROUND here is necessary for PostgreSQL and SQLite + // in order to ensure that the :statistics_scale argument is treated as + // a numeric type, because the PostgreSQL PDO driver sometimes puts + // values in as strings instead of numbers in complex expressions like + // this. 'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * (ROUND(:statistics_scale, 4)))', 'arguments' => array(':statistics_scale' => \Drupal::state()->get('statistics.node_counter_scale') ?: 0), ),