Is there a module with a functionality to delete votes using the voting api? If not, how do I implement a button that erases all votes? Or is it easier if I just empty the MYSQL table?

| improve this question | | | | |
  • You should look at Views Bulk Operations working together with Rules and Voting Rules. You should create a rules component to delete a vote on a node (or whatever) and then integrate it with View Bulk Operations. – J. Reynolds Sep 1 '14 at 4:31
  • @J.Reynolds, that doesn't seem to work. Voting Rules gives conditions and events for rules, but it doesn't give any actions, it seems. – Turion Sep 1 '14 at 9:09
  • 1
    Writing custom plugins for Rules are some of the easiest Drupal programming to do. There is a patch Allow casting new votes with Rules. You can expand on that if you need to. You should create an action to delete a vote, it must pass a parameter of a vote, and then take action by doing this: votingapi_delete_votes(array($vote)); – J. Reynolds Sep 2 '14 at 4:20
  • @J.Reynolds Thanks, I'll try to do that. How do I construct a $vote, though, if I only know the entity id of the object that has been voted on? – Turion Sep 7 '14 at 14:55
  • Open up the votingapi.module file and look at the documented functions, especially votingapi_add_votes, votingapi_add_results, votingapi_delete_votes, votingapi_select_votes etc. For hooks look in votingapi.api.php – J. Reynolds Sep 8 '14 at 4:21

The voting api defines some drush commands:

drush generate-votes <entity_type> <vote_type>
drush votingapi-recalculate <entity_type>
drush votingapi-flush <entity_type>

if you don't use drush, you can run the code from the function that the module uses on devel php or similar

$entity_type = "name_of_the_entity";
$cache = db_delete('votingapi_cache');
$votes = db_delete('votingapi_vote');

if (!empty($entity_type)) {
  $cache->condition('entity_type', $entity_type);
  $votes->condition('entity_type', $entity_type);
if (!empty($entity_id)) {
  $cache->condition('entity_id', $entity_id);
  $votes->condition('entity_id', $entity_id);

| improve this answer | | | | |

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.