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.