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

Command icon 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

steven jones created an issue. See original summary.

  • steven jones committed fdc73209 on 4.0.x
    fix: #3614670 Logic bug in \Drupal\votingapi\VoteResultFunctionManager::...
steven jones’s picture

Status: Active » Fixed

LGTM.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.