Allow multiple subjects of the same type
[MAILPOET-4465]
This commit is contained in:
@@ -55,8 +55,8 @@ class TriggerHandler {
|
||||
|
||||
// ensure subjects are registered and loadable
|
||||
$loadedSubjects = [];
|
||||
foreach ($subjects as $key => $args) {
|
||||
$loadedSubjects[] = $this->subjectLoader->loadSubject($key, $args);
|
||||
foreach ($subjects as $subject) {
|
||||
$loadedSubjects[] = $this->subjectLoader->loadSubject($subject['key'], $subject['args']);
|
||||
}
|
||||
|
||||
$workflowRun = new WorkflowRun($workflow->getId(), $trigger->getKey(), $loadedSubjects);
|
||||
|
@@ -42,11 +42,9 @@ class WorkflowRunStorage {
|
||||
|
||||
if ($result) {
|
||||
$data = (array)$result;
|
||||
$subjects = [];
|
||||
foreach (Json::decode($data['subjects']) as $key => $args) {
|
||||
$subjects[$key] = $this->subjectLoader->loadSubject($key, $args);
|
||||
}
|
||||
$data['subjects'] = $subjects;
|
||||
$data['subjects'] = array_map(function (array $subject) {
|
||||
return $this->subjectLoader->loadSubject($subject['key'], $subject['args']);
|
||||
}, Json::decode($data['subjects']));
|
||||
return WorkflowRun::fromArray($data);
|
||||
}
|
||||
return null;
|
||||
|
@@ -76,7 +76,14 @@ class WorkflowRun {
|
||||
}
|
||||
|
||||
/** @return Subject[] */
|
||||
public function getSubjects(): array {
|
||||
public function getSubjects(string $key = null): array {
|
||||
if ($key) {
|
||||
return array_values(
|
||||
array_filter($this->subjects, function (Subject $subject) use ($key) {
|
||||
return $subject->getKey() === $key;
|
||||
})
|
||||
);
|
||||
}
|
||||
return $this->subjects;
|
||||
}
|
||||
|
||||
@@ -88,10 +95,9 @@ class WorkflowRun {
|
||||
'created_at' => $this->createdAt->format(DateTimeImmutable::W3C),
|
||||
'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C),
|
||||
'subjects' => Json::encode(
|
||||
array_reduce($this->subjects, function (array $subjects, Subject $subject): array {
|
||||
$subjects[$subject->getKey()] = $subject->pack();
|
||||
return $subjects;
|
||||
}, [])
|
||||
array_map(function (Subject $subject): array {
|
||||
return ['key' => $subject->getKey(), 'args' => $subject->pack()];
|
||||
}, $this->subjects)
|
||||
),
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user