How to schedule nodes to be deleted with Rules Scheduler and let people postpone the expiry date with Flags. Users also get an expiration mail before the nodes expire.
- Install and enable these modules:
drush -y en rules rules_admin rules_scheduler flag
Create 3 Components
- Go to Configuration > Workflow > Rules > Components > Add new component
- Create an Action set component called Article : Send Expiry Notification:
- Set DATA TYPE as Node. This is an input parameter for the component to act on:
- Select Send mail action:
- Switch to data selection:
- Select node:author:mail as the recipient:
- Add mail subject:
- Add mail message:
- Hit SAVE
- Create another component in similar fashion but make it delete entity:
- Add Delete entity action:
- Select node as the Data selector.
- Create the Third component that schedules the previous two:
- Create and action and select Schedule component evaluation for Article : Send Expiry Notification component:
- Expiry notification will be sent in 5 months and 2 weeks:
- String to identify the task:
- Hit SAVE
- Do the same thing with Article : Delete component by adding another action:
- Node will be deleted in 6 months (2 weeks after the expiry notification):
Create a Rule
Create a rule to set the schedules when article is created.
- Go to Configuration > Workflow > Rules and add a new rule:
- Add an action to set the schedules:
- Create an article and you should see the schedules in Configuration > Workflow > Rules > Schedule
Create a Flag
Create a flag to update the expiry dates.
- Go to Structure > Flags > Add flag
- Select Nodes as flag type:
- If you don't tick Global flag, then every user has individual flags for users.
- Hit SAVE
- Create a rule that reacts when node has been flagged:
- Add action that sets the schedules (this will also update the schedules if they already exist):
- Add another action to set the flag unflagged when you flag it:
- In node (or teaser view) click the Update Expiry Date to test this:
- Now in Configuration > Workflow > Rules > Schedule the tasks has been updated:
These tasks will be evaluated when cron runs. See the video where I test this out and use Views Bulk Operations (VBO) to set schedules for existing nodes!
Posted by Samuli Natri on 21 July 2015