I created a new flag called "like", non-global and I used the flag_create_link function in my template file as follows:

<?php
$flag = flag_get_flag('like') or die('no "like" flag');
print $flag->get_count($node->nid);
?>
 members like this page.

<div><?php print flag_create_link('like', $node->nid); ?></div>

I visit a page and the flag count shows 0 and there is a link "Vote for this page". I flag the page, I get the expected "Vote counted" message when the page reloads.

The link then says "Remove your vote" and the target URL seems ok...flag/unflag/like...etc. I click this and the page reloads with the message "Vote removed" but the flag count still shows 1 and the create_link text is still showing "Remove your vote."

This is such a basic failure of the core function of the module that I must be doing something wrong.

CommentFileSizeAuthor
#5 flag-tables.gif68.04 KBesllou

Comments

esllou’s picture

Category: support » bug

OK, I've confirmed this now and put the issue to a bug report. I recreated the flag and also created a View with the flag/unflag links as one of the columns in the view and when I flag a node, it gets put into the view table as it should. By clicking on "unflag this" in the table, nothing happens, the page reloads and the node is still there. So there is definitely something wrong.

My existing 2 flags that I had on D5 seem to be fine, just this new one that I created in D6.

esllou’s picture

Title: Unflag doesn't seem to be working with flag_create_link function » Unflag doesn't seem to be working with new D6 flags
quicksketch’s picture

I've heard a similar bug report previously that was caused by the "flags" table not having an auto-increment on the fid column, which will cause the flag to have an fid of 0. This then causes strange behaviors with the flaggings not seeming to work. Could you check your database and make sure that the FID column is auto-increment (it was not auto-increment in D5). There might be something wrong in our D5 -> D6 upgrade path.

Note that this problem does not exist on a clean install of Flag on Drupal 6 as far as I can tell. Could you see if this is the case for you also?

quicksketch’s picture

Here's the other issue I was referring to that reported the same problem. #457422: Cannot unflag a user flag

Here's a patch that should fix the problem. Note that you'll need to remove your new flag and add it again to give it an FID. #420250: Flag D5->D6 Update Doesn't Add Auto-increment to flags.fid Column

esllou’s picture

StatusFileSize
new68.04 KB

I had a tab with phpMyAdmin open at the same time as I was doing all this and I can tell you the new flag did get an fid of 0 and it made me raise an eyebrow. Then I deleted it and started again (as I said in my second post) and THAT flag got an fid of 0 too. So I think that's the issue definitely. Look at the attached image and that will tell you what you need to know about flag_content and flag_count tables. Same issue for "flags" table...no auto-increment and fid of my new flag is 0.

I'll give the patch a go.

esllou’s picture

just a question about the patch. Do I run that patch against the install file, then run update.php (where it should run update 6004). Is that all?

also, does that patch deal with all the affected flags tables?: flags, flag_types, flag_counts, flag_content: all of these have fid of 0 for the new flag I created.

quicksketch’s picture

Apply the patch to your flag.install file, then run update.php. It does *not* fix existing flags that are broken, because it would have no way to reliably do so (such as if you tried to add two new flags) since they'd both be given an ID of 0. You'll need to delete the new flag you've created, then add it again for everything to start working properly.

esllou’s picture

Status: Active » Fixed

that seems to have done the trick.

quicksketch’s picture

Great, I'll go apply that patch right away, it's a pretty bad bug to have in the stable version.

Status: Fixed » Closed (fixed)

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