I am using Voting API with the fivestar module. Logged in users can comment on nodes and there is a fivestar rating field attached to the comment - I got my exact setup by following http://drupal.org/node/1308114. Comments must be approved by an administrator before they appear and the vote is submitted.
When the vote is added into the votingapi_vote table, it is added with the correct uid - the uid of the author of the post. But during the critera checking process the voting api module checks whether the approver has already voted and not whether the author has already posted.
Consequently, if the administrator has submitted a vote on a node, then as soon as that same administrator approves a comment & vote by another user on that same node, the administrators original vote is deleted.
I believe the code that is doing this is:
foreach ($votes as $vote) {
$tmp = votingapi_current_user_identifier();
$tmp += $vote;
if (isset($tmp['value'])) {
unset($tmp['value']);
}
votingapi_delete_votes(votingapi_select_votes($tmp));
}The votingapi_current_user_identifier function sets the uid to the current users uid rather than the one passed to the votingapi_set_votes function.
My fix has been the following modification:
foreach ($votes as $vote) {
$tmp = array();
if(!isset($vote['uid'])) {
$tmp = votingapi_current_user_identifier();
}
$tmp += $vote;
if (isset($tmp['value'])) {
unset($tmp['value']);
}
votingapi_delete_votes(votingapi_select_votes($tmp));
}I've not done any work with Drupal modules before so not sure if this is the correct way to do it, but the fix seems to work for me.
Comments
Comment #1
svabael commentedI think it's definitely a nasty bug, because the behaviour of votingapi_set_votes is "Cast a vote on a particular piece of content", while in reality is "Deletes vote for current logged in user and add vote on a particular piece of content for user specified in $vote['uid']"
Comment #2
torotil commentedThanks for your clear report. And the pointer to the right code-section. I've commited a fix to 7.x-2.x.