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

Fixed counting exception #1188

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions lib/Doctrine/ORM/Tools/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ public function count()
$countQuery->setFirstResult(null)->setMaxResults(null);

try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty newline before this line

$parser = new Query\Parser($countQuery);
$parameterMappings = $parser->parse($parser)->getParameterMappings();
$parameters = $countQuery->getParameters();
foreach($parameters as $k=>$param){
if(!array_key_exists($param->getName(), $parameterMappings)){
$parameters->remove($k);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong: too many bound parameters and you are removing some? This may even introduce security issues...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctrine didn't removes it automatically when count is performed on something like this:

return $this->getEntityManager()->createQuery(
            "select r,"
            . "(sum(case when rr.helpful=true then 1 else 0 end)* 100 / (count(rr.helpful)+0.00001)) as hidden percent_cnt,"
            . "(case when (sum(case when rr.helpful=true then 1 else 0 end)* 100 / (count(rr.helpful)+0.00001))>:percent_of_helpfulness and count(rr.helpful)>:minimum_votes then 1 else 0 end) as hidden valuable_cnt"
            . " from MerixGameBundle:Review r left join r.reviewRatings rr"
            . " where r.game = :game group by r.id order by valuable_cnt desc, percent_cnt desc"
        )
            ->setParameter('percent_of_helpfulness', self::PERCENT_OF_HELPFULNESS)
            ->setParameter('minimum_votes', self::MINIMUM_VOTES)
            ->setParameter('game', $game);

}
}
$countQuery->setParameters($parameters);

$data = $countQuery->getScalarResult();
$data = array_map('current', $data);
$this->count = array_sum($data);
Expand Down