Пример #1
0
 /**
  * This method will make a Processor that will process each transaction journal using the triggers
  * and actions found in the given Rule.
  *
  * @param Rule $rule
  *
  * @return Processor
  */
 public static function make(Rule $rule)
 {
     Log::debug(sprintf('Making new rule from Rule %d', $rule->id));
     $self = new self();
     $self->rule = $rule;
     $triggerSet = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
     /** @var RuleTrigger $trigger */
     foreach ($triggerSet as $trigger) {
         $self->triggers->push(TriggerFactory::getTrigger($trigger));
     }
     $self->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
     return $self;
 }
Пример #2
0
 /**
  * @return bool
  */
 protected function actions()
 {
     /**
      * @var int        $index
      * @var RuleAction $action
      */
     foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $action) {
         $type = $action->action_type;
         $class = $this->actionTypes[$type];
         Log::debug('Action #' . $action->id . ' for rule #' . $action->rule_id . ' (' . $type . ')');
         if (!class_exists($class)) {
             abort(500, 'Could not instantiate class for rule action type "' . $type . '" (' . $class . ').');
         }
         /** @var ActionInterface $actionClass */
         $actionClass = new $class($action, $this->journal);
         $actionClass->act();
         if ($action->stop_processing) {
             break;
         }
     }
     return true;
 }
Пример #3
0
 /**
  * @param Rule  $rule
  * @param array $data
  *
  * @return Rule
  */
 public function update(Rule $rule, array $data)
 {
     // update rule:
     $rule->active = $data['active'];
     $rule->stop_processing = $data['stop_processing'];
     $rule->title = $data['title'];
     $rule->description = $data['description'];
     $rule->save();
     // delete triggers:
     $rule->ruleTriggers()->delete();
     // delete actions:
     $rule->ruleActions()->delete();
     // recreate triggers:
     $order = 1;
     $stopProcessing = false;
     $triggerValues = ['action' => 'user_action', 'value' => $data['trigger'], 'stopProcessing' => $stopProcessing, 'order' => $order];
     $this->storeTrigger($rule, $triggerValues);
     foreach ($data['rule-triggers'] as $index => $trigger) {
         $value = $data['rule-trigger-values'][$index];
         $stopProcessing = isset($data['rule-trigger-stop'][$index]) ? true : false;
         $triggerValues = ['action' => $trigger, 'value' => $value, 'stopProcessing' => $stopProcessing, 'order' => $order];
         $this->storeTrigger($rule, $triggerValues);
         $order++;
     }
     // recreate actions:
     $order = 1;
     foreach ($data['rule-actions'] as $index => $action) {
         $value = $data['rule-action-values'][$index];
         $stopProcessing = isset($data['rule-action-stop'][$index]) ? true : false;
         $actionValues = ['action' => $action, 'value' => $value, 'stopProcessing' => $stopProcessing, 'order' => $order];
         $this->storeAction($rule, $actionValues);
     }
     return $rule;
 }
Пример #4
0
 /**
  * @param Rule  $rule
  * @param array $data
  *
  * @return Rule
  */
 public function update(Rule $rule, array $data) : Rule
 {
     // update rule:
     $rule->active = $data['active'];
     $rule->stop_processing = $data['stop_processing'];
     $rule->title = $data['title'];
     $rule->description = $data['description'];
     $rule->save();
     // delete triggers:
     $rule->ruleTriggers()->delete();
     // delete actions:
     $rule->ruleActions()->delete();
     // recreate triggers:
     $this->storeTriggers($rule, $data);
     // recreate actions:
     $this->storeActions($rule, $data);
     return $rule;
 }