Problem

When editing an existing poll node and adding another option, the new option appears at the top instead of at the bottom when viewing the node. The weight for the new option is not getting saved. Any value entered in the vote count column for the new option isn't saved either.

Steps to reproduce:

- Create a poll node with 2 choices.
- Save the poll.
- Edit the poll and add a third choice.
- Save the poll.

You will notice that the third option you just entered appears at the top of the list of choices, not at the bottom. If you've entered a value in the show count field, this value isn't saved either.

I don't think this bug is related to #1274212.

Proposed resolution

Change the db_merge query. In node.module line 579:

  foreach ($node->choice as $key => $choice) {
    if (!empty($choice['chtext'])) {
      db_merge('poll_choice')
        ->key(array('chid' => $choice['chid']))
        ->fields(array(
          'nid' => $node->nid,
          'chtext' => $choice['chtext'],
          'chvotes' => (int) $choice['chvotes'],
          'weight' => $choice['weight'],
        ))
        ->execute();
    }

Comments

c31ck’s picture

StatusFileSize
new398 bytes

Patch that implements the fix suggested above.

amateescu’s picture

Version: 7.8 » 8.x-dev
Status: Active » Postponed (maintainer needs more info)
c31ck’s picture

Status: Postponed (maintainer needs more info) » Active

Yes, I tried that patch but it did not resolve the problem.

marcingy’s picture

Status: Active » Closed (duplicate)

This is still a duplicate of #1274212: Incorrect order of choices in Poll module. all discussion should be kept in one place.

marcingy’s picture

Status: Closed (duplicate) » Active

Actually maybe not after reread the other issue for a 3rd time - my bad sorry

c31ck’s picture

Title: Incorrect order of choices after updating a poll. » Weight and number of votes not getting saved when updating a poll.

After having another look at the query it occurred to me that the chvotes value isn't getting saved either. Changing the title of this issue accordingly.

c31ck’s picture

Status: Active » Needs review
StatusFileSize
new652 bytes

Patch that fixes both the weight and the vote count not beeing saved.

marcingy’s picture

StatusFileSize
new449 bytes

The patch in #7 does not work for me as it remains with ordering issues.

c31ck’s picture

Both patch #7 and #8 work fine for me. Could you describe what exactly isn't working in patch #7?

marcingy’s picture

In #7 the sort order still do not stay fixed and it was also failing tests.

c31ck’s picture

Status: Needs review » Reviewed & tested by the community

After having another look I agree that adding the weight and chvotes field to the insertFields method is the correct way to fix this.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests, +Needs backport to D7

Let's get a test added for this. And I assume this applies to D7 too since I'm not aware of any major improvements in Poll module in D8. :)

marcingy’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.51 KB

New patch with a test to ensure order is maintained and poll votes are saved when an update is performed.

xjm’s picture

StatusFileSize
new1.55 KB

Rerolled for core/.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.64 KB
new1.68 KB

Small re-roll for some spacing issues and changing the order of:

+++ b/core/modules/poll/poll.module
@@ -584,6 +584,8 @@ function poll_update($node) {
+           'weight' => $choice['weight'],
+           'chvotes' => (int) $choice['chvotes'],

Other than that, looks ready to me. Attached a patch for D7 too.

4 days to next Drupal core point release.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Needs review

Looks good. Committed/pushed to 8.x, moving to 7.x - there's already a patch here, but it needs the bot to run it.

amateescu’s picture

StatusFileSize
new1.64 KB

Re-uploading the patch from #15 for the testbot.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looking good, back to RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks!

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

Anonymous’s picture

Issue summary: View changes

Added votes count bug information.