Skip to content
Snippets Groups Projects
Commit 822a33f0 authored by jaapjansma's avatar jaapjansma
Browse files

proof of concept of logger

parent 6eaf2db3
No related branches found
No related tags found
No related merge requests found
......@@ -22,13 +22,17 @@ class CRM_Civirules_Engine {
* @static
*/
public static function triggerRule(CRM_Civirules_Event $event, CRM_Civirules_EventData_EventData $eventData) {
$eventData->setEvent($event);
$isRuleValid = self::areConditionsValid($eventData);
try {
$eventData->setEvent($event);
$isRuleValid = self::areConditionsValid($eventData);
if ($isRuleValid) {
self::logRule($eventData);
self::executeActions($eventData);
return true;
if ($isRuleValid) {
self::logRule($eventData);
self::executeActions($eventData);
return true;
}
} catch (Exception $e) {
CRM_Civirules_Utils_LoggerFactory::logError("Failed to execute rule", $e->getMessage(), $eventData);
}
return false;
}
......@@ -120,7 +124,11 @@ class CRM_Civirules_Engine {
* @return bool
*/
public static function executeDelayedAction(CRM_Queue_TaskContext $ctx, CRM_Civirules_Action $action, CRM_Civirules_EventData_EventData $eventData) {
$action->processAction($eventData);
try {
$action->processAction($eventData);
} catch (Exception $e) {
CRM_Civirules_Utils_LoggerFactory::logError("Failed to execute delayed action", $e->getMessage(), $eventData);
}
return true;
}
......@@ -248,6 +256,9 @@ class CRM_Civirules_Engine {
/**
* This function writes a record to the log table to indicate that this rule for this event is triggered
*
* 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
*/
protected static function logRule(CRM_Civirules_EventData_EventData $eventData) {
......@@ -256,4 +267,5 @@ class CRM_Civirules_Engine {
$params[2] = array($eventData->getContactId(), 'Integer');
CRM_Core_DAO::executeQuery($sql, $params);
}
}
\ No newline at end of file
......@@ -8,6 +8,11 @@ abstract class CRM_Civirules_Event {
protected $eventParams;
/**
* @var string
*/
protected $ruleTitle;
public function setRuleId($ruleId) {
$this->ruleId = $ruleId;
}
......@@ -28,6 +33,17 @@ abstract class CRM_Civirules_Event {
return $this->eventId;
}
public function getRuleTitle() {
if (empty($this->ruleTitle) && !empty($this->ruleId)) {
$rule = new CRM_Civirules_BAO_Rule();
$rule->id = $this->ruleId;
if ($rule->find(true)) {
$this->ruleTitle = $rule->label;
}
}
return $this->ruleTitle;
}
/**
* Returns an array of entities on which the event reacts
*
......
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