Skip to content

Commit 74cd8c3

Browse files
authored
[Custom Reports]: Make element_type and element_class_id optional in CsvCreationHandler (#1773)
1 parent 4ae38ac commit 74cd8c3

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/ExecutionEngine/AutomationAction/AbstractHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ protected function getElementById(
156156
throw new EnvironmentException('How did I get here?');
157157
}
158158

159+
protected function extractOptionalConfigFieldFromJobStepConfig(
160+
GenericExecutionEngineMessageInterface $message,
161+
string $key,
162+
mixed $default = null,
163+
): mixed {
164+
$config = $this->getCurrentJobStepConfig($message);
165+
166+
return array_key_exists($key, $config) ? $config[$key] : $default;
167+
}
168+
159169
protected function updateContextArrayValues(JobRun $jobRun, string $key, array $value): void
160170
{
161171
$context = $jobRun->getContext();

src/Export/ExecutionEngine/AutomationAction/Messenger/Handler/CsvCreationHandler.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Pimcore\Bundle\StudioBackendBundle\Export\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCreationMessage;
2323
use Pimcore\Bundle\StudioBackendBundle\Export\Model\GridExportData;
2424
use Pimcore\Bundle\StudioBackendBundle\Export\Service\ExportServiceInterface;
25-
use Pimcore\Bundle\StudioBackendBundle\Export\Util\Trait\ExportCreationHandlerSetupTrait;
2625
use Pimcore\Bundle\StudioBackendBundle\Mercure\Service\PublishServiceInterface;
2726
use Pimcore\Bundle\StudioBackendBundle\Mercure\Service\UserTopicServiceInterface;
2827
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
@@ -33,7 +32,6 @@
3332
#[AsMessageHandler]
3433
final class CsvCreationHandler extends AbstractHandler
3534
{
36-
use ExportCreationHandlerSetupTrait;
3735
use HandlerProgressTrait;
3836

3937
public function __construct(
@@ -66,8 +64,8 @@ public function __invoke(CsvCreationMessage $message): void
6664

6765
$columns = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::CONFIG_COLUMNS->value);
6866
$settings = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::CONFIG_CONFIGURATION->value);
69-
$elementType = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::ELEMENT_TYPE->value);
70-
$classId = $this->extractConfigFieldFromJobStepConfig($message, StepConfig::ELEMENT_CLASS_ID->value);
67+
$elementType = $this->extractOptionalConfigFieldFromJobStepConfig($message, StepConfig::ELEMENT_TYPE->value);
68+
$classId = $this->extractOptionalConfigFieldFromJobStepConfig($message, StepConfig::ELEMENT_CLASS_ID->value);
7169
$headers = $settings[StepConfig::SETTINGS_HEADER->value] ?? StepConfig::SETTINGS_HEADER_NO_HEADER->value;
7270
$delimiter = $settings[StepConfig::SETTINGS_DELIMITER->value] ?? null;
7371

@@ -106,4 +104,24 @@ public function __invoke(CsvCreationMessage $message): void
106104
$this->getJobStep($message)->getName()
107105
);
108106
}
107+
108+
protected function configureStep(): void
109+
{
110+
$this->stepConfiguration->setRequired(StepConfig::CONFIG_CONFIGURATION->value);
111+
$this->stepConfiguration->setAllowedTypes(
112+
StepConfig::CONFIG_CONFIGURATION->value,
113+
StepConfig::CONFIG_TYPE_ARRAY->value
114+
);
115+
$this->stepConfiguration->setRequired(StepConfig::CONFIG_COLUMNS->value);
116+
$this->stepConfiguration->setAllowedTypes(
117+
StepConfig::CONFIG_COLUMNS->value,
118+
StepConfig::CONFIG_TYPE_ARRAY->value
119+
);
120+
$this->stepConfiguration->setDefaults([
121+
StepConfig::CONFIG_COLUMNS->value => [],
122+
StepConfig::CONFIG_CONFIGURATION->value => [],
123+
StepConfig::ELEMENT_TYPE->value => null,
124+
StepConfig::ELEMENT_CLASS_ID->value => null,
125+
]);
126+
}
109127
}

0 commit comments

Comments
 (0)