The function flag_trim_flag() doesn't support anonymous user flags. All anonymous user flags are trimmed to the cut-off size meaning most users lose their flags.

The errant code is:

$result = db_query("SELECT * FROM {flag_content} WHERE fid = %d AND (uid = %d OR uid = 0) ORDER BY timestamp DESC", $flag->fid, $account->uid);

I will attempt a patch...

Comments

chaps2’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

This patch does the trick but may not be ideal. Rather than replicate all the anonymous user handling code I replaced the query with a call to flag_get_user_flags() with an array sort to order by most recent flags first.

chaps2’s picture

Version: 6.x-2.0-beta5 » 6.x-2.x-dev
Jhef.Vicedo’s picture

StatusFileSize
new859 bytes

Session API module is needed to support and handle flagging for anonymous users. So we should use the session Session API provides. Attached is a patch.

mattcasey’s picture

Without this update, anonymous flagging and 'trimming' a flag to one per user does not work. It took me half a day to figure this out and come to the same solution as #3. Of course I found this post at the same time :)

Please commit! Thanks

quicksketch’s picture

Status: Needs review » Needs work

This patch doesn't look right either. It won't work for flags that are "global", because the UID (and SID) are both 0 for global flags. The function needs to take into account whether the flag is global or not and adjust as needed.

Jhef.Vicedo’s picture

I believe the flag method handles that. It checks for global setting and then set $uid and $sid to 0 if true.

Anonymous’s picture

Patch works for me too - lifesaver, please commit!

joachim’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
dsdeiz’s picture

I think this is already in place? I see this in flag_trim_flag():

  $query = db_select('flagging', 'fc')
    ->fields('fc')
    ->condition('fid', $flag->fid)
    ->condition(db_or()->condition('uid', $account->uid)->condition('uid', 0))
    // Account for session ID (in the case of anonymous users).
    ->condition('sid', flag_get_sid($account->uid));
shabana.navas’s picture

Issue summary: View changes
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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