I'm new to actions, but I did figure out how to create an e-mail action. I just can't seem to figure out how to schedule the email action to be executed, say 1 day from today.

I do not want this triggered by some node insertion or update because there is none necessary. I just want the e-mail action performed a day from today.

How can I do this? Can I do this?

I looked at the Schedule Actions module, but a) there is no 5.x version (well, that works) and b) It still seems to require some node insertion/update before it will trigger the action schedule action (asa).

Comments

somebodysysop’s picture

I have actions, workflow and sched_act (Scheduled Actions) installed.

As I said, I wanted to schedule an email send action for a future date, but I did not want this triggered by a node. I have a module I'm working on where I use views to create a recipient list, and it is that recipient list that I want to send e-mails to at a scheduled date.

I wanted to do this programmatically. Discovered that the two hooks I needed in Scheduled Actions, action_sched_act_asa and sched_act_cron, actually work, so I did the following:


// $rec is an array which contains the values for sending the e-mails;

//
// This is how I save the send e-mail request as an action
//
	$params = array();
	$params['from'] = $rec['from']; // from address
	$params['recipient'] = $rec['mail']; // recipient address
	$params['subject'] = $rec['subject']; // message subject
	$params['message'] = $rec['message']; // message

	$function = 'action_views_mail_send'; // the function in my module

	$type = 'Email';

	$desc = 'Action email save for ' . $rec['mail'];

//
// No need for watchdog entry because it is done automatically by actions using $desc.
//
//	if ($aid = actions_save($function, $type, $params, $desc)) { // This will give me an $aid to use below:
//          _views_mail_error_log('action', t('Created views mail action for %name (%mail)', array(
//              '%name' => $rec['name'], '%mail' => $rec['mail'])));
//	}

	$aid = actions_save($function, $type, $params, $desc);  // This will save action and give me an action ID to use below:

	print "The action ID is : " . $aid;

//
// Values I need to send in order to process a sched_act_asa
//
	// This is the $edit array I prepare for the scheduled action

		$edit = array();

		$edit['which'] = $aid; // This is the $aid (action ID) of the action just stored above
		$edit['a1type'] = 0;
		$edit['a2type'] = 0;
		$edit['a3type'] = 0;
		$edit['a4type'] = 0;
		$edit['terms'] = array();
		$edit['number'] = $rec['number']; // quantity of units of time to wait
		$edit['unit'] = $rec['unit']; // units of time 
		
	// This is what I call to schedule the action to be scheduled to be executed (i.e., stored in sched_act table)
	
		action_sched_act_asa('do', $edit);

       // That's it.  We're done.  When cron runs, it hooks into sched_act_cron which will execute any actions 
      //  which are scheduled to be executed.

My only problem now is to figure out how to programmatically delete the email actions once they are sent. Any solutions for that?

jefkin’s picture

Title: How do you trigger an action? » How do you programmatically delete the email actions once they are sent?

How very Meta!

This is where the books often say, "... is left to the reader as an exercise."

My suggestion (as a coder, but not one who's fooled around with actions or scheduled actions in drupal before) is, make a mod to the sched_action table with a new boolean (or tinyint) field that marks fire once events. These events would be pruned by sched_action every 12 hours, say when the marked row entry is 1 day expired.

The default for the table column should be false, and must be set to true explicitly, prossibly meaning a modification to actions_save.

Jeff

somebodysysop’s picture

What I ended up doing in views_mail is creating a second action: Delete the email action, and using cron to run and execute it. Works like a charm.

jefkin’s picture

Status: Active » Closed (fixed)