2

This is a follow-up to my question "How to use the Rules module to unset all flags (set x days ago) when cron runs?".

Case: users set flags on content using Flag module (flags are per user, not global).

Requirement: after a period of time (= x days) the system should automatically unset these flags using Rules module.

Limitation: the Rules Scheduler module cannot be used (for a solution using Rules Scheduler module please see the question linked to above).

4
  • 1
    Why can rules scheduler not be used? Before you say "doesn't matter", it could impact the answer considerably - for example, if the reason is that you can't schedule a cron job, you're pretty much out of luck – Clive Jun 22 '16 at 13:44
  • thanks. It's a follow-up question to drupal.stackexchange.com/questions/204746/… where @Pierre.Vriens proposed a solution that doesn't rely on Rules Scheduler, but would i suppose have been inappropriate as an answer to that question. Please feel free to modify my question as you think best. – penname Jun 22 '16 at 14:27
  • I can't, not sure what you're asking. Anything automatic and periodic essentially needs a cron job running. At which point Rules Scheduler is by definition an option. If you're ruling out the standard methods for accomplishing a task, it's useful for tell us why, so people can give you the best advice – Clive Jun 23 '16 at 10:36
  • @Clive Understood. Sorry for not being clearer. The first attempt tried to use cron and Rules Scheduler. However, no go. Please see chat.stackexchange.com/transcript/message/30533351#30533351 The component functioned correctly when executed manually, but not with cron. It was not clear whether using cron it would be possible to pass the data correctly from the event. Consequently i started to investigate the use of other events. Flags have a flag set time. This is not well-exposed in Rules. But we can use it with VBO and an event other than cron to target flags x days old. – penname Jun 23 '16 at 14:07
2

You could use an approach similar to what is shown in the video about Using VBO to load list of objects into Rules, starting from about 5:30, up to 11:30. Here is a summary of what is shown in this video (quote from the linked page):

  • You need a view that lists the entities you want to work on in Rules. Note that you don't need a display of the view – and it might even be better not to have one if you don't want the view to be displayed somewhere.
  • However, you need one bulk operations field. The type of bulk operations field determines what entity type will be sent to Rules. Note that you don't need any actions enabled for the field – it is enough that it is present.
  • You need a rule that, as an action, loads entities from a VBO. (This is available under the "Views bulk operations" group.) All view displayes with at least one VBO field will be selectable.
  • The action provides a list of entities, that can be used just like other lists in Rules. Combine with loops, actions and Rules Scheduler to make awesomeness happen.

In your case you want to start from your VBO list of the nodes flagged by a user at least x days ago. And for each node in the list you want the rules action to be "unflag node" (instead of "remove sticky"). You'll have to pass the userid as a parameter also, similar to what is shown around 7:30 in that video also.

It should be possible to use the same Rules component as in Step 1 of my answer to "How to use the Rules module to unset all flags (set x days ago) when cron runs?". This Rules Component should then become the Rules Action to be performed by an additional rule that is triggered by an appropriate Rules Event. It appears to me that Rules Event "User has logged in" could be a good fit for your case (if not replace it by whatever other Rules Event that fits best). This is what differs from what is shown in the video, starting from 11:30 (in the video the Rules component is triggered daily, via the Rules Scheduler). Using this Rules Event also complies with your comment to my answer to your related question, ie "... use user login as the event, fetch the set flags of the logged in user, check their creation time, if they are older than x day unset the flags...".

Note: I think rephrasing "the Rules Scheduler module cannot be used ..." in your question to something like "Without using the Rules Scheduler module ..." would improve your question (it is possible to use that module, but for this question you don't "want to" use it).

3
  • Which part of this answer satisfies the requirement: after a period of time (= x days) the system should automatically unset these flags ? As far as I can tell this approach requires action to be taken, i.e. a user must log in. That's not automatic, nor periodic. If a user doesn't log in, the event isn't fired, and the rule isn't executed. Am I missing something or have you just misunderstood the question? – Clive Jun 23 '16 at 10:30
  • @Clive : check my updated answer to understand where my suggestion about using "User has logged in" originates from. I agree with you that it is not periodic (only when user logs in, if ever), but "any time" such login happens, then automagically the Rule will fire. And I can think of situations where such solutions would be "good enough" as a compromise if one cannot, or does not want to, use Rules Scheduler. Simple sample: flagged nodes imply access to specific user, but ONLY for X days, and if users comes back after X days then disallow access (by unflagging those nodes). – Pierre.Vriens Jun 23 '16 at 11:12
  • @penname : merci for accept (and upvote) ... you're right about that video, but IMO the same is true for the entire video series ... BTW: you don't want to rephrase your question similar to what I suggested in my "note"? It might help to address Clive's newest comment to your question (just a suggestion though ...) – Pierre.Vriens Jun 23 '16 at 14:05
2

Create a page and use whatever content type you want for it, eg. "Article". And assign a path to that page also, e.g. on \admin\dummypage. It doesn't matter what the content of that page is.

Then create a rule (using Rules) and enable the Path Rules module also. With this combination you can trigger a rule when the page \admin\dummypage is visited.

The rule can do (= perform a Rules Action) what you want to do. Built a view and with the help of VBO you can apply the changes you want. See therefore the video mention in the next answer.

Then you have to make sure that the page is visited. You can do this by either of following ways:

  1. Put a reminder in your calender that includes the URL of your special page, and click on the page.
  2. Use a websites like http://www.montastic.com/ (they will retrieve this page regularly).
  3. Schedule a cron job. In this cron job you do a wget statement to retrieve the page and send it to null.
3
  • @Pierre.Vriens I edited the answer for more understanding. If not clear let me know. – Justme Jun 23 '16 at 5:34
  • Fixed the typo. Of course you can use the VBO view but then your give load to the system twice. First by triggering the page and secondly in the rule set. The only goal is to trigger the rule ... – Justme Jun 23 '16 at 17:04
  • Thanks for fixing the (crucial) typo! I hadn't thought of that load twice, so good point! – Pierre.Vriens Jun 23 '16 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.