You are here

private function BusinessRulesProcessor::avoidInfiniteLoop in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Util/BusinessRulesProcessor.php \Drupal\business_rules\Util\BusinessRulesProcessor::avoidInfiniteLoop()

Check if the event was already processed during the current request.

Get the processed events subject and reactsOn event then compare with the current event subject and reactsOn. If the there is one event with the current subject and reactsOn arguments is already processed, then stop the tell the processor to stop processing. It's necessary to avoid infinite loops when there is a business rule being executed on entity update for example.

Parameters

\Drupal\business_rules\Events\BusinessRulesEvent $event: The event being processed.

Return value

bool TRUE|FALSE

1 call to BusinessRulesProcessor::avoidInfiniteLoop()
BusinessRulesProcessor::process in src/Util/BusinessRulesProcessor.php
Process rules.

File

src/Util/BusinessRulesProcessor.php, line 202

Class

BusinessRulesProcessor
Class BusinessRulesProcessor.

Namespace

Drupal\business_rules\Util

Code

private function avoidInfiniteLoop(BusinessRulesEvent $event) {
  $keyvalue = $this->util
    ->getKeyValueExpirable('process');
  $processed_events = $keyvalue
    ->getAll();
  $loop_control = $event
    ->hasArgument('loop_control') ? $event
    ->getArgument('loop_control') : $event
    ->getSubject();
  $serialized_data = json_encode($loop_control) . json_encode($event
    ->getArgument('reacts_on'));
  if (count($processed_events)) {
    foreach ($processed_events as $processed_event) {
      if ($serialized_data == $processed_event) {
        return TRUE;
      }
    }
  }
  $this->processId = $this->util->container
    ->get('uuid')
    ->generate();
  $keyvalue
    ->set($this->processId, $serialized_data);
  return FALSE;
}