Problem/Motivation
\Drupal\votingapi\VoteResultFunctionManager::recalculateResults has some flawed logic:
It's trying to call \Drupal\votingapi\VoteResultFunctionManager::performAndStore with groups of votes, all with the same vote type and for the same entity.
$votes = [];
$vote_type = '';
foreach ($vote_ids as $vote_id) {
$vote = $vote_storage->load($vote_id);
// Votes are sorted by vote type, so when we hit a new type, we can run
// find the results of the current set and then start over.
if (!empty($vote_type) && $vote_type != $vote->bundle()) {
$this->performAndStore($votes);
$vote_type = $vote->bundle();
$votes = [];
}
$votes[] = $vote;
}
// Still one last set to process.
$this->performAndStore($votes);
This code will never get into the conditional because !empty($vote_type) will never be true.
Steps to reproduce
Run the above code.
Proposed resolution
Given that $vote_type is a required parameter, and gets passed into the query that's generated, I don't think this code is actually ever handling multiple vote types, and thus, we can remove this conditional and tidy up this loop.
Remaining tasks
Implement the solution.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork votingapi-3614670
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
steven jones commentedLGTM.