TYPO3 CMS  TYPO3_6-2
Execution.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Scheduler;
3 
23 class Execution {
24 
30  protected $start;
31 
37  protected $end;
38 
44  protected $interval;
45 
51  protected $multiple = FALSE;
52 
58  protected $cronCmd;
59 
67  protected $isNewSingleExecution = FALSE;
68 
69  /**********************************
70  * Setters and getters
71  **********************************/
78  public function setStart($start) {
79  $this->start = $start;
80  }
81 
87  public function getStart() {
88  return $this->start;
89  }
90 
97  public function setEnd($end) {
98  $this->end = $end;
99  }
100 
106  public function getEnd() {
107  return $this->end;
108  }
109 
116  public function setInterval($interval) {
117  $this->interval = $interval;
118  }
119 
125  public function getInterval() {
126  return $this->interval;
127  }
128 
135  public function setMultiple($multiple) {
136  $this->multiple = $multiple;
137  }
138 
144  public function getMultiple() {
145  return $this->multiple;
146  }
147 
154  public function setCronCmd($cmd) {
155  $this->cronCmd = $cmd;
156  }
157 
163  public function getCronCmd() {
164  return $this->cronCmd;
165  }
166 
181  $this->isNewSingleExecution = $isNewSingleExecution;
182  }
183 
189  public function getIsNewSingleExecution() {
191  }
192 
193  /**********************************
194  * Execution calculations and logic
195  **********************************/
202  public function getNextExecution() {
203  if ($this->getIsNewSingleExecution()) {
204  $this->setIsNewSingleExecution(FALSE);
205  return $this->start;
206  }
207  if (!$this->isEnded()) {
208  // If the schedule has not yet run out, find out the next date
209  if (!$this->isStarted()) {
210  // If the schedule hasn't started yet, next date is start date
211  $date = $this->start;
212  } else {
213  // If the schedule has already started, calculate next date
214  if ($this->cronCmd) {
215  // If it uses cron-like syntax, calculate next date
216  $date = $this->getNextCronExecution();
217  } elseif ($this->interval == 0) {
218  // If not and there's no interval either, it's a singe execution: use start date
219  $date = $this->start;
220  } else {
221  // Otherwise calculate date based on interval
222  $now = time();
223  $date = $now + $this->interval - ($now - $this->start) % $this->interval;
224  }
225  // If date is in the future, throw an exception
226  if (!empty($this->end) && $date > $this->end) {
227  throw new \OutOfBoundsException('Next execution date is past end date.', 1250715528);
228  }
229  }
230  } else {
231  // The event has ended, throw an exception
232  throw new \OutOfBoundsException('Task is past end date.', 1250715544);
233  }
234  return $date;
235  }
236 
242  public function getNextCronExecution() {
244  $cronCmd = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Scheduler\\CronCommand\\CronCommand', $this->getCronCmd());
245  $cronCmd->calculateNextValue();
246  return $cronCmd->getTimestamp();
247  }
248 
254  public function isStarted() {
255  return $this->start < time();
256  }
257 
263  public function isEnded() {
264  if (empty($this->end)) {
265  // If no end is defined, the schedule never ends
266  $result = FALSE;
267  } else {
268  // Otherwise check if end is in the past
269  $result = $this->end < time();
270  }
271  return $result;
272  }
273 
274 }
setIsNewSingleExecution($isNewSingleExecution)
Definition: Execution.php:180
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.