1

I am using Voting API with Fivestar. On my site users can comment on a node and leave a rating with the comment. These are aggregated and an average vote is displayed at the top of the node. The average rating for some of my nodes does not match what the average would be if you summed up the comment ratings and divided by the number of comments. Also the count is wrong.

I believe this happened because I manually converted an old Drupal 6 site to Drupal 7 so I manually entered some old reviews. Because I entered them from the same IP and within the threshold of time I believe the module does not count them.

I'm comfortable running SQL queries to fix this. I was able to enter the correct average and count records in the votingapi_cache table. This temporarily fixed the problem, but later I deleted some spam comments, and then the rating was messed up again (I guess maybe deleting causes the votingapi_cache table to be rebuilt?)

What is the correct way to fix this?

UPDATE

So there is more to the story. I just spent some time manually adding the records into the votingapi_vote table. Then I added a new comment with a vote through my drupal site. This caused the votingapi_cache to be rebuilt and I saw the the average vote and vote count were correct. I thought great problem solved.

Then I deleted my test comment and immediately the average and vote counts went to zero. Examining the votingapi_vote table which I had just manually added records to, I saw that all records for that node id were gone. So deleting a comment deletes all records in votingapi_vote table. Seemed fishy so I searched and found it's a bug in the fivestar module: Deletion of Anonymous Comments with Fivestar rating results in deletion of all votes for entity.

Pretty horrendous bug if you ask me. Don't think it's fixed in the module but that bug link has a patch for it which I will try out.

  • This question shouldn't really have an answer. This is just a bug in the module. There is a patch, I'll review it and commit it if it solves the problem. – ericduran Jun 18 '13 at 20:21
  • Thanks, I didn't know there was a bug at the time I wrote the question. If you could commit it that'd be great, either way this question may help someone else – User Jun 18 '13 at 21:01
  • @ericduran any chance you got to take a look at this? – User Aug 6 '13 at 15:06
2

Truly correct way to fix it would be to salvage original IP addresses of voters from original database.

If you cannot do it, randomize. Assign each vote an IP from 127.0.0.0/8 range, that way you will not interfere with future votes and large number laws says you'll have pretty small number of duplicates, so averages should be about right.

  • How shall i do it? Could you please provide an sql call or explain it more proper? Don't seem to get you. – Rootical V. Feb 10 '14 at 18:08
1

FYI I'm using fivestar 7.x-2.0-alpha2

Ok I was able to apply the patch I mentioned in my question: Deletion of Anonymous Comments with Fivestar rating results in deletion of all votes for entity. and now it appears to be working.

Applying the patch was not without issue, although I'm not that familiar with the process. This is what I did:

  • cd mydrupaldirectory/sites/all/modules/fivestar
  • downloaded the patch file to that folder: wget http://drupal.org/files/fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch
  • I tried git apply -v fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch but this gave me an error:

$ git apply -v fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch

fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch:35: trailing whitespace.

fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch:65: trailing whitespace. $target = _fivestar_field_target($entity, $field, $instance, $item, $langcode); Checking patch fivestar.info... error: while searching for: configure = admin/config/content/fivestar files[] = test/fivestar.base.test files[] = test/fivestar.field.test

error: patch failed: fivestar.info:6 error: fivestar.info: patch does not apply Checking patch fivestar.module... Checking patch includes/fivestar.field.inc... Checking patch widgets/basic/basic-rtl.css... Checking patch widgets/basic/basic.css... Checking patch widgets/craft/craft-rtl.css... Checking patch widgets/flames/flames-rtl.css... Checking patch widgets/hearts/hearts-rtl.css... Checking patch widgets/minimal/minimal-rtl.css... Checking patch widgets/outline/outline-rtl.css... Checking patch widgets/outline/outline.css... Checking patch widgets/oxygen/oxygen-rtl.css... Checking patch widgets/oxygen/oxygen.css... Checking patch widgets/small/small-rtl.css...

  • I don't really know why it wouldn't apply but instead I ran this: $ patch -p1 < fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch which also gave an error:

$ patch -p1 < fivestar-Deletion_of_anonymous_comments_deletes_all_comments-1674120-5.patch

patching file fivestar.info

Hunk #1 FAILED at 6.

1 out of 1 hunk FAILED -- saving rejects to file fivestar.info.rej patching file fivestar.module Hunk #1 succeeded at 130 (offset -19 lines). Hunk #2 succeeded at 147 (offset -19 lines). Hunk #3 succeeded at 400 (offset -19 lines). patching file includes/fivestar.field.inc

To me it looks like only patching the fivestar.info file failed which doesn't seem that important because it's just meta information.

I re-added the rows in the votingapi_vote table and added and deleted a comment and now the averages and counts are correct. So far so good.

UPDATE

Actually this doesn't seem to have completely fixed the problem. I just received a lot of spam comments which I deleted. After deleting them the averages and counts still reflected those now deleted spam comments. Examining the votingapi_vote table I could still see the records corresponding to the spam comments. I manually deleted those rows and then added and deleted a comment through the drupal interface to force recalculation of the votingapi_cache table. So the above patch has the benefit that fivestar will no longer completely wipe out all records for a node in the votingapi_vote table. However now it won't delete deleted comments. I'll take this behavior over the former because manually deleting a few records beats re-entering old vote data. Still a PITA

UPDATE 2

Just realized that the reason the patch probably didn't apply properly is that I have the wrong version of fivestar. I'm using 7.x-2.0-alpha2 and I should be using the dev version 7.x-2.0-alpha2+5-dev. Will check it out and report back.

  • So how it goes? I've been experiencing this issue for almost 2 years already still no answer. – Rootical V. Feb 10 '14 at 18:07
  • @RooticalV. I've been experiencing it for a long time as well. Pretty surprising this hasn't been fixed yet, I would have thought this would be a very popular module. I dug into it for a while but then got frustrated and for the time being I'm living with it. Although I see there is now an alpha3 release made just on Feb 1, 2014 so maybe there is progress. – User Feb 10 '14 at 18:16
  • No progress at all( I've just tried the newest stable and dev versions without no luck. None of the patches had been suggested worked – Rootical V. Feb 10 '14 at 18:27
  • drupal.stackexchange.com/questions/75483/… my old question regarding the issue – Rootical V. Feb 14 '14 at 14:01
  • @RooticalV. appears there was a change made to the dev version just today: drupal.org/node/1674120 Maybe this fixes it? – User Feb 28 '14 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.