2 declare(strict_types = 1);
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Exception\InvalidArgumentException;
20 use Symfony\Component\Console\Input\InputArgument;
21 use Symfony\Component\Console\Input\InputDefinition;
22 use Symfony\Component\Console\Input\InputOption;
30 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
59 $commandRegistry = GeneralUtility::makeInstance(CommandRegistry::class);
60 foreach ($commandRegistry->getSchedulableCommands() as $commandIdentifier => $command) {
61 $this->schedulableCommands[$commandIdentifier] = $command;
64 ksort($this->schedulableCommands);
79 if ($this->task !==
null) {
86 if ($this->task !==
null && isset($this->schedulableCommands[$this->task->getCommandIdentifier()])) {
87 $command = $this->schedulableCommands[$this->task->getCommandIdentifier()];
108 if (!isset($this->schedulableCommands[$submittedData[
'task_executeschedulablecommand'][
'command']])) {
112 $command = $this->schedulableCommands[$submittedData[
'task_executeschedulablecommand'][
'command']];
115 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
118 foreach ($command->getDefinition()->getArguments() as $argument) {
119 foreach ((array)$submittedData[
'task_executeschedulablecommand'][
'arguments'] as $argumentName => $argumentValue) {
122 if ($argument->getName() !== $argumentName) {
126 if ($argument->isRequired() && trim($argumentValue) ===
'') {
128 $flashMessageService->getMessageQueueByIdentifier()->addMessage(
131 $this->
getLanguageService()->sL(
'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.mandatoryArgumentMissing'),
134 $this->
getLanguageService()->sL(
'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.updateError'),
143 foreach ($command->getDefinition()->getOptions() as $optionDefinition) {
144 $optionEnabled = $submittedData[
'task_executeschedulablecommand'][
'options'][$optionDefinition->getName()] ??
false;
145 $optionValue = $submittedData[
'task_executeschedulablecommand'][
'option_values'][$optionDefinition->getName()] ?? $optionDefinition->getDefault();
146 if ($optionEnabled && $optionDefinition->isValueRequired()) {
147 if ($optionDefinition->isArray()) {
148 $testValues = is_array($optionValue) ? $optionValue : GeneralUtility::trimExplode(
',', $optionValue,
false);
150 $testValues = [$optionValue];
153 foreach ($testValues as $testValue) {
154 if ($testValue ===
null || trim($testValue) ===
'') {
156 $flashMessageService->getMessageQueueByIdentifier()->addMessage(
159 $this->
getLanguageService()->sL(
'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.mandatoryArgumentMissing'),
160 $optionDefinition->getName()
162 $this->getLanguageService()->sL(
'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.updateError'),
172 return $hasErrors ===
false;
184 $command = $this->schedulableCommands[$submittedData[
'task_executeschedulablecommand'][
'command']];
190 foreach ((array)$submittedData[
'task_executeschedulablecommand'][
'arguments'] as $argumentName => $argumentValue) {
192 $argumentDefinition = $command->getDefinition()->getArgument($argumentName);
193 }
catch (InvalidArgumentException $e) {
197 if ($argumentDefinition->isArray()) {
198 $argumentValue = GeneralUtility::trimExplode(
',', $argumentValue,
true);
201 $arguments[$argumentName] = $argumentValue;
206 foreach ($command->getDefinition()->getOptions() as $optionDefinition) {
207 $optionEnabled = $submittedData[
'task_executeschedulablecommand'][
'options'][$optionDefinition->getName()] ??
false;
208 $options[$optionDefinition->getName()] = (bool)$optionEnabled;
210 if ($optionDefinition->isValueRequired() || $optionDefinition->isValueOptional() || $optionDefinition->isArray()) {
211 $optionValue = $submittedData[
'task_executeschedulablecommand'][
'option_values'][$optionDefinition->getName()] ?? $optionDefinition->getDefault();
212 if ($optionDefinition->isArray() && !is_array($optionValue)) {
216 $optionValue = GeneralUtility::trimExplode(
',', $optionValue,
false);
220 $optionValue = (bool)$optionEnabled;
222 $optionValues[$optionDefinition->getName()] = $optionValue;
241 'label' =>
'<strong>' . $description .
'</strong>'
252 $currentlySelectedCommand = $this->task !==
null ? $this->task->getCommandIdentifier() :
'';
254 foreach ($this->schedulableCommands as $commandIdentifier => $command) {
255 $options[$commandIdentifier] = $commandIdentifier .
': ' . $command->getDescription();
259 'label' => $this->
getLanguageService()->
sL(
'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.schedulableCommandName')
274 $argumentValues = $this->task->getArguments();
275 foreach ($inputDefinition->getArguments() as $argument) {
276 $name = $argument->getName();
277 $defaultValue = $argument->getDefault();
278 $this->task->addDefaultValue($name, $defaultValue);
279 $value = $argumentValues[$name] ?? $defaultValue;
281 if (is_array($value) && $argument->isArray()) {
282 $value = implode(
',', $value);
305 $enabledOptions = $this->task->getOptions();
306 $optionValues = $this->task->getOptionValues();
307 foreach ($inputDefinition->getOptions() as $option) {
308 $name = $option->getName();
309 $defaultValue = $option->getDefault();
310 $this->task->addDefaultValue($name, $defaultValue);
311 $enabled = $enabledOptions[$name] ??
false;
312 $value = $optionValues[$name] ?? $defaultValue;
314 if (is_array($value) && $option->isArray()) {
315 $value = implode(
',', $value);
335 return 'Argument: ' . $argument->getName() .
'. <em>' . htmlspecialchars($argument->getDescription()) .
'</em>';
346 return 'Option: ' . htmlspecialchars($option->getName()) .
'. <em>' . htmlspecialchars($option->getDescription()) .
'</em>';
354 protected function renderSelectField(array $options,
string $selectedOptionValue): string
356 $selectTag =
new TagBuilder();
357 $selectTag->setTagName(
'select');
358 $selectTag->forceClosingTag(
true);
359 $selectTag->addAttribute(
'class',
'form-control');
360 $selectTag->addAttribute(
'name',
'tx_scheduler[task_executeschedulablecommand][command]');
363 foreach ($options as $value => $label) {
364 $optionTag =
new TagBuilder();
365 $optionTag->setTagName(
'option');
366 $optionTag->forceClosingTag(
true);
367 $optionTag->addAttribute(
'title', (
string)$label);
368 $optionTag->addAttribute(
'value', (
string)$value);
369 $optionTag->setContent($label);
371 if ($value === $selectedOptionValue) {
372 $optionTag->addAttribute(
'selected',
'selected');
375 $optionsHtml .= $optionTag->render();
378 $selectTag->setContent($optionsHtml);
379 return $selectTag->render();
391 $name = $argument->getName();
392 $fieldName =
'tx_scheduler[task_executeschedulablecommand][arguments][' . $name .
']';
394 $inputTag =
new TagBuilder();
395 $inputTag->setTagName(
'input');
396 $inputTag->addAttribute(
'type',
'text');
397 $inputTag->addAttribute(
'name', $fieldName);
398 $inputTag->addAttribute(
'value', $currentValue);
399 $inputTag->addAttribute(
'class',
'form-control');
401 return $inputTag->render();
411 protected function renderOptionField(InputOption $option,
bool $enabled,
string $currentValue): string
413 $name = $option->getName();
415 $checkboxFieldName =
'tx_scheduler[task_executeschedulablecommand][options][' . $name .
']';
416 $checkboxId =
'tx_scheduler_task_executeschedulablecommand_options_' . $name;
417 $checkboxTag =
new TagBuilder();
418 $checkboxTag->setTagName(
'input');
419 $checkboxTag->addAttribute(
'id', $checkboxId);
420 $checkboxTag->addAttribute(
'name', $checkboxFieldName);
421 $checkboxTag->addAttribute(
'type',
'checkbox');
423 $checkboxTag->addAttribute(
'checked',
'checked');
425 $html =
'<label for="' . $checkboxId .
'">'
426 . $checkboxTag->render()
427 .
' ' . $this->
getLanguageService()->
sL(
'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.addOptionToCommand')
430 if ($option->isValueRequired() || $option->isValueOptional() || $option->isArray()) {
431 $valueFieldName =
'tx_scheduler[task_executeschedulablecommand][option_values][' . $name .
']';
432 $inputTag =
new TagBuilder();
433 $inputTag->setTagName(
'input');
434 $inputTag->addAttribute(
'name', $valueFieldName);
435 $inputTag->addAttribute(
'type',
'text');
436 $inputTag->addAttribute(
'value', $currentValue);
437 $inputTag->addAttribute(
'class',
'form-control');
438 $html .= $inputTag->render();