[BUGFIX] Scheduler does not run tasks from module
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Controller / SchedulerModuleController.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Fran├žois Suter <francois@typo3.org>
8 * (c) 2005 Christian Jul Jensen <julle@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Module 'TYPO3 Scheduler administration module' for the 'scheduler' extension.
29 *
30 * @author Fran├žois Suter <francois@typo3.org>
31 * @author Christian Jul Jensen <julle@typo3.org>
32 * @author Ingo Renner <ingo@typo3.org>
33 * @package TYPO3
34 * @subpackage tx_scheduler
35 */
36 class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
37
38 /**
39 * Back path to typo3 main dir
40 *
41 * @var string $backPath
42 */
43 public $backPath;
44
45 /**
46 * Array containing submitted data when editing or adding a task
47 *
48 * @var array $submittedData
49 */
50 protected $submittedData = array();
51
52 /**
53 * Array containing all messages issued by the application logic
54 * Contains the error's severity and the message itself
55 *
56 * @var array $messages
57 */
58 protected $messages = array();
59
60 /**
61 * @var string Key of the CSH file
62 */
63 protected $cshKey;
64
65 /**
66 * @var \TYPO3\CMS\Scheduler\Scheduler Local scheduler instance
67 */
68 protected $scheduler;
69
70 /**
71 * Constructor
72 *
73 * @return \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
74 */
75 public function __construct() {
76 $this->backPath = $GLOBALS['BACK_PATH'];
77 // Set key for CSH
78 $this->cshKey = '_MOD_' . $GLOBALS['MCONF']['name'];
79 }
80
81 /**
82 * Initializes the backend module
83 *
84 * @return void
85 */
86 public function init() {
87 parent::init();
88 // Initialize document
89 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
90 $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Extension\ExtensionManager::extPath('scheduler') . 'mod1/mod_template.html');
91 $this->doc->getPageRenderer()->addCssFile(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler') . 'res/tx_scheduler_be.css');
92 $this->doc->backPath = $this->backPath;
93 $this->doc->bodyTagId = 'typo3-mod-php';
94 $this->doc->bodyTagAdditions = 'class="tx_scheduler_mod1"';
95 // Create scheduler instance
96 $this->scheduler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Scheduler\\Scheduler');
97 }
98
99 /**
100 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
101 *
102 * @return void
103 */
104 public function menuConfig() {
105 $this->MOD_MENU = array(
106 'function' => array(
107 'scheduler' => $GLOBALS['LANG']->getLL('function.scheduler'),
108 'check' => $GLOBALS['LANG']->getLL('function.check'),
109 'info' => $GLOBALS['LANG']->getLL('function.info')
110 )
111 );
112 parent::menuConfig();
113 }
114
115 /**
116 * Main function of the module. Write the content to $this->content
117 *
118 * @return void
119 */
120 public function main() {
121 // Access check!
122 // The page will show only if user has admin rights
123 if ($GLOBALS['BE_USER']->user['admin']) {
124 // Set the form
125 $this->doc->form = '<form name="tx_scheduler_form" id="tx_scheduler_form" method="post" action="">';
126 // JavaScript for main function menu
127 $this->doc->JScode = '
128 <script language="javascript" type="text/javascript">
129 script_ended = 0;
130 function jumpToUrl(URL) {
131 document.location = URL;
132 }
133 </script>
134 ';
135 $this->doc->getPageRenderer()->addInlineSetting('scheduler', 'runningIcon', \TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler') . 'res/gfx/status_running.png');
136 // Prepare main content
137 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('function.' . $this->MOD_SETTINGS['function']));
138 $this->content .= $this->doc->spacer(5);
139 $this->content .= $this->getModuleContent();
140 } else {
141 // If no access, only display the module's title
142 $this->content = $this->doc->header($GLOBALS['LANG']->getLL('title'));
143 $this->content .= $this->doc->spacer(5);
144 }
145 // Place content inside template
146 $content = $this->doc->moduleBody(array(), $this->getDocHeaderButtons(), $this->getTemplateMarkers());
147 // Renders the module page
148 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $content);
149 }
150
151 /**
152 * Generate the module's content
153 *
154 * @return string HTML of the module's main content
155 */
156 protected function getModuleContent() {
157 $content = '';
158 $sectionTitle = '';
159 // Get submitted data
160 $this->submittedData = \TYPO3\CMS\Core\Utility\GeneralUtility::_GPmerged('TYPO3\\CMS\\Scheduler\\Scheduler');
161 $this->submittedData['uid'] = intval($this->submittedData['uid']);
162 // If a save command was submitted, handle saving now
163 if ($this->CMD == 'save') {
164 $previousCMD = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('previousCMD');
165 // First check the submitted data
166 $result = $this->preprocessData();
167 // If result is ok, proceed with saving
168 if ($result) {
169 $this->saveTask();
170 // Unset command, so that default screen gets displayed
171 unset($this->CMD);
172 } else {
173 $this->CMD = $previousCMD;
174 }
175 }
176 // Handle chosen action
177 switch ((string) $this->MOD_SETTINGS['function']) {
178 case 'scheduler':
179 // Scheduler's main screen
180 $this->executeTasks();
181 // Execute chosen action
182 switch ($this->CMD) {
183 case 'add':
184
185 case 'edit':
186 try {
187 // Try adding or editing
188 $content .= $this->editTask();
189 $sectionTitle = $GLOBALS['LANG']->getLL('action.' . $this->CMD);
190 } catch (\Exception $e) {
191 // An exception may happen when the task to
192 // edit could not be found. In this case revert
193 // to displaying the list of tasks
194 // It can also happen when attempting to edit a running task
195 $content .= $this->listTasks();
196 }
197 break;
198 case 'delete':
199 $this->deleteTask();
200 $content .= $this->listTasks();
201 break;
202 case 'stop':
203 $this->stopTask();
204 $content .= $this->listTasks();
205 break;
206 case 'list':
207
208 default:
209 $content .= $this->listTasks();
210 break;
211 }
212 break;
213 case 'check':
214 // Setup check screen
215 // TODO: move check to the report module
216 $content .= $this->displayCheckScreen();
217 break;
218 case 'info':
219 // Information screen
220 $content .= $this->displayInfoScreen();
221 break;
222 }
223 // Wrap the content in a section
224 return $this->doc->section($sectionTitle, '<div class="tx_scheduler_mod1">' . $content . '</div>', 0, 1);
225 }
226
227 /**
228 * This method actually prints out the module's HTML content
229 *
230 * @return void
231 */
232 public function render() {
233 echo $this->content;
234 }
235
236 /**
237 * This method checks the status of the '_cli_scheduler' user
238 * It will differentiate between a non-existing user and an existing,
239 * but disabled user (as per enable fields)
240 *
241 * @return integer -1 if user doesn't exist
242 */
243 protected function checkSchedulerUser() {
244 $schedulerUserStatus = -1;
245 // Assemble base WHERE clause
246 $where = 'username = \'_cli_scheduler\' AND admin = 0' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('be_users');
247 // Check if user exists at all
248 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('1', 'be_users', $where);
249 if ($GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
250 $schedulerUserStatus = 0;
251 // Check if user exists and is enabled
252 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('1', 'be_users', $where . \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('be_users'));
253 if ($GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
254 $schedulerUserStatus = 1;
255 }
256 }
257 $GLOBALS['TYPO3_DB']->sql_free_result($res);
258 return $schedulerUserStatus;
259 }
260
261 /**
262 * This method creates the "cli_scheduler" BE user if it doesn't exist
263 *
264 * @return void
265 */
266 protected function createSchedulerUser() {
267 // Check _cli_scheduler user status
268 $checkUser = $this->checkSchedulerUser();
269 // Prepare default message
270 $message = $GLOBALS['LANG']->getLL('msg.userExists');
271 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
272 // If the user does not exist, try creating it
273 if ($checkUser == -1) {
274 // Prepare necessary data for _cli_scheduler user creation
275 $password = md5(uniqid('scheduler', TRUE));
276 $data = array('be_users' => array('NEW' => array('username' => '_cli_scheduler', 'password' => $password, 'pid' => 0)));
277 /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $tcemain */
278 $tcemain = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
279 $tcemain->stripslashes_values = 0;
280 $tcemain->start($data, array());
281 $tcemain->process_datamap();
282 // Check if a new uid was indeed generated (i.e. a new record was created)
283 // (counting TCEmain errors doesn't work as some failures don't report errors)
284 $numberOfNewIDs = count($tcemain->substNEWwithIDs);
285 if ($numberOfNewIDs == 1) {
286 $message = $GLOBALS['LANG']->getLL('msg.userCreated');
287 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
288 } else {
289 $message = $GLOBALS['LANG']->getLL('msg.userNotCreated');
290 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
291 }
292 }
293 $this->addMessage($message, $severity);
294 }
295
296 /**
297 * This method displays the result of a number of checks
298 * on whether the Scheduler is ready to run or running properly
299 *
300 * @return string Further information
301 */
302 protected function displayCheckScreen() {
303 $message = '';
304 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
305 // First, check if _cli_scheduler user creation was requested
306 if ($this->CMD == 'user') {
307 $this->createSchedulerUser();
308 }
309 // Start generating the content
310 $content = $GLOBALS['LANG']->getLL('msg.schedulerSetupCheck');
311 // Display information about last automated run, as stored in the system registry
312 /** @var \TYPO3\CMS\Core\Registry $registry */
313 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
314 $lastRun = $registry->get('TYPO3\\CMS\\Scheduler\\Scheduler', 'lastRun');
315 if (!is_array($lastRun)) {
316 $message = $GLOBALS['LANG']->getLL('msg.noLastRun');
317 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
318 } else {
319 if (empty($lastRun['end']) || empty($lastRun['start']) || empty($lastRun['type'])) {
320 $message = $GLOBALS['LANG']->getLL('msg.incompleteLastRun');
321 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
322 } else {
323 $startDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['start']);
324 $startTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['start']);
325 $endDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['end']);
326 $endTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['end']);
327 $label = 'automatically';
328 if ($lastRun['type'] == 'manual') {
329 $label = 'manually';
330 }
331 $type = $GLOBALS['LANG']->getLL('label.' . $label);
332 $message = sprintf($GLOBALS['LANG']->getLL('msg.lastRun'), $type, $startDate, $startTime, $endDate, $endTime);
333 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::INFO;
334 }
335 }
336 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
337 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
338 $content .= '<div class="info-block">';
339 $content .= '<h3>' . $GLOBALS['LANG']->getLL('hdg.lastRun') . '</h3>';
340 $content .= $flashMessage->render();
341 $content .= '</div>';
342 // Check CLI user
343 $content .= '<div class="info-block">';
344 $content .= '<h3>' . $GLOBALS['LANG']->getLL('hdg.schedulerUser') . '</h3>';
345 $content .= '<p>' . $GLOBALS['LANG']->getLL('msg.schedulerUser') . '</p>';
346 $checkUser = $this->checkSchedulerUser();
347 if ($checkUser == -1) {
348 $link = $GLOBALS['MCONF']['_'] . '&SET[function]=check&CMD=user';
349 $message = sprintf($GLOBALS['LANG']->getLL('msg.schedulerUserMissing'), htmlspecialchars($link));
350 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
351 } elseif ($checkUser == 0) {
352 $message = $GLOBALS['LANG']->getLL('msg.schedulerUserFoundButDisabled');
353 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING;
354 } else {
355 $message = $GLOBALS['LANG']->getLL('msg.schedulerUserFound');
356 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
357 }
358 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
359 $content .= $flashMessage->render() . '</div>';
360 // Check if CLI script is executable or not
361 $script = PATH_typo3 . 'cli_dispatch.phpsh';
362 $isExecutable = FALSE;
363 // Skip this check if running Windows, as rights do not work the same way on this platform
364 // (i.e. the script will always appear as *not* executable)
365 if (TYPO3_OS === 'WIN') {
366 $isExecutable = TRUE;
367 } else {
368 $isExecutable = is_executable($script);
369 }
370 $content .= '<div class="info-block">';
371 $content .= '<h3>' . $GLOBALS['LANG']->getLL('hdg.cliScript') . '</h3>';
372 $content .= '<p>' . sprintf($GLOBALS['LANG']->getLL('msg.cliScript'), $script) . '</p>';
373 if ($isExecutable) {
374 $message = $GLOBALS['LANG']->getLL('msg.cliScriptExecutable');
375 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK;
376 } else {
377 $message = $GLOBALS['LANG']->getLL('msg.cliScriptNotExecutable');
378 $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR;
379 }
380 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
381 $content .= $flashMessage->render() . '</div>';
382 return $content;
383 }
384
385 /**
386 * This method gathers information about all available task classes and displays it
387 *
388 * @return string HTML content to display
389 */
390 protected function displayInfoScreen() {
391 $content = '';
392 $registeredClasses = self::getRegisteredClasses();
393 // No classes available, display information message
394 if (count($registeredClasses) == 0) {
395 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
396 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('msg.noTasksDefined'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
397 $content .= $flashMessage->render();
398 } else {
399 // Initialise table layout
400 $tableLayout = array(
401 'table' => array('<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">', '</table>'),
402 '0' => array(
403 'tr' => array('<tr class="t3-row-header" valign="top">', '</tr>'),
404 'defCol' => array('<td>', '</td>')
405 ),
406 'defRow' => array(
407 'tr' => array('<tr class="db_list_normal">', '</tr>'),
408 'defCol' => array('<td>', '</td>')
409 )
410 );
411 $table = array();
412 $tr = 0;
413 // Header row
414 $table[$tr][] = $GLOBALS['LANG']->getLL('label.name');
415 $table[$tr][] = $GLOBALS['LANG']->getLL('label.extension');
416 $table[$tr][] = $GLOBALS['LANG']->getLL('label.description');
417 $table[$tr][] = '';
418 $tr++;
419 // Display information about each service
420 foreach ($registeredClasses as $class => $classInfo) {
421 $table[$tr][] = $classInfo['title'];
422 $table[$tr][] = $classInfo['extension'];
423 $table[$tr][] = $classInfo['description'];
424 $link = $GLOBALS['MCONF']['_'] . '&SET[function]=list&CMD=add&tx_scheduler[class]=' . $class;
425 $table[$tr][] = '<a href="' . htmlspecialchars($link) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:new', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-new') . '</a>';
426 $tr++;
427 }
428 // Render the table and return it
429 $content = '<div>' . $GLOBALS['LANG']->getLL('msg.infoScreenIntro') . '</div>';
430 $content .= $this->doc->spacer(5);
431 $content .= $this->doc->table($table, $tableLayout);
432 }
433 return $content;
434 }
435
436 /**
437 * Display the current server's time along with a help text about server time
438 * usage in the Scheduler
439 *
440 * @return string HTML to display
441 */
442 protected function displayServerTime() {
443 // Get the current time, formatted
444 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' T (e';
445 $now = date($dateFormat) . ', GMT ' . date('P') . ')';
446 // Display the help text
447 $serverTime = '<h4>' . $GLOBALS['LANG']->getLL('label.serverTime') . '</h4>';
448 $serverTime .= '<p>' . $GLOBALS['LANG']->getLL('msg.serverTimeHelp') . '</p>';
449 $serverTime .= '<p>' . sprintf($GLOBALS['LANG']->getLL('msg.serverTime'), $now) . '</p>';
450 return $serverTime;
451 }
452
453 /**
454 * Renders the task progress bar.
455 *
456 * @param float $progress Task progress
457 * @return string Progress bar markup
458 */
459 protected function renderTaskProgressBar($progress) {
460 $progressText .= $GLOBALS['LANG']->getLL('status.progress') . ':&nbsp;' . $progress . '%';
461 $progressBar = '<div class="progress"> <div class="bar" style="width: ' . $progress . '%;">' . $progressText . '</div> </div>';
462 return $progressBar;
463 }
464
465 /**
466 * Delete a task from the execution queue
467 *
468 * @return void
469 */
470 protected function deleteTask() {
471 try {
472 // Try to fetch the task and delete it
473 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
474 // If the task is currently running, it may not be deleted
475 if ($task->isExecutionRunning()) {
476 $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotDeleteRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
477 } else {
478 if ($this->scheduler->removeTask($task)) {
479 $GLOBALS['BE_USER']->writeLog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was deleted', array($task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()));
480 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteSuccess'));
481 } else {
482 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
483 }
484 }
485 } catch (\UnexpectedValueException $e) {
486 // The task could not be unserialized properly, simply delete the database record
487 $result = $GLOBALS['TYPO3_DB']->exec_DELETEquery('TYPO3\\CMS\\Scheduler\\Scheduler_task', 'uid = ' . intval($this->submittedData['uid']));
488 if ($result) {
489 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteSuccess'));
490 } else {
491 $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
492 }
493 } catch (\OutOfBoundsException $e) {
494 // The task was not found, for some reason
495 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
496 }
497 }
498
499 /**
500 * Clears the registered running executions from the task
501 * Note that this doesn't actually stop the running script. It just unmarks
502 * all executions.
503 * TODO: find a way to really kill the running task
504 *
505 * @return void
506 */
507 protected function stopTask() {
508 try {
509 // Try to fetch the task and stop it
510 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
511 if ($task->isExecutionRunning()) {
512 // If the task is indeed currently running, clear marked executions
513 $result = $task->unmarkAllExecutions();
514 if ($result) {
515 $this->addMessage($GLOBALS['LANG']->getLL('msg.stopSuccess'));
516 } else {
517 $this->addMessage($GLOBALS['LANG']->getLL('msg.stopError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
518 }
519 } else {
520 // The task is not running, nothing to unmark
521 $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotStopNonRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
522 }
523 } catch (\Exception $e) {
524 // The task was not found, for some reason
525 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
526 }
527 }
528
529 /**
530 * Return a form to add a new task or edit an existing one
531 *
532 * @return string HTML form to add or edit a task
533 */
534 protected function editTask() {
535 $registeredClasses = self::getRegisteredClasses();
536 $content = '';
537 $taskInfo = array();
538 $task = NULL;
539 $process = 'edit';
540 if ($this->submittedData['uid'] > 0) {
541 // If editing, retrieve data for existing task
542 try {
543 $taskRecord = $this->scheduler->fetchTaskRecord($this->submittedData['uid']);
544 // If there's a registered execution, the task should not be edited
545 if (!empty($taskRecord['serialized_executions'])) {
546 $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotEditRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
547 throw new \LogicException('Runnings tasks cannot not be edited', 1251232849);
548 }
549 // Get the task object
550 /** @var $task \TYPO3\CMS\Scheduler\Task */
551 $task = unserialize($taskRecord['serialized_task_object']);
552 // Set some task information
553 $class = $taskRecord['classname'];
554 $taskInfo['disable'] = $taskRecord['disable'];
555 // Check that the task object is valid
556 if ($this->scheduler->isValidTaskObject($task)) {
557 // The task object is valid, process with fetching current data
558 $taskInfo['class'] = $class;
559 // Get execution information
560 $taskInfo['start'] = $task->getExecution()->getStart();
561 $taskInfo['end'] = $task->getExecution()->getEnd();
562 $taskInfo['interval'] = $task->getExecution()->getInterval();
563 $taskInfo['croncmd'] = $task->getExecution()->getCronCmd();
564 $taskInfo['multiple'] = $task->getExecution()->getMultiple();
565 if (!empty($taskInfo['interval']) || !empty($taskInfo['croncmd'])) {
566 // Guess task type from the existing information
567 // If an interval or a cron command is defined, it's a recurring task
568 // FIXME: remove magic numbers for the type, use class constants instead
569 $taskInfo['type'] = 2;
570 $taskInfo['frequency'] = empty($taskInfo['interval']) ? $taskInfo['croncmd'] : $taskInfo['interval'];
571 } else {
572 // It's not a recurring task
573 // Make sure interval and cron command are both empty
574 $taskInfo['type'] = 1;
575 $taskInfo['frequency'] = '';
576 $taskInfo['end'] = 0;
577 }
578 } else {
579 // The task object is not valid
580 // Issue error message
581 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.invalidTaskClassEdit'), $class), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
582 // Initialize empty values
583 $taskInfo['start'] = 0;
584 $taskInfo['end'] = 0;
585 $taskInfo['frequency'] = '';
586 $taskInfo['multiple'] = FALSE;
587 $taskInfo['type'] = 1;
588 }
589 } catch (\OutOfBoundsException $e) {
590 // Add a message and continue throwing the exception
591 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
592 throw $e;
593 }
594 } else {
595 // If adding a new object, set some default values
596 $taskInfo['class'] = key($registeredClasses);
597 $taskInfo['type'] = 2;
598 $taskInfo['start'] = $GLOBALS['EXEC_TIME'];
599 $taskInfo['end'] = '';
600 $taskInfo['frequency'] = '';
601 $taskInfo['multiple'] = 0;
602 $process = 'add';
603 }
604 if (count($this->submittedData) > 0) {
605 // If some data was already submitted, use it to override
606 // existing data
607 $taskInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($taskInfo, $this->submittedData);
608 }
609 // Get the extra fields to display for each task that needs some
610 $allAdditionalFields = array();
611 if ($process == 'add') {
612 foreach ($registeredClasses as $class => $registrationInfo) {
613 if (!empty($registrationInfo['provider'])) {
614 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
615 $providerObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($registrationInfo['provider']);
616 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
617 $additionalFields = $providerObject->getAdditionalFields($taskInfo, NULL, $this);
618 $allAdditionalFields = array_merge($allAdditionalFields, array($class => $additionalFields));
619 }
620 }
621 }
622 } else {
623 if (!empty($registeredClasses[$taskInfo['class']]['provider'])) {
624 $providerObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($registeredClasses[$taskInfo['class']]['provider']);
625 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
626 $allAdditionalFields[$taskInfo['class']] = $providerObject->getAdditionalFields($taskInfo, $task, $this);
627 }
628 }
629 }
630 // Load necessary JavaScript
631 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
632 $pageRenderer = $this->doc->getPageRenderer();
633 $pageRenderer->loadExtJS();
634 $pageRenderer->addJsFile(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler') . 'res/tx_scheduler_be.js');
635 $pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/tceforms.js');
636 $pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/Ext.ux.DateTimePicker.js');
637 // Define settings for Date Picker
638 $typo3Settings = array(
639 'datePickerUSmode' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? 1 : 0,
640 'dateFormat' => array('j-n-Y', 'G:i j-n-Y'),
641 'dateFormatUS' => array('n-j-Y', 'G:i n-j-Y')
642 );
643 $pageRenderer->addInlineSettingArray('', $typo3Settings);
644 // Define table layout for add/edit form
645 $tableLayout = array(
646 'table' => array('<table border="0" cellspacing="0" cellpadding="0" id="edit_form" class="typo3-usersettings">', '</table>')
647 );
648 // Define a style for hiding
649 // Some fields will be hidden when the task is not recurring
650 $style = '';
651 if ($taskInfo['type'] == 1) {
652 $style = ' style="display: none"';
653 }
654 // Start rendering the add/edit form
655 $content .= '<input type="hidden" name="tx_scheduler[uid]" value="' . $this->submittedData['uid'] . '" />';
656 $content .= '<input type="hidden" name="previousCMD" value="' . $this->CMD . '" />';
657 $content .= '<input type="hidden" name="CMD" value="save" />';
658 $table = array();
659 $tr = 0;
660 $defaultCell = array('<td class="td-input">', '</td>');
661 // Disable checkbox
662 $label = '<label for="task_disable">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:disable') . '</label>';
663 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_disable', $label);
664 $table[$tr][] = '<input type="hidden" name="tx_scheduler[disable]" value="0" />
665 <input type="checkbox" name="tx_scheduler[disable]" value="1" id="task_disable"' . ($taskInfo['disable'] == 1 ? ' checked="checked"' : '') . ' />';
666 $tableLayout[$tr] = array(
667 'tr' => array('<tr id="task_disable_row">', '</tr>'),
668 'defCol' => $defaultCell,
669 '0' => array('<td class="td-label">', '</td>')
670 );
671 $tr++;
672 // Task class selector
673 $label = '<label for="task_class">' . $GLOBALS['LANG']->getLL('label.class') . '</label>';
674 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_class', $label);
675 // On editing, don't allow changing of the task class, unless it was not valid
676 if ($this->submittedData['uid'] > 0 && !empty($taskInfo['class'])) {
677 $cell = $registeredClasses[$taskInfo['class']]['title'] . ' (' . $registeredClasses[$taskInfo['class']]['extension'] . ')';
678 $cell .= '<input type="hidden" name="tx_scheduler[class]" id="task_class" value="' . $taskInfo['class'] . '" />';
679 } else {
680 $cell = '<select name="tx_scheduler[class]" id="task_class" class="wide" onchange="actOnChangedTaskClass(this)">';
681 // Group registered classes by classname
682 $groupedClasses = array();
683 foreach ($registeredClasses as $class => $classInfo) {
684 $groupedClasses[$classInfo['extension']][$class] = $classInfo;
685 }
686 ksort($groupedClasses);
687 // Loop on all grouped classes to display a selector
688 foreach ($groupedClasses as $extension => $class) {
689 $cell .= '<optgroup label="' . $extension . '">';
690 foreach ($groupedClasses[$extension] as $class => $classInfo) {
691 $selected = $class == $taskInfo['class'] ? ' selected="selected"' : '';
692 $cell .= '<option value="' . $class . '"' . 'title="' . $classInfo['description'] . '"' . $selected . '>' . $classInfo['title'] . '</option>';
693 }
694 $cell .= '</optgroup>';
695 }
696 $cell .= '</select>';
697 }
698 $table[$tr][] = $cell;
699 // Make sure each row has a unique id, for manipulation with JS
700 $tableLayout[$tr] = array(
701 'tr' => array('<tr id="task_class_row">', '</tr>'),
702 'defCol' => $defaultCell,
703 '0' => array('<td class="td-label">', '</td>')
704 );
705 $tr++;
706 // Task type selector
707 $label = '<label for="task_type">' . $GLOBALS['LANG']->getLL('label.type') . '</label>';
708 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_type', $label);
709 $table[$tr][] = '<select name="tx_scheduler[type]" id="task_type" onchange="actOnChangedTaskType(this)">' . '<option value="1"' . ($taskInfo['type'] == 1 ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->getLL('label.type.single') . '</option>' . '<option value="2"' . ($taskInfo['type'] == 2 ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->getLL('label.type.recurring') . '</option>' . '</select>';
710 $tableLayout[$tr] = array(
711 'tr' => array('<tr id="task_type_row">', '</tr>'),
712 'defCol' => $defaultCell,
713 '0' => array('<td class="td-label">', '</td>')
714 );
715 $tr++;
716 // Start date/time field
717 // NOTE: datetime fields need a special id naming scheme
718 $label = '<label for="tceforms-datetimefield-task_start">' . $GLOBALS['LANG']->getLL('label.start') . '</label>';
719 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_start', $label);
720 $table[$tr][] = '<input name="tx_scheduler[start]" type="text" id="tceforms-datetimefield-task_start" value="' . (empty($taskInfo['start']) ? '' : strftime('%H:%M %d-%m-%Y', $taskInfo['start'])) . '" />' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-pick-date', array(
721 'style' => 'cursor:pointer;',
722 'id' => 'picker-tceforms-datetimefield-task_start'
723 ));
724 $tableLayout[$tr] = array(
725 'tr' => array('<tr id="task_start_row">', '</tr>'),
726 'defCol' => $defaultCell,
727 '0' => array('<td class="td-label">', '</td>')
728 );
729 $tr++;
730 // End date/time field
731 // NOTE: datetime fields need a special id naming scheme
732 $label = '<label for="tceforms-datetimefield-task_end">' . $GLOBALS['LANG']->getLL('label.end') . '</label>';
733 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_end', $label);
734 $table[$tr][] = '<input name="tx_scheduler[end]" type="text" id="tceforms-datetimefield-task_end" value="' . (empty($taskInfo['end']) ? '' : strftime('%H:%M %d-%m-%Y', $taskInfo['end'])) . '" />' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-pick-date', array(
735 'style' => 'cursor:pointer;',
736 'id' => 'picker-tceforms-datetimefield-task_end'
737 ));
738 $tableLayout[$tr] = array(
739 'tr' => array('<tr id="task_end_row"' . $style . '>', '</tr>'),
740 'defCol' => $defaultCell,
741 '0' => array('<td class="td-label">', '</td>')
742 );
743 $tr++;
744 // Frequency input field
745 $label = '<label for="task_frequency">' . $GLOBALS['LANG']->getLL('label.frequency.long') . '</label>';
746 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_frequency', $label);
747 $cell = '<input type="text" name="tx_scheduler[frequency]" id="task_frequency" value="' . htmlspecialchars($taskInfo['frequency']) . '" />';
748 $table[$tr][] = $cell;
749 $tableLayout[$tr] = array(
750 'tr' => array('<tr id="task_frequency_row"' . $style . '>', '</tr>'),
751 'defCol' => $defaultCell,
752 '0' => array('<td class="td-label">', '</td>')
753 );
754 $tr++;
755 // Multiple execution selector
756 $label = '<label for="task_multiple">' . $GLOBALS['LANG']->getLL('label.parallel.long') . '</label>';
757 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($this->cshKey, 'task_multiple', $label);
758 $table[$tr][] = '<input type="hidden" name="tx_scheduler[multiple]" value="0" />
759 <input type="checkbox" name="tx_scheduler[multiple]" value="1" id="task_multiple"' . ($taskInfo['multiple'] == 1 ? ' checked="checked"' : '') . ' />';
760 $tableLayout[$tr] = array(
761 'tr' => array('<tr id="task_multiple_row"' . $style . '>', '</tr>'),
762 'defCol' => $defaultCell,
763 '0' => array('<td class="td-label">', '</td>')
764 );
765 $tr++;
766 // Display additional fields
767 foreach ($allAdditionalFields as $class => $fields) {
768 if ($class == $taskInfo['class']) {
769 $additionalFieldsStyle = '';
770 } else {
771 $additionalFieldsStyle = ' style="display: none"';
772 }
773 // Add each field to the display, if there are indeed any
774 if (isset($fields) && is_array($fields)) {
775 foreach ($fields as $fieldID => $fieldInfo) {
776 $label = '<label for="' . $fieldID . '">' . $GLOBALS['LANG']->sL($fieldInfo['label']) . '</label>';
777 $table[$tr][] = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($fieldInfo['cshKey'], $fieldInfo['cshLabel'], $label);
778 $table[$tr][] = $fieldInfo['code'];
779 $tableLayout[$tr] = array(
780 'tr' => array('<tr id="' . $fieldID . '_row"' . $additionalFieldsStyle . ' class="extraFields extra_fields_' . $class . '">', '</tr>'),
781 'defCol' => $defaultCell,
782 '0' => array('<td class="td-label">', '</td>')
783 );
784 $tr++;
785 }
786 }
787 }
788 // Render the add/edit task form
789 $content .= '<div style="float: left;"><div class="typo3-dyntabmenu-divs">';
790 $content .= $this->doc->table($table, $tableLayout);
791 $content .= '</div></div>';
792 $content .= '<div style="padding-top: 20px; clear: both;"></div>';
793 // Display information about server time usage
794 $content .= $this->displayServerTime();
795 return $content;
796 }
797
798 /**
799 * Execute all selected tasks
800 *
801 * @return void
802 */
803 protected function executeTasks() {
804 // Make sure next automatic scheduler-run is scheduled
805 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('go') !== NULL) {
806 $this->scheduler->scheduleNextSchedulerRunUsingAtDaemon();
807 }
808 // Continue if some elements have been chosen for execution
809 if (isset($this->submittedData['execute']) && count($this->submittedData['execute']) > 0) {
810 // Get list of registered classes
811 $registeredClasses = self::getRegisteredClasses();
812 // Loop on all selected tasks
813 foreach ($this->submittedData['execute'] as $uid) {
814 try {
815 // Try fetching the task
816 $task = $this->scheduler->fetchTask($uid);
817 $class = get_class($task);
818 $name = $registeredClasses[$class]['title'] . ' (' . $registeredClasses[$class]['extension'] . ')';
819 // Now try to execute it and report on outcome
820 try {
821 $result = $this->scheduler->executeTask($task);
822 if ($result) {
823 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executed'), $name));
824 } else {
825 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.notExecuted'), $name), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
826 }
827 } catch (\Exception $e) {
828 // An exception was thrown, display its message as an error
829 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executionFailed'), $name, $e->getMessage()), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
830 }
831 } catch (\OutOfBoundsException $e) {
832 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $uid), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
833 } catch (\UnexpectedValueException $e) {
834 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executionFailed'), $name, $e->getMessage()), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
835 }
836 }
837 // Record the run in the system registry
838 $this->scheduler->recordLastRun('manual');
839 // Make sure to switch to list view after execution
840 $this->CMD = 'list';
841 }
842 }
843
844 /**
845 * Assemble display of list of scheduled tasks
846 *
847 * @return string Table of pending tasks
848 */
849 protected function listTasks() {
850 // Define display format for dates
851 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
852 $content = '';
853 // Get list of registered classes
854 $registeredClasses = self::getRegisteredClasses();
855 // Get all registered tasks
856 $query = array(
857 'SELECT' => '*',
858 'FROM' => 'tx_scheduler_task',
859 'WHERE' => '1=1',
860 'ORDERBY' => 'nextexecution'
861 );
862 $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($query);
863 $numRows = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
864 // No tasks defined, display information message
865 if ($numRows == 0) {
866 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
867 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('msg.noTasks'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
868 $content .= $flashMessage->render();
869 } else {
870 // Load ExtJS framework and specific JS library
871 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
872 $pageRenderer = $this->doc->getPageRenderer();
873 $pageRenderer->loadExtJS();
874 $pageRenderer->addJsFile(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler') . 'res/tx_scheduler_be.js');
875 // Initialise table layout
876 $tableLayout = array(
877 'table' => array(
878 '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">',
879 '</table>'
880 ),
881 '0' => array(
882 'tr' => array('<tr class="t3-row-header">', '</tr>'),
883 'defCol' => array('<td>', '</td>'),
884 '1' => array('<td style="width: 36px;">', '</td>'),
885 '3' => array('<td colspan="2">', '</td>')
886 ),
887 'defRow' => array(
888 'tr' => array('<tr class="db_list_normal">', '</tr>'),
889 'defCol' => array('<td>', '</td>'),
890 '1' => array('<td class="right">', '</td>'),
891 '2' => array('<td class="right">', '</td>')
892 )
893 );
894 $disabledTaskRow = array(
895 'tr' => array('<tr class="db_list_normal disabled">', '</tr>'),
896 'defCol' => array('<td>', '</td>'),
897 '1' => array('<td class="right">', '</td>'),
898 '2' => array('<td class="right">', '</td>')
899 );
900 $rowWithSpan = array(
901 'tr' => array('<tr class="db_list_normal">', '</tr>'),
902 'defCol' => array('<td>', '</td>'),
903 '1' => array('<td class="right">', '</td>'),
904 '2' => array('<td class="right">', '</td>'),
905 '3' => array('<td colspan="6">', '</td>')
906 );
907 $table = array();
908 $tr = 0;
909 // Header row
910 $table[$tr][] = '<a href="#" onclick="toggleCheckboxes();" title="' . $GLOBALS['LANG']->getLL('label.checkAll', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-select') . '</a>';
911 $table[$tr][] = '&nbsp;';
912 $table[$tr][] = $GLOBALS['LANG']->getLL('label.id');
913 $table[$tr][] = $GLOBALS['LANG']->getLL('task');
914 $table[$tr][] = $GLOBALS['LANG']->getLL('label.type');
915 $table[$tr][] = $GLOBALS['LANG']->getLL('label.frequency');
916 $table[$tr][] = $GLOBALS['LANG']->getLL('label.parallel');
917 $table[$tr][] = $GLOBALS['LANG']->getLL('label.lastExecution');
918 $table[$tr][] = $GLOBALS['LANG']->getLL('label.nextExecution');
919 $tr++;
920 // Loop on all tasks
921 while ($schedulerRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
922 // Define action icons
923 $editAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=edit&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:edit', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
924 $deleteAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=delete&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('msg.delete') . '\');" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:delete', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
925 $stopAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=stop&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('msg.stop') . '\');" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:stop', TRUE) . '" class="icon"><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, (\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler') . '/res/gfx/stop.png')) . ' alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:stop') . '" /></a>';
926 // Define some default values
927 $lastExecution = '-';
928 $isRunning = FALSE;
929 $executionStatus = 'scheduled';
930 $executionStatusOutput = '';
931 $name = '';
932 $nextDate = '-';
933 $execType = '-';
934 $frequency = '-';
935 $multiple = '-';
936 $startExecutionElement = '&nbsp;';
937 // Restore the serialized task and pass it a reference to the scheduler object
938 /** @var $task \TYPO3\CMS\Scheduler\Task */
939 $task = unserialize($schedulerRecord['serialized_task_object']);
940 // Assemble information about last execution
941 $context = '';
942 if (!empty($schedulerRecord['lastexecution_time'])) {
943 $lastExecution = date($dateFormat, $schedulerRecord['lastexecution_time']);
944 if ($schedulerRecord['lastexecution_context'] == 'CLI') {
945 $context = $GLOBALS['LANG']->getLL('label.cron');
946 } else {
947 $context = $GLOBALS['LANG']->getLL('label.manual');
948 }
949 $lastExecution .= ' (' . $context . ')';
950 }
951 if ($this->scheduler->isValidTaskObject($task)) {
952 // The task object is valid
953 $name = htmlspecialchars($registeredClasses[$schedulerRecord['classname']]['title'] . ' (' . $registeredClasses[$schedulerRecord['classname']]['extension'] . ')');
954 $name .= '<br /> ';
955 $additionalInformation = $task->getAdditionalInformation();
956 if ($task instanceof \TYPO3\CMS\Scheduler\ProgressProviderInterface) {
957 $progress = round(floatval($task->getProgress()), 2);
958 $name .= $this->renderTaskProgressBar($progress);
959 }
960 if (!empty($additionalInformation)) {
961 $name .= '[' . htmlspecialchars($additionalInformation) . ']';
962 }
963 // Check if task currently has a running execution
964 if (!empty($schedulerRecord['serialized_executions'])) {
965 $isRunning = TRUE;
966 $executionStatus = 'running';
967 }
968 // Prepare display of next execution date
969 // If task is currently running, date is not displayed (as next hasn't been calculated yet)
970 // Also hide the date if task is disabled (the information doesn't make sense, as it will not run anyway)
971 if ($isRunning || $schedulerRecord['disable'] == 1) {
972 $nextDate = '-';
973 } else {
974 $nextDate = date($dateFormat, $schedulerRecord['nextexecution']);
975 if (empty($schedulerRecord['nextexecution'])) {
976 $nextDate = $GLOBALS['LANG']->getLL('none');
977 } elseif ($schedulerRecord['nextexecution'] < $GLOBALS['EXEC_TIME']) {
978 // Next execution is overdue, highlight date
979 $nextDate = '<span class="late" title="' . $GLOBALS['LANG']->getLL('status.legend.scheduled') . '">' . $nextDate . '</span>';
980 $executionStatus = 'late';
981 }
982 }
983 // Get execution type
984 if ($task->getExecution()->getInterval() == 0 && $task->getExecution()->getCronCmd() == '') {
985 $execType = $GLOBALS['LANG']->getLL('label.type.single');
986 $frequency = '-';
987 } else {
988 $execType = $GLOBALS['LANG']->getLL('label.type.recurring');
989 if ($task->getExecution()->getCronCmd() == '') {
990 $frequency = $task->getExecution()->getInterval();
991 } else {
992 $frequency = $task->getExecution()->getCronCmd();
993 }
994 }
995 // Get multiple executions setting
996 if ($task->getExecution()->getMultiple()) {
997 $multiple = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
998 } else {
999 $multiple = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
1000 }
1001 // Define checkbox
1002 $startExecutionElement = '<input type="checkbox" name="TYPO3\\CMS\\Scheduler\\Scheduler[execute][]" value="' . $schedulerRecord['uid'] . '" id="task_' . $schedulerRecord['uid'] . '" class="checkboxes" />';
1003 // Show no action links (edit, delete) if task is running
1004 $actions = $editAction . $deleteAction;
1005 if ($isRunning) {
1006 $actions = $stopAction;
1007 }
1008 // Check the disable status
1009 // Row is shown dimmed if task is disabled, unless it is still running
1010 if ($schedulerRecord['disable'] == 1 && !$isRunning) {
1011 $tableLayout[$tr] = $disabledTaskRow;
1012 $executionStatus = 'disabled';
1013 }
1014 // Check if the last run failed
1015 $failureOutput = '';
1016 if (!empty($schedulerRecord['lastexecution_failure'])) {
1017 // Try to get the stored exception object
1018 /** @var $exception Exception */
1019 $exception = unserialize($schedulerRecord['lastexecution_failure']);
1020 // If the exception could not be unserialized, issue a default error message
1021 if ($exception === FALSE || $exception instanceof \__PHP_Incomplete_Class) {
1022 $failureDetail = $GLOBALS['LANG']->getLL('msg.executionFailureDefault');
1023 } else {
1024 $failureDetail = sprintf($GLOBALS['LANG']->getLL('msg.executionFailureReport'), $exception->getCode(), $exception->getMessage());
1025 }
1026 $failureOutput = ' <img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), 'res/gfx/status_failure.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" title="' . htmlspecialchars($failureDetail) . '" />';
1027 }
1028 // Format the execution status,
1029 // including failure feedback, if any
1030 $executionStatusOutput = '<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), ('res/gfx/status_' . $executionStatus . '.png')) . ' id="executionstatus_' . $schedulerRecord['uid'] . '" alt="' . htmlspecialchars($GLOBALS['LANG']->getLL(('status.' . $executionStatus))) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL(('status.legend.' . $executionStatus))) . '" />' . $failureOutput;
1031 $table[$tr][] = $startExecutionElement;
1032 $table[$tr][] = $actions;
1033 $table[$tr][] = $schedulerRecord['uid'];
1034 $table[$tr][] = $executionStatusOutput;
1035 $table[$tr][] = $name;
1036 $table[$tr][] = $execType;
1037 $table[$tr][] = $frequency;
1038 $table[$tr][] = $multiple;
1039 $table[$tr][] = $lastExecution;
1040 $table[$tr][] = $nextDate;
1041 } else {
1042 // The task object is not valid
1043 // Prepare to issue an error
1044 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
1045 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('msg.invalidTaskClass'), $schedulerRecord['classname']), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1046 $executionStatusOutput = $flashMessage->render();
1047 $tableLayout[$tr] = $rowWithSpan;
1048 $table[$tr][] = $startExecutionElement;
1049 $table[$tr][] = $deleteAction;
1050 $table[$tr][] = $schedulerRecord['uid'];
1051 $table[$tr][] = $executionStatusOutput;
1052 }
1053 $tr++;
1054 }
1055 // Render table
1056 $content .= $this->doc->table($table, $tableLayout);
1057 $content .= '<input type="submit" class="button" name="go" id="scheduler_executeselected" value="' . $GLOBALS['LANG']->getLL('label.executeSelected') . '" />';
1058 }
1059 if (!count($registeredClasses) > 0) {
1060 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
1061 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('msg.noTasksDefined'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
1062 $content .= $flashMessage->render();
1063 }
1064 // Display legend, if there's at least one registered task
1065 // Also display information about the usage of server time
1066 if ($numRows > 0) {
1067 $content .= $this->doc->spacer(20);
1068 $content .= '<h4>' . $GLOBALS['LANG']->getLL('status.legend') . '</h4>
1069 <ul>
1070 <li><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), 'res/gfx/status_failure.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.failure')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.failure') . '</li>
1071 <li><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), 'res/gfx/status_late.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.late')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.late')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.late') . '</li>
1072 <li><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), 'res/gfx/status_running.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.running')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.running')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.running') . '</li>
1073 <li><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), 'res/gfx/status_scheduled.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.scheduled')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.scheduled')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.scheduled') . '</li>
1074 <li><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(\TYPO3\CMS\Core\Extension\ExtensionManager::extRelPath('scheduler'), 'res/gfx/status_disabled.png') . ' alt="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.disabled')) . '" title="' . htmlspecialchars($GLOBALS['LANG']->getLL('status.disabled')) . '" /> ' . $GLOBALS['LANG']->getLL('status.legend.disabled') . '</li>
1075 </ul>';
1076 $content .= $this->doc->spacer(10);
1077 $content .= $this->displayServerTime();
1078 }
1079 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1080 return $content;
1081 }
1082
1083 /**
1084 * Saves a task specified in the backend form to the database
1085 *
1086 * @return void
1087 */
1088 protected function saveTask() {
1089 // If a task is being edited fetch old task data
1090 if (!empty($this->submittedData['uid'])) {
1091 try {
1092 $taskRecord = $this->scheduler->fetchTaskRecord($this->submittedData['uid']);
1093 /** @var \TYPO3\CMS\Scheduler\Task $task */
1094 $task = unserialize($taskRecord['serialized_task_object']);
1095 } catch (\OutOfBoundsException $e) {
1096 // If the task could not be fetched, issue an error message
1097 // and exit early
1098 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1099 return;
1100 }
1101 // Register single execution
1102 if ($this->submittedData['type'] == 1) {
1103 $task->registerSingleExecution($this->submittedData['start']);
1104 } else {
1105 if (!empty($this->submittedData['croncmd'])) {
1106 // Definition by cron-like syntax
1107 $interval = 0;
1108 $cronCmd = $this->submittedData['croncmd'];
1109 } else {
1110 // Definition by interval
1111 $interval = $this->submittedData['interval'];
1112 $cronCmd = '';
1113 }
1114 // Register recurring execution
1115 $task->registerRecurringExecution($this->submittedData['start'], $interval, $this->submittedData['end'], $this->submittedData['multiple'], $cronCmd);
1116 }
1117 // Set disable flag
1118 $task->setDisabled($this->submittedData['disable']);
1119 // Save additional input values
1120 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1121 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1122 $providerObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1123 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1124 $providerObject->saveAdditionalFields($this->submittedData, $task);
1125 }
1126 }
1127 // Save to database
1128 $result = $this->scheduler->saveTask($task);
1129 if ($result) {
1130 $GLOBALS['BE_USER']->writeLog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was updated', array($task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()));
1131 $this->addMessage($GLOBALS['LANG']->getLL('msg.updateSuccess'));
1132 } else {
1133 $this->addMessage($GLOBALS['LANG']->getLL('msg.updateError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1134 }
1135 } else {
1136 // A new task is being created
1137 // Create an instance of chosen class
1138 $task = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($this->submittedData['class']);
1139 if ($this->submittedData['type'] == 1) {
1140 // Set up single execution
1141 $task->registerSingleExecution($this->submittedData['start']);
1142 } else {
1143 // Set up recurring execution
1144 $task->registerRecurringExecution($this->submittedData['start'], $this->submittedData['interval'], $this->submittedData['end'], $this->submittedData['multiple'], $this->submittedData['croncmd']);
1145 }
1146 // Save additional input values
1147 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1148 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1149 $providerObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1150 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1151 $providerObject->saveAdditionalFields($this->submittedData, $task);
1152 }
1153 }
1154 // Set disable flag
1155 $task->setDisabled($this->submittedData['disable']);
1156 // Add to database
1157 $result = $this->scheduler->addTask($task);
1158 if ($result) {
1159 $GLOBALS['BE_USER']->writeLog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was added', array($task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()));
1160 $this->addMessage($GLOBALS['LANG']->getLL('msg.addSuccess'));
1161 } else {
1162 $this->addMessage($GLOBALS['LANG']->getLL('msg.addError'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1163 }
1164 }
1165 }
1166
1167 /*************************
1168 *
1169 * INPUT PROCESSING UTILITIES
1170 *
1171 *************************/
1172 /**
1173 * Checks the submitted data and performs some pre-processing on it
1174 *
1175 * @return boolean TRUE if everything was ok, FALSE otherwise
1176 */
1177 protected function preprocessData() {
1178 $result = TRUE;
1179 // Validate id
1180 $this->submittedData['uid'] = empty($this->submittedData['uid']) ? 0 : intval($this->submittedData['uid']);
1181 // Validate selected task class
1182 if (!class_exists($this->submittedData['class'])) {
1183 $this->addMessage($GLOBALS['LANG']->getLL('msg.noTaskClassFound'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1184 }
1185 // Check start date
1186 if (empty($this->submittedData['start'])) {
1187 $this->addMessage($GLOBALS['LANG']->getLL('msg.noStartDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1188 $result = FALSE;
1189 } else {
1190 try {
1191 $timestamp = $this->checkDate($this->submittedData['start']);
1192 $this->submittedData['start'] = $timestamp;
1193 } catch (\Exception $e) {
1194 $this->addMessage($GLOBALS['LANG']->getLL('msg.invalidStartDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1195 $result = FALSE;
1196 }
1197 }
1198 // Check end date, if recurring task
1199 if ($this->submittedData['type'] == 2 && !empty($this->submittedData['end'])) {
1200 try {
1201 $timestamp = $this->checkDate($this->submittedData['end']);
1202 $this->submittedData['end'] = $timestamp;
1203 if ($this->submittedData['end'] < $this->submittedData['start']) {
1204 $this->addMessage($GLOBALS['LANG']->getLL('msg.endDateSmallerThanStartDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1205 $result = FALSE;
1206 }
1207 } catch (\Exception $e) {
1208 $this->addMessage($GLOBALS['LANG']->getLL('msg.invalidEndDate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1209 $result = FALSE;
1210 }
1211 }
1212 // Set default values for interval and cron command
1213 $this->submittedData['interval'] = 0;
1214 $this->submittedData['croncmd'] = '';
1215 // Check type and validity of frequency, if recurring
1216 if ($this->submittedData['type'] == 2) {
1217 $frequency = trim($this->submittedData['frequency']);
1218 if (empty($frequency)) {
1219 // Empty frequency, not valid
1220 $this->addMessage($GLOBALS['LANG']->getLL('msg.noFrequency'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1221 $result = FALSE;
1222 } else {
1223 $cronErrorCode = 0;
1224 $cronErrorMessage = '';
1225 // Try interpreting the cron command
1226 try {
1227 \TYPO3\CMS\Scheduler\CronCommand\NormalizeCommand::normalize($frequency);
1228 $this->submittedData['croncmd'] = $frequency;
1229 } catch (\Exception $e) {
1230 // Store the exception's result
1231 $cronErrorMessage = $e->getMessage();
1232 $cronErrorCode = $e->getCode();
1233 // Check if the frequency is a valid number
1234 // If yes, assume it is a frequency in seconds, and unset cron error code
1235 if (is_numeric($frequency)) {
1236 $this->submittedData['interval'] = intval($frequency);
1237 unset($cronErrorCode);
1238 }
1239 }
1240 // If there's a cron error code, issue validation error message
1241 if (!empty($cronErrorCode)) {
1242 $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.frequencyError'), $cronErrorMessage, $cronErrorCode), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
1243 $result = FALSE;
1244 }
1245 }
1246 }
1247 // Validate additional input fields
1248 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1249 $providerObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1250 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1251 // The validate method will return TRUE if all went well, but that must not
1252 // override previous FALSE values => AND the returned value with the existing one
1253 $result &= $providerObject->validateAdditionalFields($this->submittedData, $this);
1254 }
1255 }
1256 return $result;
1257 }
1258
1259 /**
1260 * This method checks whether the given string can be considered a valid date or not
1261 * Allowed values are anything that matches natural language (see PHP function strtotime())
1262 * or TYPO3's date syntax: HH:ii yyyy-mm-dd
1263 * If the string is a valid date, the corresponding timestamp is returned.
1264 * Otherwise an exception is thrown
1265 *
1266 * @param string $string String to check
1267 * @return integer Unix timestamp
1268 * @throws \InvalidArgumentException
1269 */
1270 public function checkDate($string) {
1271 // Try with strtotime
1272 $timestamp = strtotime($string);
1273 // That failed. Try TYPO3's standard date/time input format
1274 if ($timestamp === FALSE) {
1275 // Split time and date
1276 $dateParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $string, TRUE);
1277 // Proceed if there are indeed two parts
1278 // Extract each component of date and time
1279 if (count($dateParts) == 2) {
1280 list($time, $date) = $dateParts;
1281 list($hour, $minutes) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $time, TRUE);
1282 list($day, $month, $year) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('-', $date, TRUE);
1283 // Get a timestamp from all these parts
1284 $timestamp = @mktime($hour, $minutes, 0, $month, $day, $year);
1285 }
1286 // If the timestamp is still FALSE, throw an exception
1287 if ($timestamp === FALSE) {
1288 throw new \InvalidArgumentException('"' . $string . '" seems not to be a correct date.', 1294587694);
1289 }
1290 }
1291 return $timestamp;
1292 }
1293
1294 /*************************
1295 *
1296 * APPLICATION LOGIC UTILITIES
1297 *
1298 *************************/
1299 /**
1300 * This method is used to add a message to the internal queue
1301 *
1302 * @param string $message The message itself
1303 * @param integer $severity Message level (according to t3lib_FlashMessage class constants)
1304 * @return void
1305 */
1306 public function addMessage($message, $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK) {
1307 $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, '', $severity);
1308 \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
1309 }
1310
1311 /**
1312 * This method a list of all classes that have been registered with the Scheduler
1313 * For each item the following information is provided, as an associative array:
1314 *
1315 * ['extension'] => Key of the extension which provides the class
1316 * ['filename'] => Path to the file containing the class
1317 * ['title'] => String (possibly localized) containing a human-readable name for the class
1318 * ['provider'] => Name of class that implements the interface for additional fields, if necessary
1319 *
1320 * The name of the class itself is used as the key of the list array
1321 *
1322 * @return array List of registered classes
1323 */
1324 static protected function getRegisteredClasses() {
1325 $list = array();
1326 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'])) {
1327 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'] as $class => $registrationInformation) {
1328 $title = isset($registrationInformation['title']) ? $GLOBALS['LANG']->sL($registrationInformation['title']) : '';
1329 $description = isset($registrationInformation['description']) ? $GLOBALS['LANG']->sL($registrationInformation['description']) : '';
1330 $list[$class] = array(
1331 'extension' => $registrationInformation['extension'],
1332 'title' => $title,
1333 'description' => $description,
1334 'provider' => isset($registrationInformation['additionalFields']) ? $registrationInformation['additionalFields'] : ''
1335 );
1336 }
1337 }
1338 return $list;
1339 }
1340
1341 /*************************
1342 *
1343 * RENDERING UTILITIES
1344 *
1345 *************************/
1346 /**
1347 * Gets the filled markers that are used in the HTML template.
1348 *
1349 * @return array The filled marker array
1350 */
1351 protected function getTemplateMarkers() {
1352 $markers = array(
1353 'CSH' => \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('_MOD_tools_txschedulerM1', ''),
1354 'FUNC_MENU' => $this->getFunctionMenu(),
1355 'CONTENT' => $this->content,
1356 'TITLE' => $GLOBALS['LANG']->getLL('title')
1357 );
1358 return $markers;
1359 }
1360
1361 /**
1362 * Gets the function menu selector for this backend module.
1363 *
1364 * @return string The HTML representation of the function menu selector
1365 */
1366 protected function getFunctionMenu() {
1367 $functionMenu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
1368 return $functionMenu;
1369 }
1370
1371 /**
1372 * Gets the buttons that shall be rendered in the docHeader.
1373 *
1374 * @return array Available buttons for the docHeader
1375 */
1376 protected function getDocHeaderButtons() {
1377 $buttons = array(
1378 'addtask' => '',
1379 'close' => '',
1380 'save' => '',
1381 'reload' => '',
1382 'shortcut' => $this->getShortcutButton()
1383 );
1384 if (empty($this->CMD) || $this->CMD == 'list' || $this->CMD == 'delete') {
1385 $buttons['reload'] = '<a href="' . $GLOBALS['MCONF']['_'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.reload', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
1386 if ($this->MOD_SETTINGS['function'] === 'scheduler' && count(self::getRegisteredClasses())) {
1387 $link = $GLOBALS['MCONF']['_'] . '&CMD=add';
1388 $image = '<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, 'gfx/new_el.gif') . ' alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:new', TRUE) . '" />';
1389 $buttons['addtask'] = '<a href="' . htmlspecialchars($link) . '" ' . 'title="' . $GLOBALS['LANG']->getLL('action.add') . '">' . $image . '</a>';
1390 }
1391 }
1392 if ($this->CMD === 'add' || $this->CMD === 'edit') {
1393 $buttons['close'] = '<a href="#" onclick="document.location=\'' . $GLOBALS['MCONF']['_'] . '\'" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:cancel', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-close') . '</a>';
1394 $buttons['save'] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-save-close', array('html' => '<input type="image" name="data[save]" class="c-inputButton" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:saveAndClose', TRUE) . '" />'));
1395 }
1396 return $buttons;
1397 }
1398
1399 /**
1400 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
1401 *
1402 * @return string HTML representation of the shortcut button
1403 */
1404 protected function getShortcutButton() {
1405 $result = '';
1406 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
1407 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
1408 }
1409 return $result;
1410 }
1411
1412 }
1413
1414
1415 ?>