[TASK] Remove @package and @subpackage annotations
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / cli / scheduler_cli_dispatch.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Markus Friedrich (markus.friedrich@dkd.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Starts all due tasks, used by the command line interface
26 * This script must be included by the "CLI module dispatcher"
27 *
28 * @author Markus Friedrich <markus.friedrich@dkd.de>
29 */
30 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI && basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
31 $hasTask = TRUE;
32 // Create an instance of the scheduler object
33 /** @var $scheduler \TYPO3\CMS\Scheduler\Scheduler */
34 $scheduler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Scheduler\\Scheduler');
35 /** @var \TYPO3\CMS\Core\Controller\CommandLineController $cli */
36 $cli = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Controller\\CommandLineController');
37 // If a specific id is given in arguments, then run that task. Otherwise run scheduled tasks.
38 if ($cli->cli_isArg('-i')) {
39 $taskId = intval($cli->cli_argValue('-i'));
40 if ($taskId > 0) {
41 // Force the execution of the task even if it is disabled or no execution scheduled
42 if ($cli->cli_isArg('-f')) {
43 $task = $scheduler->fetchTask($taskId);
44 } else {
45 $whereClause = 'uid = ' . $taskId . ' AND nextexecution != 0 AND nextexecution <= ' . $GLOBALS['EXEC_TIME'];
46 list($task) = $scheduler->fetchTasksWithCondition($whereClause);
47 }
48 if ($scheduler->isValidTaskObject($task)) {
49 try {
50 $scheduler->executeTask($task);
51 } catch (\Exception $e) {
52
53 }
54 // Record the run in the system registry
55 $scheduler->recordLastRun('cli-by-id');
56 }
57 }
58 } else {
59 // Loop as long as there are tasks
60 do {
61 // Try getting the next task and execute it
62 // If there are no more tasks to execute, an exception is thrown by tx_scheduler::fetchTask()
63 try {
64 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask */
65 $task = $scheduler->fetchTask();
66 $hasTask = TRUE;
67 try {
68 $scheduler->executeTask($task);
69 } catch (\Exception $e) {
70 // We ignore any exception that may have been thrown during execution,
71 // as this is a background process.
72 // The exception message has been recorded to the database anyway
73 continue;
74 }
75 } catch (\OutOfBoundsException $e) {
76 $hasTask = FALSE;
77 } catch (\UnexpectedValueException $e) {
78 continue;
79 }
80 } while ($hasTask);
81 // Record the run in the system registry
82 $scheduler->recordLastRun();
83 }
84 } else {
85 die('This script must be included by the "CLI module dispatcher"');
86 }
87 ?>