1

I'm working on a website where we are offering trial access and I want a way to automatically cancel an account after the account is more than 14 days old EXCEPT if they have submitted a feedback form in which case they get an additional 7 days (for a total of 21 days).

I think there ought to be a way to do this using Rules or cron but right now I'm stuck.

0

Sure you can do this, using the Rules module (and the Webform module for your form). Here is a blueprint about how to do so:

1. Rules Component to block a user

Create a (rather basic) Rules Component to "block" a user, whereas you use a "User" entity as parameter for it.

2. Rule to cancel an account

Create a (rather basic) rule like so:

  • Rules Event: Before saving a user account
  • Rules Conditions: None (feel free to add whatever fits)
  • Rules Action: Schedule the execution of the Rules Component (from step 1), to be executed after 14 days. For this you need to have the "Rules Scheduler" (a sub-module of Rules) enabled. Make sure to use an "id" for this scheduled task that includes the user's uid (you'll need it in Step 3).

Refer to my answer to "How to send an email notification reminder based on a user's date of entry field?" for a sample of a rule that is pretty close to what your rule should look like (especially Step 3 of it).

3. Rule to delete the scheduled rule

Use the Webform Rules module to create a rule like so:

  • Rules Event: After a webform has been submitted
  • Rules Conditions: Check the webform Id (to ensure it's the form you want to consider).
  • Rules Action: Delete the Scheduled rule from Step 2, and Reschedule it to be executed 21 days after there account activation date. For this you'll need the id of the Scheduled task, but if you used the user's uid for that, this should be no problem.

PS: I'm assuming this is about D7 ...

0

You can do this using hook cron or rules also
contrib module available for your requirement https://www.drupal.org/project/user_expire

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.