2 namespace TYPO3\CMS\Scheduler\CronCommand;
42 $cronCommand = trim($cronCommand);
43 $cronCommand = self::convertKeywordsToCronCommand($cronCommand);
44 $cronCommand = self::normalizeFields($cronCommand);
57 switch ($cronCommand) {
60 $cronCommand =
'0 0 1 1 *';
63 $cronCommand =
'0 0 1 * *';
66 $cronCommand =
'0 0 * * 0';
71 $cronCommand =
'0 0 * * *';
74 $cronCommand =
'0 * * * *';
88 $fieldArray = self::splitFields($cronCommand);
89 $fieldArray[0] = self::normalizeIntegerField($fieldArray[0], 0, 59);
90 $fieldArray[1] = self::normalizeIntegerField($fieldArray[1], 0, 23);
91 $fieldArray[2] = self::normalizeIntegerField($fieldArray[2], 1, 31);
92 $fieldArray[3] = self::normalizeMonthAndWeekdayField($fieldArray[3],
true);
93 $fieldArray[4] = self::normalizeMonthAndWeekdayField($fieldArray[4],
false);
94 $normalizedCronCommand = implode(
' ', $fieldArray);
95 return $normalizedCronCommand;
107 $fields = explode(
' ', $cronCommand);
108 if (count($fields) !== 5) {
109 throw new \InvalidArgumentException(
'Unable to split given cron command to five fields.', 1291227373);
123 if ((
string)$expression ===
'*') {
127 $listOfCommaValues = explode(
',', $expression);
128 $fieldArray = array();
129 foreach ($listOfCommaValues as $listElement) {
130 if (strpos($listElement,
'/') !==
false) {
131 list($left, $right) = explode(
'/', $listElement);
132 if (strpos($left,
'-') !==
false) {
133 list($leftBound, $rightBound) = explode(
'-', $left);
134 $leftBound = self::normalizeMonthAndWeekday($leftBound, $isMonthField);
135 $rightBound = self::normalizeMonthAndWeekday($rightBound, $isMonthField);
136 $left = $leftBound .
'-' . $rightBound;
138 if ((
string)$left !==
'*') {
139 $left = self::normalizeMonthAndWeekday($left, $isMonthField);
142 $fieldArray[] = $left .
'/' . $right;
143 }
elseif (strpos($listElement,
'-') !==
false) {
144 list($left, $right) = explode(
'-', $listElement);
145 $left = self::normalizeMonthAndWeekday($left, $isMonthField);
146 $right = self::normalizeMonthAndWeekday($right, $isMonthField);
147 $fieldArray[] = $left .
'-' . $right;
149 $fieldArray[] = self::normalizeMonthAndWeekday($listElement, $isMonthField);
152 $fieldValues = implode(
',', $fieldArray);
154 return $isMonthField ? self::normalizeIntegerField($fieldValues, 1, 12) : self::normalizeIntegerField($fieldValues, 1, 7);
168 if ((
string)$expression ===
'*') {
171 $listOfCommaValues = explode(
',', $expression);
172 $fieldArray = array();
173 foreach ($listOfCommaValues as $listElement) {
174 if (strpos($listElement,
'/') !==
false) {
175 list($left, $right) = explode(
'/', $listElement);
176 if ((
string)$left ===
'*') {
177 $leftList = self::convertRangeToListOfValues($lowerBound .
'-' . $upperBound);
179 $leftList = self::convertRangeToListOfValues($left);
181 $fieldArray[] = self::reduceListOfValuesByStepValue($leftList .
'/' . $right);
182 }
elseif (strpos($listElement,
'-') !==
false) {
183 $fieldArray[] = self::convertRangeToListOfValues($listElement);
185 $fieldArray[] = $listElement;
187 throw new \InvalidArgumentException(
'Unable to normalize integer field.', 1291429389);
190 $fieldValues = implode(
',', $fieldArray);
192 if ((
string)$fieldValues ===
'') {
193 throw new \InvalidArgumentException(
'Unable to convert integer field to list of values: Result list empty.', 1291422012);
195 if ((
string)$fieldValues !==
'*') {
196 $fieldList = explode(
',', $fieldValues);
198 $fieldList = array_unique($fieldList);
199 if (current($fieldList) < $lowerBound) {
200 throw new \InvalidArgumentException(
'Lowest element in list is smaller than allowed.', 1291470084);
202 if (end($fieldList) > $upperBound) {
203 throw new \InvalidArgumentException(
'An element in the list is higher than allowed.', 1291470170);
205 $fieldValues = implode(
',', $fieldList);
207 return (
string)$fieldValues;
219 if ((
string)$range ===
'') {
220 throw new \InvalidArgumentException(
'Unable to convert range to list of values with empty string.', 1291234985);
222 $rangeArray = explode(
'-', $range);
224 foreach ($rangeArray as $fieldNumber => $fieldValue) {
226 throw new \InvalidArgumentException(
'Unable to convert value to integer.', 1291237668);
228 $rangeArray[$fieldNumber] = (int)$fieldValue;
231 $rangeArrayCount = count($rangeArray);
232 if ($rangeArrayCount === 1) {
233 $resultList = $rangeArray[0];
234 }
elseif ($rangeArrayCount === 2) {
235 $left = $rangeArray[0];
236 $right = $rangeArray[1];
237 if ($left > $right) {
238 throw new \InvalidArgumentException(
'Unable to convert range to list: Left integer must not be greater than right integer.', 1291237145);
240 $resultListArray = array();
241 for ($i = $left; $i <= $right; $i++) {
242 $resultListArray[] = $i;
244 $resultList = implode(
',', $resultListArray);
246 throw new \InvalidArgumentException(
'Unable to convert range to list of values.', 1291234986);
248 return (
string)$resultList;
263 if ($stepExpression ===
'') {
264 throw new \InvalidArgumentException(
'Unable to convert step values.', 1291234987);
266 $stepValuesAndStepArray = explode(
'/', $stepExpression);
267 $stepValuesAndStepArrayCount = count($stepValuesAndStepArray);
268 if ($stepValuesAndStepArrayCount < 1 || $stepValuesAndStepArrayCount > 2) {
269 throw new \InvalidArgumentException(
'Unable to convert step values: Multiple slashes found.', 1291242168);
271 $left = $stepValuesAndStepArray[0];
272 $right = $stepValuesAndStepArray[1];
273 if ((
string)$stepValuesAndStepArray[0] ===
'') {
274 throw new \InvalidArgumentException(
'Unable to convert step values: Left part of / is empty.', 1291414955);
276 if ((
string)$stepValuesAndStepArray[1] ===
'') {
277 throw new \InvalidArgumentException(
'Unable to convert step values: Right part of / is empty.', 1291414956);
280 throw new \InvalidArgumentException(
'Unable to convert step values: Right part must be a single integer.', 1291414957);
282 $right = (int)$right;
283 $leftArray = explode(
',', $left);
284 $validValues = array();
285 $currentStep = $right;
286 foreach ($leftArray as $leftValue) {
288 throw new \InvalidArgumentException(
'Unable to convert step values: Left part must be a single integer or comma separated list of integers.', 1291414958);
290 if ($currentStep === 0) {
291 $currentStep = $right;
293 if ($currentStep === $right) {
294 $validValues[] = (int)$leftValue;
298 if (empty($validValues)) {
299 throw new \InvalidArgumentException(
'Unable to convert step values: Result value list is empty.', 1291414959);
301 return implode(
',', $validValues);
313 $expression = $isMonth ? self::normalizeMonth($expression) : self::normalizeWeekday($expression);
314 return (
string)$expression;
327 $timestamp = strtotime(
'2010-' . $month .
'-01');
329 if (!$timestamp || $timestamp < strtotime(
'2010-01-01') || $timestamp > strtotime(
'2010-12-01')) {
330 throw new \InvalidArgumentException(
'Unable to convert given month name.', 1291083486);
332 return (
int)date(
'n', $timestamp);
345 $normalizedWeekday =
false;
347 if ((
string)$weekday ===
'0') {
350 if ($weekday >= 1 && $weekday <= 7) {
351 $normalizedWeekday = (int)$weekday;
353 if (!$normalizedWeekday) {
355 $timestamp = strtotime(
'next ' . $weekday, mktime(0, 0, 0, 1, 1, 2010));
356 if (!$timestamp || $timestamp < strtotime(
'2010-01-01') || $timestamp > strtotime(
'2010-01-08')) {
357 throw new \InvalidArgumentException(
'Unable to convert given weekday name.', 1291163589);
359 $normalizedWeekday = (int)date(
'N', $timestamp);
361 return $normalizedWeekday;