Skip to content
Snippets Groups Projects
Commit 4ad8cb02 authored by jaapjansma's avatar jaapjansma
Browse files

added rechecking of conditions at processing of delayed actions

parent c6312eb1
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,16 @@ abstract class CRM_Civirules_Action {
return $params;
}
/**
* Returns wether we should ignore rechecking of the conditions when an action
* is executed with a delay
*
* @return bool
*/
public function ignoreConditionsOnDelayedProcessing() {
return $this->ruleAction['ignore_condition_with_delay'] ? true : false;
}
/**
* Returns a redirect url to extra data input from the user after adding a action
*
......
......@@ -50,6 +50,10 @@ class CRM_Civirules_DAO_RuleAction extends CRM_Core_DAO {
'name' => 'delay',
'type' => CRM_Utils_Type::T_TEXT
),
'ignore_condition_with_delay' => array(
'name' => 'ignore_condition_with_delay',
'type' => CRM_Utils_Type::T_INT,
),
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_INT,
......@@ -73,6 +77,7 @@ class CRM_Civirules_DAO_RuleAction extends CRM_Core_DAO {
'action_id' => 'action_id',
'action_params' => 'action_params',
'delay' => 'delay',
'ignore_condition_with_delay' => 'ignore_condition_with_delay',
'is_active' => 'is_active'
);
}
......
......@@ -130,7 +130,15 @@ class CRM_Civirules_Engine {
*/
public static function executeDelayedAction(CRM_Queue_TaskContext $ctx, CRM_Civirules_Action $action, CRM_Civirules_TriggerData_TriggerData $triggerData) {
try {
$action->processAction($triggerData);
if ($action->ignoreConditionsOnDelayedProcessing()) {
$processAction = true;
} else {
$processAction = self::areConditionsValid($triggerData);
}
if ($processAction) {
$action->processAction($triggerData);
}
} catch (Exception $e) {
CRM_Civirules_Utils_LoggerFactory::logError("Failed to execute delayed action", $e->getMessage(), $triggerData);
}
......@@ -261,14 +269,10 @@ class CRM_Civirules_Engine {
/**
* This function writes a record to the log table to indicate that this rule for this trigger is triggered
*
<<<<<<< HEAD
* The data this function stores is required by the cron type events.
* @todo: think of a better handling for cron type events
*
* @param CRM_Civirules_EventData_EventData $eventData
=======
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
>>>>>>> origin/event_to_trigger
*/
protected static function logRule(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$sql = "INSERT INTO `civirule_rule_log` (`rule_id`, `contact_id`, `log_date`) VALUES (%1, %2, NOW())";
......
......@@ -75,6 +75,7 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
'rule_id' => $this->_submitValues['rule_id'],
'action_id' => $this->_submitValues['rule_action_select'],
'delay' => 'null',
'ignore_condition_with_delay' => '0',
);
if ($this->ruleActionId) {
$saveParams['id'] = $this->ruleActionId;
......@@ -84,6 +85,7 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
$delayClass = CRM_Civirules_Delay_Factory::getDelayClassByName($this->_submitValues['delay_select']);
$delayClass->setValues($this->_submitValues);
$saveParams['delay'] = serialize($delayClass);
$saveParams['ignore_condition_with_delay'] = $this->_submitValues['ignore_condition_with_delay'];
}
$ruleAction = CRM_Civirules_BAO_RuleAction::add($saveParams);
......@@ -127,6 +129,7 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
$delay_class->addElements($this);
}
$this->assign('delayClasses', CRM_Civirules_Delay_Factory::getAllDelayClasses());
$this->add('checkbox', 'ignore_condition_with_delay', ts('Don\'t recheck condition upon processing of delayed action'));
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE,),
......@@ -143,6 +146,7 @@ class CRM_Civirules_Form_RuleAction extends CRM_Core_Form {
if (!empty($this->ruleActionId)) {
$defaults['rule_action_select'] = $this->ruleActionId;
$defaults['id'] = $this->ruleActionId;
$defaults['ignore_condition_with_delay'] = $this->ruleAction->ignore_condition_with_delay;
$delayClass = unserialize($this->ruleAction->delay);
if ($delayClass) {
......
......@@ -85,6 +85,7 @@ class CRM_Civirules_Upgrader extends CRM_Civirules_Upgrader_Base {
*/
public function upgrade_1004() {
CRM_Core_DAO::executeQuery("update `civirule_trigger` set `class_name` = 'CRM_CivirulesPostTrigger_EntityTag' where `object_name` = 'EntityTag';");
CRM_Core_DAO::executeQuery("ALTER TABLE `civirule_rule_action` ADD COLUMN `ignore_condition_with_delay` TINYINT NULL default 0 AFTER `delay`");
return true;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS civirule_rule_action (
action_id INT UNSIGNED NULL,
action_params TEXT NULL,
delay TEXT NULL,
ignore_condition_with_delay TINYINT NULL default 0,
is_active TINYINT NULL DEFAULT 1,
PRIMARY KEY (id),
UNIQUE INDEX id_UNIQUE (id ASC),
......
......@@ -30,6 +30,14 @@
{include file=$delayClass->getTemplateFilename()}
</div>
{/foreach}
<div class="crm-section crm-ignore_condition_with_delay" id="div_ignore_condition_with_delay">
<div class="label"></div>
<div class="content">
{$form.ignore_condition_with_delay.html}
{$form.ignore_condition_with_delay.label}
</div>
<div class="clear"></div>
</div>
</div>
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment