Versus stores completely wrong results - flaw in use of form api
| Project: | Versus |
| Version: | 5.x-1.0-rc1 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs review |
Versus does not set the #multistep property in its forms, and uses dynamic forms. As a result, submitted data is corrupted by new (random) data, and we end up with completely invalid rows stored in the voting_api table (and reported as results). Completely invalid.
You can demonstrate this bug by simply creating three or more of any kind of data (I used story data) and then voting on the data. After each vote, take a look at the votingapi_vote table (best approach) to see what was stored (best approach) or just look at the view provided, which mostly shows what is going on. You'll find that random data is being stored (the next random poll overwrites the values provided by the vote submit).
Note that the winner being voted upon is stored in the "value" field of the table, not the content_id field, where you'd expect it. The "loser" is stored in the content_id field.
The attached patch seems to solve the problem. The issues involved are discussed at http://drupal.org/node/101707.
| Attachment | Size |
|---|---|
| versus_multistep_required.patch | 558 bytes |

#1
Tried the patch, but it buggered up my views integration for Verses?
#2
Since this was a change in how the data is stored, I'd be surprised if it affected views.
You'll need to do a bit more troubleshooting, though.
1. Clear your cache.
2. See if views works OK for you with the unpatched versus. If it does, try it with the patched versus.
3. If it works with the unpatched and doesn't work with the patched, please give exact instructions on what happens and how to recreate the problem.
I can't guarantee that I'll be able to work on anything, but this is what to do to take a look.
-Randy
#3
Got it to work, thanks for the patch. It was actually that I messed up the patching. Cheers for the help! I actually neede to do some work to make the Versus module a little more bespoke for my own requirements. Rather than give an 'option' and 'loser' value in the votingapi_vote table I needed 'points'. Rather than allocating a $loser and $winner, I allocated "1 point" to the winner of each Versus vote.
/**
* Process a voting form submission.
*/
function versus_voting_form_submit($form_id, $form_values) {
// Figure out who won & who lost.
$winner = $form_values['vote_refs']['versus_winner'];
$loser = $form_values['vote_refs']['versus_loser'];
// Record the vote in the database.
//I CHANGED THIS LINE BELOW TO ALLOCATE 1 POINT TO THE WINNER
$result = votingapi_add_vote('node', $winner, 1, 'option', 'versus');
// Take the user to the next voting ballot.
drupal_goto('versus/vote/'. arg(2) . (arg(3) ? '/'. arg(3) : ''));
return;
}