‪TYPO3CMS  9.5
ExecuteSchedulableCommandTask.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Symfony\Component\Console\Exception\InvalidOptionException;
19 use Symfony\Component\Console\Input\ArrayInput;
20 use Symfony\Component\Console\Output\NullOutput;
25 
30 {
34  protected ‪$commandIdentifier = '';
35 
39  protected ‪$arguments = [];
40 
44  protected ‪$options = [];
45 
49  protected ‪$optionValues = [];
50 
54  protected ‪$defaults = [];
55 
59  public function ‪setCommandIdentifier(string ‪$commandIdentifier)
60  {
61  $this->commandIdentifier = ‪$commandIdentifier;
62  }
63 
67  public function ‪getCommandIdentifier(): string
68  {
70  }
71 
83  public function ‪execute(): bool
84  {
85  try {
86  $commandRegistry = GeneralUtility::makeInstance(CommandRegistry::class);
87  $schedulableCommand = $commandRegistry->getCommandByIdentifier($this->commandIdentifier);
88  } catch (UnknownCommandException $e) {
89  throw new \RuntimeException(
90  sprintf(
91  $this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.unregisteredCommand'),
92  $this->commandIdentifier
93  ),
94  1505055445,
95  $e
96  );
97  }
98 
99  $input = new ArrayInput($this->‪getParameters(false));
100  ‪$output = new NullOutput();
101 
102  return $schedulableCommand->run($input, ‪$output) === 0;
103  }
104 
110  public function ‪getAdditionalInformation(): string
111  {
113 
114  try {
115  $commandRegistry = GeneralUtility::makeInstance(CommandRegistry::class);
116  $schedulableCommand = $commandRegistry->getCommandByIdentifier($this->commandIdentifier);
117  } catch (UnknownCommandException $e) {
118  return sprintf(
119  $this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.unregisteredCommand'),
120  $this->commandIdentifier
121  );
122  }
123 
124  try {
125  $input = new ArrayInput($this->‪getParameters(true), $schedulableCommand->getDefinition());
126  ‪$arguments = $input->__toString();
127  } catch (\Symfony\Component\Console\Exception\RuntimeException|\Symfony\Component\Console\Exception\InvalidArgumentException $e) {
128  return $label . "\n"
129  . sprintf(
130  $this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.errorParsingArguments'),
131  $e->getMessage()
132  );
133  } catch (InvalidOptionException $e) {
134  return $label . "\n"
135  . sprintf(
136  $this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.errorParsingOptions'),
137  $e->getMessage()
138  );
139  }
140  if (‪$arguments !== '') {
141  $label .= ' ' . ‪$arguments;
142  }
143 
144  return $label;
145  }
146 
147  public function ‪getArguments(): array
148  {
149  return ‪$this->arguments;
150  }
151 
152  public function ‪setArguments(array ‪$arguments)
153  {
154  $this->arguments = ‪$arguments;
155  }
156 
157  public function ‪getOptions(): array
158  {
159  return ‪$this->options;
160  }
161 
162  public function ‪setOptions(array ‪$options)
163  {
164  $this->options = ‪$options;
165  }
166 
167  public function ‪getOptionValues(): array
168  {
169  return ‪$this->optionValues;
170  }
171 
172  public function ‪setOptionValues(array ‪$optionValues)
173  {
174  $this->optionValues = ‪$optionValues;
175  }
176 
181  public function ‪addDefaultValue(string $argumentName, $argumentValue)
182  {
183  if (is_bool($argumentValue)) {
184  $argumentValue = (int)$argumentValue;
185  }
186  $this->defaults[$argumentName] = $argumentValue;
187  }
188 
193  {
194  return ‪$GLOBALS['LANG'];
195  }
196 
197  private function ‪getParameters(bool $forDisplay): array
198  {
199  ‪$options = [];
200  foreach ($this->options as $name => $enabled) {
201  if ($enabled) {
202  $value = $this->optionValues[$name] ?? null;
203  ‪$options['--' . $name] = ($forDisplay && $value === true) ? '' : $value;
204  }
205  }
206  return array_merge($this->arguments, ‪$options);
207  }
208 }
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getCommandIdentifier
‪string getCommandIdentifier()
Definition: ExecuteSchedulableCommandTask.php:62
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\execute
‪bool execute()
Definition: ExecuteSchedulableCommandTask.php:78
‪TYPO3\CMS\Core\Console\UnknownCommandException
Definition: UnknownCommandException.php:24
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:2
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\setArguments
‪setArguments(array $arguments)
Definition: ExecuteSchedulableCommandTask.php:147
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getOptionValues
‪getOptionValues()
Definition: ExecuteSchedulableCommandTask.php:162
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask
Definition: ExecuteSchedulableCommandTask.php:30
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\$optionValues
‪array $optionValues
Definition: ExecuteSchedulableCommandTask.php:45
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\addDefaultValue
‪addDefaultValue(string $argumentName, $argumentValue)
Definition: ExecuteSchedulableCommandTask.php:176
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\$options
‪array $options
Definition: ExecuteSchedulableCommandTask.php:41
‪TYPO3\CMS\Core\Console\CommandRegistry
Definition: CommandRegistry.php:27
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getLanguageService
‪LanguageService getLanguageService()
Definition: ExecuteSchedulableCommandTask.php:187
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\$arguments
‪array $arguments
Definition: ExecuteSchedulableCommandTask.php:37
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\$defaults
‪array $defaults
Definition: ExecuteSchedulableCommandTask.php:49
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\setCommandIdentifier
‪setCommandIdentifier(string $commandIdentifier)
Definition: ExecuteSchedulableCommandTask.php:54
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getAdditionalInformation
‪string getAdditionalInformation()
Definition: ExecuteSchedulableCommandTask.php:105
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\setOptions
‪setOptions(array $options)
Definition: ExecuteSchedulableCommandTask.php:157
‪$output
‪$output
Definition: annotationChecker.php:113
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\$commandIdentifier
‪string $commandIdentifier
Definition: ExecuteSchedulableCommandTask.php:33
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getOptions
‪getOptions()
Definition: ExecuteSchedulableCommandTask.php:152
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getParameters
‪getParameters(bool $forDisplay)
Definition: ExecuteSchedulableCommandTask.php:192
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\setOptionValues
‪setOptionValues(array $optionValues)
Definition: ExecuteSchedulableCommandTask.php:167
‪TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask\getArguments
‪getArguments()
Definition: ExecuteSchedulableCommandTask.php:142