Posted by gtin on May 24, 2009 at 6:22am
Hi,
I am new to rules but I was able to create a triggered rule that schedules a rule set to run at a given date when a node is flagged. How can I delete the scheduled rule from rules_scheduler table when the node is unflagged?
Thanks
Comments
Hm, as of now you can't. But
Hm, as of now you can't. But work is in progress, check: http://groups.drupal.org/node/22929 or the soc project in general.
As of now, you can only add a condition that checks if the scheduled rule set schould still operate once it's executed.. (not ideal, yes.)
Checking a condition in the scheduler
Here's an example. I'm setting an alarm on a "task" type node based on the "deadline" CCK date field.
When the "task" is saved, I schedule an alarm which I've created as a rule-set. The rule-set takes two arguments, the task node and the "original deadline". I pass the deadline when the task is saved as "original deadline" to the alarm rule. If the task is changed, a second alarm will be scheduled, with a new "original deadline" in it. Both alarms will start executing, but the condition will see that the first alarm no longer matches the deadline and will not execute it. The second alarm will have an "original deadline" that still matches the task deadline and will run. Effectively, I've cancelled the first scheduled alarm because it no longer matched my deadline.
The condition is a text comparison. I convert both dates to text, using a PHP evaluation input and the PHP date function. Once both datetimes are in m-d-Y format, theyre easy to compare as text.
This is part of the export, just the conditions part, for you to see how a scheduled event can be canceled if the original conditions no longer apply.
'#conditions' =>
array (
0 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Compare Deadline with Original Deadline',
'label callback' => false,
'arguments' =>
array (
'text1' =>
array (
'label' => 'Text 1',
'type' => 'string',
),
'text2' =>
array (
'label' => 'Text 2',
'type' => 'string',
),
),
'module' => 'Rules',
),
'#name' => 'rules_condition_text_compare',
'#settings' =>
array (
'text1' => '
<?phpecho date("m-d-Y", strtotime($original_deadline));
?>
'text2' => '
<?phpecho date("m-d-Y", strtotime("[task_node:field_task_deadline-datetime]"));
?>
'regex' => 0,
'#eval input' =>
array (
'token_rules_input_evaluator' =>
array (
'text2' =>
array (
0 => 'task_node',
),
),
'rules_input_evaluator_php' =>
array (
'text1' =>
array (
0 => 'original_deadline',
),
'text2' =>
array (
),
),
),
),
'#type' => 'condition',
),
),
easier method?
It's easier to just override the first scheduled alarm by giving the new scheduled alarm the same name as the first (the nodes id for example). A scheduled rule will override another scheduled rule if it has the same name. To achieve this just clone the first triggered alarm (trigger: 'After saving new content') and set the trigger to 'After updating existing content'. example: http://drupal.org/node/652158