initializeResultArray();
$selectedTaskType = $this->data['databaseRow']['tasktype'][0] ?? '';
if ($selectedTaskType === '') {
return $resultArray;
}
$parameterArray = $this->data['parameterArray'];
$itemName = $parameterArray['itemFormElName'];
try {
$taskObject = $this->taskRepository->findByUid((int)$this->data['databaseRow']['uid']);
} catch (\OutOfBoundsException) {
// This happens for new tasks when 'uid' is set to "0" because we have a Task Type from defVals
try {
$taskObject = $this->taskService->createNewTask($selectedTaskType);
} catch (InvalidTaskException) {
// Given task type is not registered - skip this element
return $resultArray;
}
}
if ($taskObject instanceof ExecuteSchedulableCommandTask === false) {
// Task is not an executable schedulable command task
return $resultArray;
}
try {
$command = $this->commandRegistry->get($selectedTaskType);
} catch (CommandNotFoundException) {
// Command not found
return $resultArray;
}
$argumentFields = $this->getCommandArgumentFields($command->getDefinition(), $taskObject);
$optionFields = $this->getCommandOptionFields($command->getDefinition(), $taskObject);
if ($argumentFields !== [] || $optionFields !== []) {
$fieldInformationResult = $this->renderFieldInformation();
$fieldInformationHtml = $fieldInformationResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false);
$html = [];
$html[] = '
';
$resultArray['html'] = $this->wrapWithFieldsetAndLegend(implode(LF, $html));
}
return $resultArray;
}
protected function getCommandArgumentFields(InputDefinition $inputDefinition, ExecuteSchedulableCommandTask $task): array
{
$fields = [];
$argumentValues = $task->getArguments();
foreach ($inputDefinition->getArguments() as $argument) {
$name = $argument->getName();
$defaultValue = $argument->getDefault();
$task->addDefaultValue($name, $defaultValue);
$value = $argumentValues[$name] ?? $defaultValue;
if (is_array($value) && $argument->isArray()) {
$value = implode(',', $value);
}
$fields['arguments'][$name] = [
'label' => 'Argument "' . $argument->getName() . '"',
'description' => $argument->getDescription(),
'value' => $value,
'required' => $argument->isRequired(),
];
}
return $fields;
}
protected function getCommandOptionFields(InputDefinition $inputDefinition, ExecuteSchedulableCommandTask $task): array
{
$fields = [];
$enabledOptions = $task->getOptions();
$optionValues = $task->getOptionValues();
foreach ($inputDefinition->getOptions() as $option) {
$name = $option->getName();
$defaultValue = $option->getDefault();
$task->addDefaultValue($name, $defaultValue);
$enabled = $enabledOptions[$name] ?? false;
$value = $optionValues[$name] ?? $defaultValue;
if (is_array($value) && $option->isArray()) {
$value = implode(',', $value);
}
$fields['options'][$name] = [
'label' => 'Option "' . $option->getName() . '"',
'description' => $option->getDescription(),
'enabled' => $enabled,
'value' => $value,
'valueOption' => $option->isValueRequired() || $option->isValueOptional() || $option->isArray(),
];
}
return $fields;
}
protected function getRunOnCliInfo(ExecuteSchedulableCommandTask $taskObject, Command $command): string
{
$options = [];
foreach ($taskObject->getOptions() as $name => $enabled) {
if ($enabled) {
$value = $taskObject->getOptionValues()[$name] ?? null;
$options['--' . $name] = ($value === true) ? '' : $value;
}
}
$parameters = array_merge($taskObject->getArguments(), $options);
try {
$input = new ArrayInput($parameters, $command->getDefinition());
$arguments = $input->__toString();
$cliCommand = '' . $command->getName() . ' ' . $arguments . '
';
} catch (RuntimeException|InvalidArgumentException $e) {
$cliCommand = '' . htmlspecialchars(sprintf($this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.errorParsingArguments'), $e->getMessage())) . '
';
} catch (InvalidOptionException $e) {
$cliCommand = '' . htmlspecialchars(sprintf($this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.errorParsingOptions'), $e->getMessage())) . '
';
}
return '
';
}
protected function renderCommandConfiguration(array $fields, string $taskType, string $itemName): string
{
return $this->viewFactory->create(
new ViewFactoryData(
templateRootPaths: ['EXT:scheduler/Resources/Private/Templates'],
partialRootPaths: ['EXT:scheduler/Resources/Private/Partials'],
layoutRootPaths: ['EXT:scheduler/Resources/Private/Layouts'],
request: $this->data['request'],
format: 'html',
)
)->assignMultiple([
'taskType' => $taskType,
'fields' => $fields,
'itemName' => $itemName,
'renderDebug' => $this->getBackendUser()->shallDisplayDebugInformation(),
])->render('CommandConfiguration');
}
}