How can I update a user flag in rules? I am using a user flag, Visits, to track each user's visits to other user's profiles.

When a user visits another user's profile, a rule is triggered that automatically flags the visited user on behalf of the visiting user.

Flagging the user on the first visit is no problem.  But on the second visit and thereafter, I want to update the flag that was flagged on the first visit.  To do this, I made the following rule:


Event: User account page is viewed
Condition 1: NOT [account] is [site:current-user]
Condition 2: User is flagged ([account] on behalf of [site:current-user])
Actions-> How do I fetch and update the flag?


This rule is triggered correctly; however, I don't know how to get the previous flag (the flag applied when the user visited the profile for the first time) in order to update it.  

My question: how can I fetch the previously applied flag in rules so that I can update the timestamp and re-save it?

What I tried

Flag provides a rules action Fetch user flagged by user, but this does not help because this returns an array of users, not the flagging, which is what I want to update.

I can add the Unflag a node action and then the Flag a node action, but this will destroy my previous flag and replace it with a new one; since I want to track referer information over time, this is not a good solution.

Since I'm using Flag 3.x in which flags are entities, I tried using the Fetch entity by property action in Rules to fetch the flagging, but in this case the only property I can choose to select is the value of the Referer field, which is not helpful.  There seems to be no way to fetch the flag by its endpoints.

Why I'm doing this

This flag has a computed field, Referer, which stores the value of $_SERVER['HTTP_REFERER'] upon flagging.

When a user visits the profile of a user for the second time, I want to update this flag by updating the timestamp of the flagging and adding the new referer information to the flag.
My question: how can I fetch the previously applied flag in rules so
  that I can update the timestamp and re-save it?


Some good news but mostly bad.

If you add an extra text field to the flag and add an extra rule to set its data value to [flagged_uid]-[flagger_uid] when a flag is created, it seems that you can then fetch the flagging using that field as the Property and [account_uid]-[current-user_uid]. 

I say seems because while the rule runs without errors and I know my logic is right, I can't do anything to the fetched flagging to prove I've actually fetched it. I get an error when trying to delete it because "Rules doesn't have info about deleting a flagging" and saving it doesn't change the timestamp.

It just feels like it's not fully integrated. Even if you added a date field, I'm not sure Rules could access it on user view.



I guess I would either create a custom rules action to finish the rule or go with a fully fledged Field Collections solution.