‪TYPO3CMS  9.5
Execution.php
Go to the documentation of this file.
1 <?php
2 namespace ‪TYPO3\CMS\Scheduler;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 {
28  protected ‪$start;
29 
35  protected ‪$end;
36 
42  protected ‪$interval;
43 
49  protected ‪$multiple = false;
50 
56  protected ‪$cronCmd;
57 
65  protected ‪$isNewSingleExecution = false;
66 
67  /**********************************
68  * Setters and getters
69  **********************************/
75  public function ‪setStart(‪$start)
76  {
77  $this->start = ‪$start;
78  }
79 
85  public function ‪getStart()
86  {
87  return ‪$this->start;
88  }
89 
95  public function ‪setEnd(‪$end)
96  {
97  $this->end = ‪$end;
98  }
99 
105  public function ‪getEnd()
106  {
107  return ‪$this->end;
108  }
109 
115  public function ‪setInterval(‪$interval)
116  {
117  $this->interval = ‪$interval;
118  }
119 
125  public function ‪getInterval()
126  {
127  return ‪$this->interval;
128  }
129 
135  public function ‪setMultiple(‪$multiple)
136  {
137  $this->multiple = ‪$multiple;
138  }
139 
145  public function ‪getMultiple()
146  {
147  return ‪$this->multiple;
148  }
149 
155  public function ‪setCronCmd($cmd)
156  {
157  $this->cronCmd = $cmd;
158  }
159 
165  public function ‪getCronCmd()
166  {
167  return ‪$this->cronCmd;
168  }
169 
183  {
184  $this->isNewSingleExecution = ‪$isNewSingleExecution;
185  }
186 
192  public function ‪getIsNewSingleExecution()
193  {
195  }
196 
197  /**********************************
198  * Execution calculations and logic
199  **********************************/
206  public function ‪getNextExecution()
207  {
208  if ($this->‪getIsNewSingleExecution()) {
209  $this->‪setIsNewSingleExecution(false);
210  return ‪$this->start;
211  }
212  if (!$this->‪isEnded()) {
213  // If the schedule has not yet run out, find out the next date
214  if (!$this->‪isStarted()) {
215  // If the schedule hasn't started yet, next date is start date
216  $date = ‪$this->start;
217  } else {
218  // If the schedule has already started, calculate next date
219  if ($this->cronCmd) {
220  // If it uses cron-like syntax, calculate next date
221  $date = $this->‪getNextCronExecution();
222  } elseif ($this->interval == 0) {
223  // If not and there's no interval either, it's a singe execution: use start date
224  $date = ‪$this->start;
225  } else {
226  // Otherwise calculate date based on interval
227  $now = time();
228  $date = $now + $this->interval - ($now - ‪$this->start) % $this->interval;
229  }
230  // If date is in the future, throw an exception
231  if (!empty($this->end) && $date > ‪$this->end) {
232  throw new \OutOfBoundsException('Next execution date is past end date.', 1250715528);
233  }
234  }
235  } else {
236  // The event has ended, throw an exception
237  throw new \OutOfBoundsException('Task is past end date.', 1250715544);
238  }
239  return $date;
240  }
241 
247  public function ‪getNextCronExecution()
248  {
250  ‪$cronCmd = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Scheduler\CronCommand\CronCommand::class, $this->‪getCronCmd());
251  ‪$cronCmd->calculateNextValue();
252  return ‪$cronCmd->getTimestamp();
253  }
254 
260  public function ‪isStarted()
261  {
262  return $this->start < time();
263  }
264 
270  public function ‪isEnded()
271  {
272  if (empty($this->end)) {
273  // If no end is defined, the schedule never ends
274  $result = false;
275  } else {
276  // Otherwise check if end is in the past
277  $result = $this->end < time();
278  }
279  return $result;
280  }
281 }
‪TYPO3\CMS\Scheduler
Definition: AbstractAdditionalFieldProvider.php:3
‪TYPO3\CMS\Scheduler\Execution\$multiple
‪bool $multiple
Definition: Execution.php:45
‪TYPO3\CMS\Scheduler\Execution\setStart
‪setStart($start)
Definition: Execution.php:69
‪TYPO3\CMS\Scheduler\Execution\isEnded
‪bool isEnded()
Definition: Execution.php:264
‪TYPO3\CMS\Scheduler\Execution\setCronCmd
‪setCronCmd($cmd)
Definition: Execution.php:149
‪TYPO3
‪TYPO3\CMS\Scheduler\Execution\setIsNewSingleExecution
‪setIsNewSingleExecution($isNewSingleExecution)
Definition: Execution.php:176
‪TYPO3\CMS\Scheduler\Execution\getIsNewSingleExecution
‪bool getIsNewSingleExecution()
Definition: Execution.php:186
‪TYPO3\CMS\Scheduler\Execution\getInterval
‪int getInterval()
Definition: Execution.php:119
‪TYPO3\CMS\Scheduler\Execution\$cronCmd
‪string $cronCmd
Definition: Execution.php:51
‪TYPO3\CMS\Scheduler\Execution\$start
‪int $start
Definition: Execution.php:27
‪TYPO3\CMS\Scheduler\Execution\$interval
‪int $interval
Definition: Execution.php:39
‪TYPO3\CMS\Scheduler\Execution\getNextCronExecution
‪int getNextCronExecution()
Definition: Execution.php:241
‪TYPO3\CMS\Scheduler\Execution
Definition: Execution.php:22
‪TYPO3\CMS\Scheduler\Execution\getCronCmd
‪string getCronCmd()
Definition: Execution.php:159
‪TYPO3\CMS\Scheduler\Execution\getEnd
‪int getEnd()
Definition: Execution.php:99
‪TYPO3\CMS\Scheduler\Scheduler
Definition: Scheduler.php:33
‪TYPO3\CMS\Scheduler\Execution\setInterval
‪setInterval($interval)
Definition: Execution.php:109
‪TYPO3\CMS\Scheduler\Execution\getNextExecution
‪int getNextExecution()
Definition: Execution.php:200
‪TYPO3\CMS\Scheduler\Execution\getStart
‪int getStart()
Definition: Execution.php:79
‪TYPO3\CMS\Scheduler\Execution\setEnd
‪setEnd($end)
Definition: Execution.php:89
‪TYPO3\CMS\Scheduler\Execution\$isNewSingleExecution
‪bool $isNewSingleExecution
Definition: Execution.php:59
‪TYPO3\CMS\Scheduler\Execution\$end
‪int $end
Definition: Execution.php:33
‪TYPO3\CMS\Scheduler\Execution\getMultiple
‪bool getMultiple()
Definition: Execution.php:139
‪TYPO3\CMS\Scheduler\Execution\isStarted
‪bool isStarted()
Definition: Execution.php:254
‪TYPO3\CMS\Scheduler\Execution\setMultiple
‪setMultiple($multiple)
Definition: Execution.php:129