Skip to content

Commit 22f9b86

Browse files
committed
[Commands] fixed DB injection - followup of #187
1 parent 719b900 commit 22f9b86

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/ActionTrigger/EventHandler/DefaultEventHandler.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DefaultEventHandler implements EventHandlerInterface
3333
{
3434
use LoggerAware;
3535

36-
private $rulesGroupedByEvents;
36+
private $rulesGroupedByEvents = null;
3737

3838
/**
3939
* @var QueueInterface
@@ -47,24 +47,29 @@ class DefaultEventHandler implements EventHandlerInterface
4747

4848
public function __construct(QueueInterface $actionTriggerQueue, PaginatorInterface $paginator)
4949
{
50-
$rules = new Rule\Listing();
51-
$rules->setCondition('active = 1');
52-
$rules = $rules->load();
50+
$this->actionTriggerQueue = $actionTriggerQueue;
51+
$this->paginator = $paginator;
52+
}
5353

54-
$rulesGroupedByEvents = [];
54+
protected function getRulesGroupedByEvents() {
55+
if($this->rulesGroupedByEvents === null) {
56+
$rules = new Rule\Listing();
57+
$rules->setCondition('active = 1');
58+
$rules = $rules->load();
5559

56-
foreach ($rules as $rule) {
57-
if ($triggers = $rule->getTrigger()) {
58-
foreach ($triggers as $trigger) {
59-
$rulesGroupedByEvents[$trigger->getEventName()][] = $rule;
60+
$rulesGroupedByEvents = [];
61+
62+
foreach ($rules as $rule) {
63+
if ($triggers = $rule->getTrigger()) {
64+
foreach ($triggers as $trigger) {
65+
$rulesGroupedByEvents[$trigger->getEventName()][] = $rule;
66+
}
6067
}
6168
}
69+
$this->rulesGroupedByEvents = $rulesGroupedByEvents;
6270
}
6371

64-
$this->rulesGroupedByEvents = $rulesGroupedByEvents;
65-
66-
$this->actionTriggerQueue = $actionTriggerQueue;
67-
$this->paginator = $paginator;
72+
return $this->rulesGroupedByEvents;
6873
}
6974

7075
public function handleEvent($event)
@@ -154,8 +159,8 @@ private function getAppliedRules(EventInterface $event, RuleEnvironmentInterface
154159
{
155160
$appliedRules = [];
156161

157-
if (isset($this->rulesGroupedByEvents[$event->getName()]) && sizeof(
158-
$this->rulesGroupedByEvents[$event->getName()]
162+
if (isset($this->getRulesGroupedByEvents()[$event->getName()]) && sizeof(
163+
$this->getRulesGroupedByEvents()[$event->getName()]
159164
)
160165
) {
161166
$rules = $this->rulesGroupedByEvents[$event->getName()];

0 commit comments

Comments
 (0)