Follow-up to #12132: New exception was not caught nor handled properly everywhere
[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 /**
26 * Starts all due tasks, used by the command line interface
27 * This script must be included by the "CLI module dispatcher"
28 *
29 * @author Markus Friedrich <markus.friedrich@dkd.de>
30 * @package TYPO3
31 * @subpackage tx_scheduler
32 *
33 * $Id: scheduler_cli_dispatch.php 1261 2009-09-15 20:22:45Z francois $
34 */
35 if (defined('TYPO3_cliMode') && TYPO3_cliMode && basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
36 $hasTask = true;
37 // Create an instance of the scheduler object
38 /**
39 * @var tx_scheduler
40 */
41 $scheduler = t3lib_div::makeInstance('tx_scheduler');
42 // Loop as long as there are tasks
43 do {
44 // Try getting the next task and execute it
45 // If there are no more tasks to execute, an exception is thrown by tx_scheduler::fetchTask()
46 try {
47 /**
48 * @var tx_scheduler_Task
49 */
50 $task = $scheduler->fetchTask();
51 $hasTask = true;
52 try {
53 $scheduler->executeTask($task);
54 }
55 catch (Exception $e) {
56 // We ignore any exception that may have been thrown during execution,
57 // as this is a background process.
58 // The exception message has been recorded to the database anyway
59 continue;
60 }
61 }
62 // There are no more tasks, quit the run
63 catch (OutOfBoundsException $e) {
64 $hasTask = false;
65 }
66 // A task could not be unserialized properly, skip to next task
67 catch (UnexpectedValueException $e) {
68 continue;
69 }
70 } while ($hasTask);
71 // Record the run in the system registry
72 $scheduler->recordLastRun();
73 } else {
74 die('This script must be included by the "CLI module dispatcher"');
75 }
76
77 ?>