[FEATURE] EXT:Scheduler: Implemented folding of scheduler task groups
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Controller / SchedulerModuleController.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Controller;
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
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20 use TYPO3\CMS\Backend\Template\ModuleTemplate;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Database\ConnectionPool;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Imaging\IconFactory;
25 use TYPO3\CMS\Core\Messaging\FlashMessage;
26 use TYPO3\CMS\Core\Page\PageRenderer;
27 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
30 use TYPO3\CMS\Scheduler\Task\AbstractTask;
31
32 /**
33 * Module 'TYPO3 Scheduler administration module' for the 'scheduler' extension.
34 */
35 class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass
36 {
37 /**
38 * Array containing submitted data when editing or adding a task
39 *
40 * @var array
41 */
42 protected $submittedData = [];
43
44 /**
45 * Array containing all messages issued by the application logic
46 * Contains the error's severity and the message itself
47 *
48 * @var array
49 */
50 protected $messages = [];
51
52 /**
53 * @var string Key of the CSH file
54 */
55 protected $cshKey;
56
57 /**
58 * @var \TYPO3\CMS\Scheduler\Scheduler Local scheduler instance
59 */
60 protected $scheduler;
61
62 /**
63 * @var string
64 */
65 protected $backendTemplatePath = '';
66
67 /**
68 * @var \TYPO3\CMS\Fluid\View\StandaloneView
69 */
70 protected $view;
71
72 /**
73 * The name of the module
74 *
75 * @var string
76 */
77 protected $moduleName = 'system_txschedulerM1';
78
79 /**
80 * @var string Base URI of scheduler module
81 */
82 protected $moduleUri;
83
84 /**
85 * ModuleTemplate Container
86 *
87 * @var ModuleTemplate
88 */
89 protected $moduleTemplate;
90
91 /**
92 * @return \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
93 */
94 public function __construct()
95 {
96 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
97 $this->getLanguageService()->includeLLFile('EXT:scheduler/Resources/Private/Language/locallang.xlf');
98 $this->MCONF = [
99 'name' => $this->moduleName,
100 ];
101 $this->cshKey = '_MOD_' . $this->moduleName;
102 $this->backendTemplatePath = ExtensionManagementUtility::extPath('scheduler') . 'Resources/Private/Templates/Backend/SchedulerModule/';
103 $this->view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
104 $this->view->getRequest()->setControllerExtensionName('scheduler');
105 $this->view->setPartialRootPaths([ExtensionManagementUtility::extPath('scheduler') . 'Resources/Private/Partials/Backend/SchedulerModule/']);
106 $this->moduleUri = BackendUtility::getModuleUrl($this->moduleName);
107
108 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
109 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
110 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/SplitButtons');
111 }
112
113 /**
114 * Initializes the backend module
115 *
116 * @return void
117 */
118 public function init()
119 {
120 parent::init();
121
122 // Create scheduler instance
123 $this->scheduler = GeneralUtility::makeInstance(\TYPO3\CMS\Scheduler\Scheduler::class);
124 }
125
126 /**
127 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
128 *
129 * @return void
130 */
131 public function menuConfig()
132 {
133 $this->MOD_MENU = [
134 'function' => [
135 'scheduler' => $this->getLanguageService()->getLL('function.scheduler'),
136 'check' => $this->getLanguageService()->getLL('function.check'),
137 'info' => $this->getLanguageService()->getLL('function.info')
138 ]
139 ];
140 parent::menuConfig();
141 }
142
143 /**
144 * Main function of the module. Write the content to $this->content
145 *
146 * @return void
147 */
148 public function main()
149 {
150 // Access check!
151 // The page will show only if user has admin rights
152 if ($this->getBackendUser()->isAdmin()) {
153 // Set the form
154 $this->content = '<form name="tx_scheduler_form" id="tx_scheduler_form" method="post" action="">';
155
156 // Prepare main content
157 $this->content .= '<h1>' . $this->getLanguageService()->getLL('function.' . $this->MOD_SETTINGS['function']) . '</h1>';
158 $this->content .= $this->getModuleContent();
159 $this->content .= '</form>';
160 } else {
161 // If no access, only display the module's title
162 $this->content = '<h1>' . $this->getLanguageService()->getLL('title.') . '</h1>';
163 $this->content .='<div style="padding-top: 5px;"></div>';
164 }
165 $this->getButtons();
166 $this->getModuleMenu();
167 }
168
169 /**
170 * Generates the action menu
171 */
172 protected function getModuleMenu()
173 {
174 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
175 $menu->setIdentifier('SchedulerJumpMenu');
176
177 foreach ($this->MOD_MENU['function'] as $controller => $title) {
178 $item = $menu
179 ->makeMenuItem()
180 ->setHref(
181 BackendUtility::getModuleUrl(
182 $this->moduleName,
183 [
184 'id' => $this->id,
185 'SET' => [
186 'function' => $controller
187 ]
188 ]
189 )
190 )
191 ->setTitle($title);
192 if ($controller === $this->MOD_SETTINGS['function']) {
193 $item->setActive(true);
194 }
195 $menu->addMenuItem($item);
196 }
197 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
198 }
199
200 /**
201 * Generate the module's content
202 *
203 * @return string HTML of the module's main content
204 */
205 protected function getModuleContent()
206 {
207 $content = '';
208 $sectionTitle = '';
209 // Get submitted data
210 $this->submittedData = GeneralUtility::_GPmerged('tx_scheduler');
211 $this->submittedData['uid'] = (int)$this->submittedData['uid'];
212 // If a save command was submitted, handle saving now
213 if ($this->CMD === 'save' || $this->CMD === 'saveclose' || $this->CMD === 'savenew') {
214 $previousCMD = GeneralUtility::_GP('previousCMD');
215 // First check the submitted data
216 $result = $this->preprocessData();
217 // If result is ok, proceed with saving
218 if ($result) {
219 $this->saveTask();
220 if ($this->CMD === 'saveclose') {
221 // Unset command, so that default screen gets displayed
222 unset($this->CMD);
223 } elseif ($this->CMD === 'save') {
224 // After saving a "add form", return to edit
225 $this->CMD = 'edit';
226 } elseif ($this->CMD === 'savenew') {
227 // Unset submitted data, so that empty form gets displayed
228 unset($this->submittedData);
229 // After saving a "add/edit form", return to add
230 $this->CMD = 'add';
231 } else {
232 // Return to edit form
233 $this->CMD = $previousCMD;
234 }
235 } else {
236 $this->CMD = $previousCMD;
237 }
238 }
239
240 // Handle chosen action
241 switch ((string)$this->MOD_SETTINGS['function']) {
242 case 'scheduler':
243 $this->executeTasks();
244
245 switch ($this->CMD) {
246 case 'add':
247 case 'edit':
248 try {
249 // Try adding or editing
250 $content .= $this->editTaskAction();
251 $sectionTitle = $this->getLanguageService()->getLL('action.' . $this->CMD);
252 } catch (\Exception $e) {
253 if ($e->getCode() === 1305100019) {
254 // Invalid controller class name exception
255 $this->addMessage($e->getMessage(), FlashMessage::ERROR);
256 }
257 // An exception may also happen when the task to
258 // edit could not be found. In this case revert
259 // to displaying the list of tasks
260 // It can also happen when attempting to edit a running task
261 $content .= $this->listTasksAction();
262 }
263 break;
264 case 'delete':
265 $this->deleteTask();
266 $content .= $this->listTasksAction();
267 break;
268 case 'stop':
269 $this->stopTask();
270 $content .= $this->listTasksAction();
271 break;
272 case 'toggleHidden':
273 $this->toggleDisableAction();
274 $content .= $this->listTasksAction();
275 break;
276 case 'setNextExecutionTime':
277 $this->setNextExecutionTimeAction();
278 $content .= $this->listTasksAction();
279 break;
280 case 'list':
281
282 default:
283 $content .= $this->listTasksAction();
284 }
285 break;
286
287 // Setup check screen
288 case 'check':
289 // @todo move check to the report module
290 $content .= $this->checkScreenAction();
291 break;
292
293 // Information screen
294 case 'info':
295 $content .= $this->infoScreenAction();
296 break;
297 }
298 // Wrap the content
299 return '<h2>' . $sectionTitle . '</h2><div class="tx_scheduler_mod1">' . $content . '</div>';
300 }
301
302 /**
303 * Injects the request object for the current request or subrequest
304 * Simply calls main() and init() and outputs the content
305 *
306 * @param ServerRequestInterface $request the current request
307 * @param ResponseInterface $response
308 * @return ResponseInterface the response with the content
309 */
310 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
311 {
312 $GLOBALS['SOBE'] = $this;
313 $this->init();
314 $this->main();
315
316 $this->moduleTemplate->setContent($this->content);
317 $response->getBody()->write($this->moduleTemplate->renderContent());
318 return $response;
319 }
320
321 /**
322 * This method displays the result of a number of checks
323 * on whether the Scheduler is ready to run or running properly
324 *
325 * @return string Further information
326 */
327 protected function checkScreenAction()
328 {
329 $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'CheckScreen.html');
330
331 // Display information about last automated run, as stored in the system registry
332 /** @var $registry \TYPO3\CMS\Core\Registry */
333 $registry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
334 $lastRun = $registry->get('tx_scheduler', 'lastRun');
335 if (!is_array($lastRun)) {
336 $message = $this->getLanguageService()->getLL('msg.noLastRun');
337 $severity = InfoboxViewHelper::STATE_WARNING;
338 } else {
339 if (empty($lastRun['end']) || empty($lastRun['start']) || empty($lastRun['type'])) {
340 $message = $this->getLanguageService()->getLL('msg.incompleteLastRun');
341 $severity = InfoboxViewHelper::STATE_WARNING;
342 } else {
343 $startDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['start']);
344 $startTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['start']);
345 $endDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['end']);
346 $endTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['end']);
347 $label = 'automatically';
348 if ($lastRun['type'] === 'manual') {
349 $label = 'manually';
350 }
351 $type = $this->getLanguageService()->getLL('label.' . $label);
352 $message = sprintf($this->getLanguageService()->getLL('msg.lastRun'), $type, $startDate, $startTime, $endDate, $endTime);
353 $severity = InfoboxViewHelper::STATE_INFO;
354 }
355 }
356 $this->view->assign('lastRunMessage', $message);
357 $this->view->assign('lastRunSeverity', $severity);
358
359 // Check if CLI script is executable or not
360 $script = PATH_typo3 . 'cli_dispatch.phpsh';
361 $this->view->assign('script', $script);
362
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 if ($isExecutable) {
371 $message = $this->getLanguageService()->getLL('msg.cliScriptExecutable');
372 $severity = InfoboxViewHelper::STATE_OK;
373 } else {
374 $message = $this->getLanguageService()->getLL('msg.cliScriptNotExecutable');
375 $severity = InfoboxViewHelper::STATE_ERROR;
376 }
377 $this->view->assign('isExecutableMessage', $message);
378 $this->view->assign('isExecutableSeverity', $severity);
379 $this->view->assign('now', $this->getServerTime());
380
381 return $this->view->render();
382 }
383
384 /**
385 * This method gathers information about all available task classes and displays it
386 *
387 * @return string html
388 */
389 protected function infoScreenAction()
390 {
391 $registeredClasses = $this->getRegisteredClasses();
392 // No classes available, display information message
393 if (empty($registeredClasses)) {
394 $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'InfoScreenNoClasses.html');
395 return $this->view->render();
396 }
397
398 $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'InfoScreen.html');
399 $this->view->assign('registeredClasses', $registeredClasses);
400
401 return $this->view->render();
402 }
403
404 /**
405 * Renders the task progress bar.
406 *
407 * @param float $progress Task progress
408 * @return string Progress bar markup
409 */
410 protected function renderTaskProgressBar($progress)
411 {
412 $progressText = $this->getLanguageService()->getLL('status.progress') . ':&nbsp;' . $progress . '%';
413 return '<div class="progress">'
414 . '<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%;">' . $progressText . '</div>'
415 . '</div>';
416 }
417
418 /**
419 * Delete a task from the execution queue
420 *
421 * @return void
422 */
423 protected function deleteTask()
424 {
425 try {
426 // Try to fetch the task and delete it
427 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
428 // If the task is currently running, it may not be deleted
429 if ($task->isExecutionRunning()) {
430 $this->addMessage($this->getLanguageService()->getLL('msg.maynotDeleteRunningTask'), FlashMessage::ERROR);
431 } else {
432 if ($this->scheduler->removeTask($task)) {
433 $this->getBackendUser()->writelog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was deleted', [$task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()]);
434 $this->addMessage($this->getLanguageService()->getLL('msg.deleteSuccess'));
435 } else {
436 $this->addMessage($this->getLanguageService()->getLL('msg.deleteError'), FlashMessage::ERROR);
437 }
438 }
439 } catch (\UnexpectedValueException $e) {
440 // The task could not be unserialized properly, simply delete the database record
441 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_scheduler_task');
442 $result = $queryBuilder->delete('tx_scheduler_task')
443 ->where(
444 $queryBuilder->expr()->eq(
445 'uid',
446 $queryBuilder->createNamedParameter($this->submittedData['uid'], \PDO::PARAM_INT)
447 )
448 )
449 ->execute();
450
451 if ($result) {
452 $this->addMessage($this->getLanguageService()->getLL('msg.deleteSuccess'));
453 } else {
454 $this->addMessage($this->getLanguageService()->getLL('msg.deleteError'), FlashMessage::ERROR);
455 }
456 } catch (\OutOfBoundsException $e) {
457 // The task was not found, for some reason
458 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.taskNotFound'), $this->submittedData['uid']), FlashMessage::ERROR);
459 }
460 }
461
462 /**
463 * Clears the registered running executions from the task
464 * Note that this doesn't actually stop the running script. It just unmarks
465 * all executions.
466 * @todo find a way to really kill the running task
467 *
468 * @return void
469 */
470 protected function stopTask()
471 {
472 try {
473 // Try to fetch the task and stop it
474 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
475 if ($task->isExecutionRunning()) {
476 // If the task is indeed currently running, clear marked executions
477 $result = $task->unmarkAllExecutions();
478 if ($result) {
479 $this->addMessage($this->getLanguageService()->getLL('msg.stopSuccess'));
480 } else {
481 $this->addMessage($this->getLanguageService()->getLL('msg.stopError'), FlashMessage::ERROR);
482 }
483 } else {
484 // The task is not running, nothing to unmark
485 $this->addMessage($this->getLanguageService()->getLL('msg.maynotStopNonRunningTask'), FlashMessage::WARNING);
486 }
487 } catch (\Exception $e) {
488 // The task was not found, for some reason
489 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.taskNotFound'), $this->submittedData['uid']), FlashMessage::ERROR);
490 }
491 }
492
493 /**
494 * Toggles the disabled state of the submitted task
495 *
496 * @return void
497 */
498 protected function toggleDisableAction()
499 {
500 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
501 $task->setDisabled(!$task->isDisabled());
502 // If a disabled single task is enabled again, we register it for a
503 // single execution at next scheduler run.
504 if ($task->getType() === AbstractTask::TYPE_SINGLE) {
505 $task->registerSingleExecution(time());
506 }
507 $task->save();
508 }
509
510 /**
511 * Sets the next execution time of the submitted task to now
512 *
513 * @return void
514 */
515 protected function setNextExecutionTimeAction()
516 {
517 $task = $this->scheduler->fetchTask($this->submittedData['uid']);
518 $task->setRunOnNextCronJob(true);
519 $task->save();
520 }
521
522 /**
523 * Return a form to add a new task or edit an existing one
524 *
525 * @return string HTML form to add or edit a task
526 */
527 protected function editTaskAction()
528 {
529 $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'EditTask.html');
530
531 $registeredClasses = $this->getRegisteredClasses();
532 $registeredTaskGroups = $this->getRegisteredTaskGroups();
533
534 $taskInfo = [];
535 $task = null;
536 $process = 'edit';
537
538 if ($this->submittedData['uid'] > 0) {
539 // If editing, retrieve data for existing task
540 try {
541 $taskRecord = $this->scheduler->fetchTaskRecord($this->submittedData['uid']);
542 // If there's a registered execution, the task should not be edited
543 if (!empty($taskRecord['serialized_executions'])) {
544 $this->addMessage($this->getLanguageService()->getLL('msg.maynotEditRunningTask'), FlashMessage::ERROR);
545 throw new \LogicException('Runnings tasks cannot not be edited', 1251232849);
546 }
547
548 // Get the task object
549 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask */
550 $task = unserialize($taskRecord['serialized_task_object']);
551
552 // Set some task information
553 $taskInfo['disable'] = $taskRecord['disable'];
554 $taskInfo['description'] = $taskRecord['description'];
555 $taskInfo['task_group'] = $taskRecord['task_group'];
556
557 // Check that the task object is valid
558 if (isset($registeredClasses[get_class($task)]) && $this->scheduler->isValidTaskObject($task)) {
559 // The task object is valid, process with fetching current data
560 $taskInfo['class'] = get_class($task);
561 // Get execution information
562 $taskInfo['start'] = (int)$task->getExecution()->getStart();
563 $taskInfo['end'] = (int)$task->getExecution()->getEnd();
564 $taskInfo['interval'] = $task->getExecution()->getInterval();
565 $taskInfo['croncmd'] = $task->getExecution()->getCronCmd();
566 $taskInfo['multiple'] = $task->getExecution()->getMultiple();
567 if (!empty($taskInfo['interval']) || !empty($taskInfo['croncmd'])) {
568 // Guess task type from the existing information
569 // If an interval or a cron command is defined, it's a recurring task
570 $taskInfo['type'] = AbstractTask::TYPE_RECURRING;
571 $taskInfo['frequency'] = $taskInfo['interval'] ?: $taskInfo['croncmd'];
572 } else {
573 // It's not a recurring task
574 // Make sure interval and cron command are both empty
575 $taskInfo['type'] = AbstractTask::TYPE_SINGLE;
576 $taskInfo['frequency'] = '';
577 $taskInfo['end'] = 0;
578 }
579 } else {
580 // The task object is not valid
581 // Issue error message
582 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.invalidTaskClassEdit'), get_class($task)), FlashMessage::ERROR);
583 // Initialize empty values
584 $taskInfo['start'] = 0;
585 $taskInfo['end'] = 0;
586 $taskInfo['frequency'] = '';
587 $taskInfo['multiple'] = false;
588 $taskInfo['type'] = AbstractTask::TYPE_SINGLE;
589 }
590 } catch (\OutOfBoundsException $e) {
591 // Add a message and continue throwing the exception
592 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.taskNotFound'), $this->submittedData['uid']), FlashMessage::ERROR);
593 throw $e;
594 }
595 } else {
596 // If adding a new object, set some default values
597 $taskInfo['class'] = key($registeredClasses);
598 $taskInfo['type'] = AbstractTask::TYPE_RECURRING;
599 $taskInfo['start'] = $GLOBALS['EXEC_TIME'];
600 $taskInfo['end'] = '';
601 $taskInfo['frequency'] = '';
602 $taskInfo['multiple'] = 0;
603 $process = 'add';
604 }
605
606 // If some data was already submitted, use it to override
607 // existing data
608 if (!empty($this->submittedData)) {
609 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($taskInfo, $this->submittedData);
610 }
611
612 // Get the extra fields to display for each task that needs some
613 $allAdditionalFields = [];
614 if ($process === 'add') {
615 foreach ($registeredClasses as $class => $registrationInfo) {
616 if (!empty($registrationInfo['provider'])) {
617 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
618 $providerObject = GeneralUtility::getUserObj($registrationInfo['provider']);
619 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
620 $additionalFields = $providerObject->getAdditionalFields($taskInfo, null, $this);
621 $allAdditionalFields = array_merge($allAdditionalFields, [$class => $additionalFields]);
622 }
623 }
624 }
625 } else {
626 if (!empty($registeredClasses[$taskInfo['class']]['provider'])) {
627 $providerObject = GeneralUtility::getUserObj($registeredClasses[$taskInfo['class']]['provider']);
628 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
629 $allAdditionalFields[$taskInfo['class']] = $providerObject->getAdditionalFields($taskInfo, $task, $this);
630 }
631 }
632 }
633
634 // Load necessary JavaScript
635 $this->getPageRenderer()->loadJquery();
636 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Scheduler/Scheduler');
637 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker');
638
639 // Start rendering the add/edit form
640 $this->view->assign('uid', htmlspecialchars($this->submittedData['uid']));
641 $this->view->assign('cmd', htmlspecialchars($this->CMD));
642
643 $table = [];
644
645 // Disable checkbox
646 $label = '<label>' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:disable') . '</label>';
647 $table[] =
648 '<div class="form-section" id="task_disable_row"><div class="form-group">'
649 . BackendUtility::wrapInHelp($this->cshKey, 'task_disable', $label)
650 . '<div class="form-control-wrap">'
651 . '<input type="hidden" name="tx_scheduler[disable]" value="0">'
652 . '<input class="checkbox" type="checkbox" name="tx_scheduler[disable]" value="1" id="task_disable" ' . ($taskInfo['disable'] ? ' checked="checked"' : '') . '>'
653 . '</div>'
654 . '</div></div>';
655
656 // Task class selector
657 $label = '<label>' . $this->getLanguageService()->getLL('label.class') . '</label>';
658
659 // On editing, don't allow changing of the task class, unless it was not valid
660 if ($this->submittedData['uid'] > 0 && !empty($taskInfo['class'])) {
661 $cell = '<div>' . $registeredClasses[$taskInfo['class']]['title'] . ' (' . $registeredClasses[$taskInfo['class']]['extension'] . ')</div>';
662 $cell .= '<input type="hidden" name="tx_scheduler[class]" id="task_class" value="' . htmlspecialchars($taskInfo['class']) . '">';
663 } else {
664 $cell = '<select name="tx_scheduler[class]" id="task_class" class="form-control">';
665 // Group registered classes by classname
666 $groupedClasses = [];
667 foreach ($registeredClasses as $class => $classInfo) {
668 $groupedClasses[$classInfo['extension']][$class] = $classInfo;
669 }
670 ksort($groupedClasses);
671 // Loop on all grouped classes to display a selector
672 foreach ($groupedClasses as $extension => $class) {
673 $cell .= '<optgroup label="' . htmlspecialchars($extension) . '">';
674 foreach ($groupedClasses[$extension] as $class => $classInfo) {
675 $selected = $class == $taskInfo['class'] ? ' selected="selected"' : '';
676 $cell .= '<option value="' . htmlspecialchars($class) . '"' . 'title="' . htmlspecialchars($classInfo['description']) . '" ' . $selected . '>' . htmlspecialchars($classInfo['title']) . '</option>';
677 }
678 $cell .= '</optgroup>';
679 }
680 $cell .= '</select>';
681 }
682 $table[] =
683 '<div class="form-section" id="task_class_row"><div class="form-group">'
684 . BackendUtility::wrapInHelp($this->cshKey, 'task_class', $label)
685 . '<div class="form-control-wrap">'
686 . $cell
687 . '</div>'
688 . '</div></div>';
689
690 // Task type selector
691 $label = '<label>' . $this->getLanguageService()->getLL('label.type') . '</label>';
692 $table[] =
693 '<div class="form-section" id="task_type_row"><div class="form-group">'
694 . BackendUtility::wrapInHelp($this->cshKey, 'task_type', $label)
695 . '<div class="form-control-wrap">'
696 . '<select name="tx_scheduler[type]" id="task_type" class="form-control">'
697 . '<option value="1" ' . ((int)$taskInfo['type'] === AbstractTask::TYPE_SINGLE ? ' selected="selected"' : '') . '>' . $this->getLanguageService()->getLL('label.type.single') . '</option>'
698 . '<option value="2" ' . ((int)$taskInfo['type'] === AbstractTask::TYPE_RECURRING ? ' selected="selected"' : '') . '>' . $this->getLanguageService()->getLL('label.type.recurring') . '</option>'
699 . '</select>'
700 . '</div>'
701 . '</div></div>';
702
703 // Task group selector
704 $label = '<label>' . $this->getLanguageService()->getLL('label.group') . '</label>';
705 $cell = '<select name="tx_scheduler[task_group]" id="task_class" class="form-control">';
706
707 // Loop on all groups to display a selector
708 $cell .= '<option value="0" title=""></option>';
709 foreach ($registeredTaskGroups as $taskGroup) {
710 $selected = $taskGroup['uid'] == $taskInfo['task_group'] ? ' selected="selected"' : '';
711 $cell .= '<option value="' . $taskGroup['uid'] . '"' . 'title="';
712 $cell .= htmlspecialchars($taskGroup['groupName']) . '"' . $selected . '>';
713 $cell .= htmlspecialchars($taskGroup['groupName']) . '</option>';
714 }
715 $cell .= '</select>';
716
717 $table[] =
718 '<div class="form-section" id="task_group_row"><div class="form-group">'
719 . BackendUtility::wrapInHelp($this->cshKey, 'task_group', $label)
720 . '<div class="form-control-wrap">'
721 . $cell
722 . '</div>'
723 . '</div></div>';
724
725 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? '%H:%M %m-%d-%Y' : '%H:%M %d-%m-%Y';
726
727 $label = '<label>' . BackendUtility::wrapInHelp($this->cshKey, 'task_start', $this->getLanguageService()->getLL('label.start')) . '</label>';
728 $value = ($taskInfo['start'] > 0 ? strftime($dateFormat, $taskInfo['start']) : '');
729 $table[] =
730 '<div class="form-section"><div class="row"><div class="form-group col-sm-6" id="task_start_col">'
731 . $label
732 . '<div class="form-control-wrap">'
733 . '<div class="input-group" id="tceforms-datetimefield-task_start_row-wrapper">'
734 . '<input name="tx_scheduler[start]_hr" value="' . $value . '" class="form-control t3js-datetimepicker t3js-clearable" data-date-type="datetime" data-date-offset="0" type="text" id="tceforms-datetimefield-task_start_row">'
735 . '<input name="tx_scheduler[start]" value="' . $taskInfo['start'] . '" type="hidden">'
736 . '<span class="input-group-btn"><label class="btn btn-default" for="tceforms-datetimefield-task_start_row"><span class="fa fa-calendar"></span></label></span>'
737 . '</div>'
738 . '</div>'
739 . '</div>';
740
741 // End date/time field
742 // NOTE: datetime fields need a special id naming scheme
743 $value = ($taskInfo['end'] > 0 ? strftime($dateFormat, $taskInfo['end']) : '');
744 $label = '<label>' . $this->getLanguageService()->getLL('label.end') . '</label>';
745 $table[] =
746 '<div class="form-group col-sm-6" id="task_end_col">'
747 . BackendUtility::wrapInHelp($this->cshKey, 'task_end', $label)
748 . '<div class="form-control-wrap">'
749 . '<div class="input-group" id="tceforms-datetimefield-task_end_row-wrapper">'
750 . '<input name="tx_scheduler[end]_hr" value="' . $value . '" class="form-control t3js-datetimepicker t3js-clearable" data-date-type="datetime" data-date-offset="0" type="text" id="tceforms-datetimefield-task_end_row">'
751 . '<input name="tx_scheduler[end]" value="' . $taskInfo['end'] . '" type="hidden">'
752 . '<span class="input-group-btn"><label class="btn btn-default" for="tceforms-datetimefield-task_end_row"><span class="fa fa-calendar"></span></label></span>'
753 . '</div>'
754 . '</div>'
755 . '</div></div></div>';
756
757 // Frequency input field
758 $label = '<label>' . $this->getLanguageService()->getLL('label.frequency.long') . '</label>';
759 $table[] =
760 '<div class="form-section" id="task_frequency_row"><div class="form-group">'
761 . BackendUtility::wrapInHelp($this->cshKey, 'task_frequency', $label)
762 . '<div class="form-control-wrap">'
763 . '<input type="text" name="tx_scheduler[frequency]" class="form-control" id="task_frequency" value="' . htmlspecialchars($taskInfo['frequency']) . '">'
764 . '</div>'
765 . '</div></div>';
766
767 // Multiple execution selector
768 $label = '<label>' . $this->getLanguageService()->getLL('label.parallel.long') . '</label>';
769 $table[] =
770 '<div class="form-section" id="task_multiple_row"><div class="form-group">'
771 . BackendUtility::wrapInHelp($this->cshKey, 'task_multiple', $label)
772 . '<div class="form-control-wrap">'
773 . '<input type="hidden" name="tx_scheduler[multiple]" value="0">'
774 . '<input class="checkbox" type="checkbox" name="tx_scheduler[multiple]" value="1" id="task_multiple" ' . ($taskInfo['multiple'] ? 'checked="checked"' : '') . '>'
775 . '</div>'
776 . '</div></div>';
777
778 // Description
779 $label = '<label>' . $this->getLanguageService()->getLL('label.description') . '</label>';
780 $table[] =
781 '<div class="form-section" id="task_description_row"><div class="form-group">'
782 . BackendUtility::wrapInHelp($this->cshKey, 'task_description', $label)
783 . '<div class="form-control-wrap">'
784 . '<textarea class="form-control" name="tx_scheduler[description]">' . htmlspecialchars($taskInfo['description']) . '</textarea>'
785 . '</div>'
786 . '</div></div>';
787
788 // Display additional fields
789 foreach ($allAdditionalFields as $class => $fields) {
790 if ($class == $taskInfo['class']) {
791 $additionalFieldsStyle = '';
792 } else {
793 $additionalFieldsStyle = ' style="display: none"';
794 }
795 // Add each field to the display, if there are indeed any
796 if (isset($fields) && is_array($fields)) {
797 foreach ($fields as $fieldID => $fieldInfo) {
798 $label = '<label>' . $this->getLanguageService()->sL($fieldInfo['label']) . '</label>';
799 $htmlClassName = strtolower(str_replace('\\', '-', $class));
800
801 $table[] =
802 '<div class="form-section extraFields extra_fields_' . $htmlClassName . '" ' . $additionalFieldsStyle . ' id="' . $fieldID . '_row"><div class="form-group">'
803 . BackendUtility::wrapInHelp($fieldInfo['cshKey'], $fieldInfo['cshLabel'], $label)
804 . '<div class="form-control-wrap">' . $fieldInfo['code'] . '</div>'
805 . '</div></div>';
806 }
807 }
808 }
809
810 $this->view->assign('table', implode(LF, $table));
811 $this->view->assign('now', $this->getServerTime());
812
813 return $this->view->render();
814 }
815
816 /**
817 * Execute all selected tasks
818 *
819 * @return void
820 */
821 protected function executeTasks()
822 {
823 // Make sure next automatic scheduler-run is scheduled
824 if (GeneralUtility::_POST('go') !== null) {
825 $this->scheduler->scheduleNextSchedulerRunUsingAtDaemon();
826 }
827 // Continue if some elements have been chosen for execution
828 if (isset($this->submittedData['execute']) && !empty($this->submittedData['execute'])) {
829 // Get list of registered classes
830 $registeredClasses = $this->getRegisteredClasses();
831 // Loop on all selected tasks
832 foreach ($this->submittedData['execute'] as $uid) {
833 try {
834 // Try fetching the task
835 $task = $this->scheduler->fetchTask($uid);
836 $class = get_class($task);
837 $name = $registeredClasses[$class]['title'] . ' (' . $registeredClasses[$class]['extension'] . ')';
838 if (GeneralUtility::_POST('go_cron') !== null) {
839 $task->setRunOnNextCronJob(true);
840 $task->save();
841 } else {
842 // Now try to execute it and report on outcome
843 try {
844 $result = $this->scheduler->executeTask($task);
845 if ($result) {
846 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.executed'), $name));
847 } else {
848 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.notExecuted'), $name), FlashMessage::ERROR);
849 }
850 } catch (\Exception $e) {
851 // An exception was thrown, display its message as an error
852 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.executionFailed'), $name, $e->getMessage()), FlashMessage::ERROR);
853 }
854 }
855 } catch (\OutOfBoundsException $e) {
856 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.taskNotFound'), $uid), FlashMessage::ERROR);
857 } catch (\UnexpectedValueException $e) {
858 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.executionFailed'), $uid, $e->getMessage()), FlashMessage::ERROR);
859 }
860 }
861 // Record the run in the system registry
862 $this->scheduler->recordLastRun('manual');
863 // Make sure to switch to list view after execution
864 $this->CMD = 'list';
865 }
866 }
867
868 /**
869 * Assemble display of list of scheduled tasks
870 *
871 * @return string Table of pending tasks
872 */
873 protected function listTasksAction()
874 {
875 $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'ListTasks.html');
876
877 // Define display format for dates
878 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
879
880 // Get list of registered task groups
881 $registeredTaskGroups = $this->getRegisteredTaskGroups();
882
883 // add an empty entry for non-grouped tasks
884 // add in front of list
885 array_unshift($registeredTaskGroups, ['uid' => 0, 'groupName' => '']);
886
887 // Get all registered tasks
888 // Just to get the number of entries
889 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
890 ->getQueryBuilderForTable('tx_scheduler_task');
891 $queryBuilder->getRestrictions()->removeAll();
892
893 $result = $queryBuilder->select('t.*')
894 ->addSelect(
895 'g.groupName AS taskGroupName',
896 'g.description AS taskGroupDescription',
897 'g.deleted AS isTaskGroupDeleted'
898 )
899 ->from('tx_scheduler_task', 't')
900 ->leftJoin(
901 't',
902 'tx_scheduler_task_group',
903 'g',
904 $queryBuilder->expr()->eq('t.task_group', $queryBuilder->quoteIdentifier('g.uid'))
905 )
906 ->orderBy('g.sorting')
907 ->execute();
908
909 // Loop on all tasks
910 $temporaryResult = [];
911 while ($row = $result->fetch()) {
912 if ($row['taskGroupName'] === null || $row['isTaskGroupDeleted'] === '1') {
913 $row['taskGroupName'] = '';
914 $row['taskGroupDescription'] = '';
915 $row['task_group'] = 0;
916 }
917 $temporaryResult[$row['task_group']]['groupName'] = $row['taskGroupName'];
918 $temporaryResult[$row['task_group']]['groupDescription'] = $row['taskGroupDescription'];
919 $temporaryResult[$row['task_group']]['tasks'][] = $row;
920 }
921
922 // No tasks defined, display information message
923 if (empty($temporaryResult)) {
924 $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'ListTasksNoTasks.html');
925 return $this->view->render();
926 }
927
928 $this->getPageRenderer()->loadJquery();
929 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Scheduler/Scheduler');
930 $table = [];
931 // Header row
932 $table[] =
933 '<thead><tr>'
934 . '<th><a class="btn btn-default" href="#" id="checkall" title="' . htmlspecialchars($this->getLanguageService()->getLL('label.checkAll')) . '" class="icon">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a></th>'
935 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('label.id')) . '</th>'
936 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('task')) . '</th>'
937 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('label.type')) . '</th>'
938 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('label.frequency')) . '</th>'
939 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('label.parallel')) . '</th>'
940 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('label.lastExecution')) . '</th>'
941 . '<th>' . htmlspecialchars($this->getLanguageService()->getLL('label.nextExecution')) . '</th>'
942 . '<th></th>'
943 . '</tr></thead>';
944
945 $registeredClasses = $this->getRegisteredClasses();
946 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
947 $collapseIcon = $iconFactory->getIcon('actions-view-list-collapse', Icon::SIZE_SMALL)->render();
948 $expandIcon = $iconFactory->getIcon('actions-view-list-expand', Icon::SIZE_SMALL)->render();
949 foreach ($temporaryResult as $taskIndex => $taskGroup) {
950 $collapseExpandIcons = '<span class="taskGroup_' . $taskIndex . '">' . $collapseIcon . '</span>'
951 . '<span class="taskGroup_' . $taskIndex . '" style="display: none;">' . $expandIcon . '</span>';
952 if (!empty($taskGroup['groupName'])) {
953 $groupText = '<strong>' . htmlspecialchars($taskGroup['groupName']) . '</strong>';
954 if (!empty($taskGroup['groupDescription'])) {
955 $groupText .= '<br>' . nl2br(htmlspecialchars($taskGroup['groupDescription']));
956 }
957 $table[] = '<tr class="taskGroup" data-task-group-id="' . $taskIndex . '"><td colspan="8">' . $groupText . '</td><td style="text-align:right;">' . $collapseExpandIcons . '</td></tr>';
958 } else {
959 if (sizeof($temporaryResult) > 1) {
960 $table[] = '<tr class="taskGroup" data-task-group-id="0"><td colspan="8"><strong>' . htmlspecialchars($this->getLanguageService()->getLL('label.noGroup')) . '</strong></td><td style="text-align:right;">' . $collapseExpandIcons . '</td></tr>';
961 }
962 }
963
964 foreach ($taskGroup['tasks'] as $schedulerRecord) {
965 // Define action icons
966 $link = htmlspecialchars($this->moduleUri . '&CMD=edit&tx_scheduler[uid]=' . $schedulerRecord['uid']);
967 $editAction = '<a class="btn btn-default" href="' . $link . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:edit')) . '" class="icon">' .
968 $this->moduleTemplate->getIconFactory()->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
969 if ((int)$schedulerRecord['disable'] === 1) {
970 $translationKey = 'enable';
971 $icon = $this->moduleTemplate->getIconFactory()->getIcon('actions-edit-unhide', Icon::SIZE_SMALL);
972 } else {
973 $translationKey = 'disable';
974 $icon = $this->moduleTemplate->getIconFactory()->getIcon('actions-edit-hide', Icon::SIZE_SMALL);
975 }
976 $toggleHiddenAction = '<a class="btn btn-default" href="' . htmlspecialchars($this->moduleUri
977 . '&CMD=toggleHidden&tx_scheduler[uid]=' . $schedulerRecord['uid']) . '" title="'
978 . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:' . $translationKey))
979 . '" class="icon">' . $icon->render() . '</a>';
980 $deleteAction = '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($this->moduleUri . '&CMD=delete&tx_scheduler[uid]=' . $schedulerRecord['uid']) . '" '
981 . ' data-severity="warning"'
982 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:delete')) . '"'
983 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel')) . '"'
984 . ' data-content="' . htmlspecialchars($this->getLanguageService()->getLL('msg.delete')) . '"'
985 . ' title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:delete')) . '" class="icon">' .
986 $this->moduleTemplate->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
987 $stopAction = '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($this->moduleUri . '&CMD=stop&tx_scheduler[uid]=' . $schedulerRecord['uid']) . '" '
988 . ' data-severity="warning"'
989 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:stop')) . '"'
990 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel')) . '"'
991 . ' data-content="' . htmlspecialchars($this->getLanguageService()->getLL('msg.stop')) . '"'
992 . ' title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:stop')) . '" class="icon">' .
993 $this->moduleTemplate->getIconFactory()->getIcon('actions-document-close', Icon::SIZE_SMALL)->render() . '</a>';
994 $runAction = '<a class="btn btn-default" href="' . htmlspecialchars($this->moduleUri . '&tx_scheduler[execute][]=' . $schedulerRecord['uid']) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('action.run_task')) . '" class="icon">' .
995 $this->moduleTemplate->getIconFactory()->getIcon('extensions-scheduler-run-task', Icon::SIZE_SMALL)->render() . '</a>';
996 $runCronAction = '<a class="btn btn-default" href="' . htmlspecialchars($this->moduleUri . '&CMD=setNextExecutionTime&tx_scheduler[uid]=' . $schedulerRecord['uid']) . '" title="' . $this->getLanguageService()->getLL('action.run_task_cron', true) . '" class="icon">' .
997 $this->moduleTemplate->getIconFactory()->getIcon('extensions-scheduler-run-task-cron', Icon::SIZE_SMALL)->render() . '</a>';
998
999 // Define some default values
1000 $lastExecution = '-';
1001 $isRunning = false;
1002 $showAsDisabled = false;
1003 $startExecutionElement = '<span class="btn btn-default disabled">' . $this->moduleTemplate->getIconFactory()->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1004 // Restore the serialized task and pass it a reference to the scheduler object
1005 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask|\TYPO3\CMS\Scheduler\ProgressProviderInterface */
1006 $task = unserialize($schedulerRecord['serialized_task_object']);
1007 $class = get_class($task);
1008 if ($class === '__PHP_Incomplete_Class' && preg_match('/^O:[0-9]+:"(?P<classname>.+?)"/', $schedulerRecord['serialized_task_object'], $matches) === 1) {
1009 $class = $matches['classname'];
1010 }
1011 // Assemble information about last execution
1012 if (!empty($schedulerRecord['lastexecution_time'])) {
1013 $lastExecution = date($dateFormat, $schedulerRecord['lastexecution_time']);
1014 if ($schedulerRecord['lastexecution_context'] === 'CLI') {
1015 $context = $this->getLanguageService()->getLL('label.cron');
1016 } else {
1017 $context = $this->getLanguageService()->getLL('label.manual');
1018 }
1019 $lastExecution .= ' (' . $context . ')';
1020 }
1021
1022 if (isset($registeredClasses[get_class($task)]) && $this->scheduler->isValidTaskObject($task)) {
1023 // The task object is valid
1024 $labels = [];
1025 $name = htmlspecialchars($registeredClasses[$class]['title'] . ' (' . $registeredClasses[$class]['extension'] . ')');
1026 $additionalInformation = $task->getAdditionalInformation();
1027 if ($task instanceof \TYPO3\CMS\Scheduler\ProgressProviderInterface) {
1028 $progress = round((float)$task->getProgress(), 2);
1029 $name .= $this->renderTaskProgressBar($progress);
1030 }
1031 if (!empty($additionalInformation)) {
1032 $name .= '<div class="additional-information">' . nl2br(htmlspecialchars($additionalInformation)) . '</div>';
1033 }
1034 // Check if task currently has a running execution
1035 if (!empty($schedulerRecord['serialized_executions'])) {
1036 $labels[] = [
1037 'class' => 'success',
1038 'text' => $this->getLanguageService()->getLL('status.running')
1039 ];
1040 $isRunning = true;
1041 }
1042
1043 // Prepare display of next execution date
1044 // If task is currently running, date is not displayed (as next hasn't been calculated yet)
1045 // Also hide the date if task is disabled (the information doesn't make sense, as it will not run anyway)
1046 if ($isRunning || $schedulerRecord['disable']) {
1047 $nextDate = '-';
1048 } else {
1049 $nextDate = date($dateFormat, $schedulerRecord['nextexecution']);
1050 if (empty($schedulerRecord['nextexecution'])) {
1051 $nextDate = $this->getLanguageService()->getLL('none');
1052 } elseif ($schedulerRecord['nextexecution'] < $GLOBALS['EXEC_TIME']) {
1053 $labels[] = [
1054 'class' => 'warning',
1055 'text' => $this->getLanguageService()->getLL('status.late'),
1056 'description' => $this->getLanguageService()->getLL('status.legend.scheduled')
1057 ];
1058 }
1059 }
1060 // Get execution type
1061 if ($task->getType() === AbstractTask::TYPE_SINGLE) {
1062 $execType = $this->getLanguageService()->getLL('label.type.single');
1063 $frequency = '-';
1064 } else {
1065 $execType = $this->getLanguageService()->getLL('label.type.recurring');
1066 if ($task->getExecution()->getCronCmd() == '') {
1067 $frequency = $task->getExecution()->getInterval();
1068 } else {
1069 $frequency = $task->getExecution()->getCronCmd();
1070 }
1071 }
1072 // Get multiple executions setting
1073 if ($task->getExecution()->getMultiple()) {
1074 $multiple = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:yes');
1075 } else {
1076 $multiple = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:no');
1077 }
1078 // Define checkbox
1079 $startExecutionElement = '<label class="btn btn-default btn-checkbox"><input type="checkbox" name="tx_scheduler[execute][]" value="' . $schedulerRecord['uid'] . '" id="task_' . $schedulerRecord['uid'] . '"><span class="t3-icon fa"></span></label>';
1080
1081 $actions = '<div class="btn-group" role="group">' . $editAction . $toggleHiddenAction . $deleteAction . '</div>';
1082
1083 // Check the disable status
1084 // Row is shown dimmed if task is disabled, unless it is still running
1085 if ($schedulerRecord['disable'] && !$isRunning) {
1086 $labels[] = [
1087 'class' => 'default',
1088 'text' => $this->getLanguageService()->getLL('status.disabled')
1089 ];
1090 $showAsDisabled = true;
1091 }
1092
1093 // Show no action links (edit, delete) if task is running
1094 if ($isRunning) {
1095 $actions = '<div class="btn-group" role="group">' . $stopAction . '</div>';
1096 } else {
1097 $actions .= '&nbsp;<div class="btn-group" role="group">' . $runAction . $runCronAction . '</div>';
1098 }
1099
1100 // Check if the last run failed
1101 if (!empty($schedulerRecord['lastexecution_failure'])) {
1102 // Try to get the stored exception array
1103 /** @var $exceptionArray array */
1104 $exceptionArray = @unserialize($schedulerRecord['lastexecution_failure']);
1105 // If the exception could not be unserialized, issue a default error message
1106 if (!is_array($exceptionArray) || empty($exceptionArray)) {
1107 $labelDescription = $this->getLanguageService()->getLL('msg.executionFailureDefault');
1108 } else {
1109 $labelDescription = sprintf($this->getLanguageService()->getLL('msg.executionFailureReport'), $exceptionArray['code'], $exceptionArray['message']);
1110 }
1111 $labels[] = [
1112 'class' => 'danger',
1113 'text' => $this->getLanguageService()->getLL('status.failure'),
1114 'description' => $labelDescription
1115 ];
1116 }
1117 // Format the execution status,
1118 // including failure feedback, if any
1119 $taskDesc = '';
1120 if ($schedulerRecord['description'] !== '') {
1121 $taskDesc = '<span class="description">' . nl2br(htmlspecialchars($schedulerRecord['description'])) . '</span>';
1122 }
1123 $taskName = '<span class="name"><a href="' . $link . '">' . $name . '</a></span>';
1124
1125 $table[] =
1126 '<tr class="' . ($showAsDisabled ? 'disabled' : '') . ' taskGroup_' . $taskIndex . '">'
1127 . '<td><span class="t-span">' . $startExecutionElement . '</span></td>'
1128 . '<td class="right"><span class="t-span">' . $schedulerRecord['uid'] . '</span></td>'
1129 . '<td><span class="t-span">' . $this->makeStatusLabel($labels) . $taskName . $taskDesc . '</span></td>'
1130 . '<td><span class="t-span">' . $execType . '</span></td>'
1131 . '<td><span class="t-span">' . $frequency . '</span></td>'
1132 . '<td><span class="t-span">' . $multiple . '</span></td>'
1133 . '<td><span class="t-span">' . $lastExecution . '</span></td>'
1134 . '<td><span class="t-span">' . $nextDate . '</span></td>'
1135 . '<td nowrap="nowrap"><span class="t-span">' . $actions . '</span></td>'
1136 . '</tr>';
1137 } else {
1138 // The task object is not valid
1139 // Prepare to issue an error
1140 $executionStatusOutput = '<span class="label label-danger">'
1141 . htmlspecialchars(sprintf(
1142 $this->getLanguageService()->getLL('msg.invalidTaskClass'),
1143 $class
1144 ))
1145 . '</span>';
1146 $table[] =
1147 '<tr>'
1148 . '<td>' . $startExecutionElement . '</td>'
1149 . '<td class="right">' . $schedulerRecord['uid'] . '</td>'
1150 . '<td colspan="6">' . $executionStatusOutput . '</td>'
1151 . '<td nowrap="nowrap"><div class="btn-group" role="group">'
1152 . '<span class="btn btn-default disabled">' . $this->moduleTemplate->getIconFactory()->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>'
1153 . '<span class="btn btn-default disabled">' . $this->moduleTemplate->getIconFactory()->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>'
1154 . $deleteAction
1155 . '<span class="btn btn-default disabled">' . $this->moduleTemplate->getIconFactory()->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>'
1156 . '</div></td>'
1157 . '</tr>';
1158 }
1159 }
1160 }
1161
1162 $this->view->assign('table', '<table class="table table-striped table-hover">' . implode(LF, $table) . '</table>');
1163 $this->view->assign('now', $this->getServerTime());
1164
1165 return $this->view->render();
1166 }
1167
1168 /**
1169 * Generates bootstrap labels containing the label statuses
1170 *
1171 * @param array $labels
1172 * @return string
1173 */
1174 protected function makeStatusLabel(array $labels)
1175 {
1176 $htmlLabels = [];
1177 foreach ($labels as $label) {
1178 if (empty($label['text'])) {
1179 continue;
1180 }
1181 $htmlLabels[] = '<span class="label label-' . htmlspecialchars($label['class']) . ' pull-right" title="' . htmlspecialchars($label['description']) . '">' . htmlspecialchars($label['text']) . '</span>';
1182 }
1183
1184 return implode('&nbsp;', $htmlLabels);
1185 }
1186
1187 /**
1188 * Saves a task specified in the backend form to the database
1189 *
1190 * @return void
1191 */
1192 protected function saveTask()
1193 {
1194 // If a task is being edited fetch old task data
1195 if (!empty($this->submittedData['uid'])) {
1196 try {
1197 $taskRecord = $this->scheduler->fetchTaskRecord($this->submittedData['uid']);
1198 /** @var $task \TYPO3\CMS\Scheduler\Task\AbstractTask */
1199 $task = unserialize($taskRecord['serialized_task_object']);
1200 } catch (\OutOfBoundsException $e) {
1201 // If the task could not be fetched, issue an error message
1202 // and exit early
1203 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.taskNotFound'), $this->submittedData['uid']), FlashMessage::ERROR);
1204 return;
1205 }
1206 // Register single execution
1207 if ((int)$this->submittedData['type'] === AbstractTask::TYPE_SINGLE) {
1208 $task->registerSingleExecution($this->submittedData['start']);
1209 } else {
1210 if (!empty($this->submittedData['croncmd'])) {
1211 // Definition by cron-like syntax
1212 $interval = 0;
1213 $cronCmd = $this->submittedData['croncmd'];
1214 } else {
1215 // Definition by interval
1216 $interval = $this->submittedData['interval'];
1217 $cronCmd = '';
1218 }
1219 // Register recurring execution
1220 $task->registerRecurringExecution($this->submittedData['start'], $interval, $this->submittedData['end'], $this->submittedData['multiple'], $cronCmd);
1221 }
1222 // Set disable flag
1223 $task->setDisabled($this->submittedData['disable']);
1224 // Set description
1225 $task->setDescription($this->submittedData['description']);
1226 // Set task group
1227 $task->setTaskGroup($this->submittedData['task_group']);
1228 // Save additional input values
1229 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1230 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1231 $providerObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1232 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1233 $providerObject->saveAdditionalFields($this->submittedData, $task);
1234 }
1235 }
1236 // Save to database
1237 $result = $this->scheduler->saveTask($task);
1238 if ($result) {
1239 $this->getBackendUser()->writelog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was updated', [$task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()]);
1240 $this->addMessage($this->getLanguageService()->getLL('msg.updateSuccess'));
1241 } else {
1242 $this->addMessage($this->getLanguageService()->getLL('msg.updateError'), FlashMessage::ERROR);
1243 }
1244 } else {
1245 // A new task is being created
1246 // Create an instance of chosen class
1247 /** @var $task AbstractTask */
1248 $task = GeneralUtility::makeInstance($this->submittedData['class']);
1249 if ((int)$this->submittedData['type'] === AbstractTask::TYPE_SINGLE) {
1250 // Set up single execution
1251 $task->registerSingleExecution($this->submittedData['start']);
1252 } else {
1253 // Set up recurring execution
1254 $task->registerRecurringExecution($this->submittedData['start'], $this->submittedData['interval'], $this->submittedData['end'], $this->submittedData['multiple'], $this->submittedData['croncmd']);
1255 }
1256 // Save additional input values
1257 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1258 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1259 $providerObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1260 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1261 $providerObject->saveAdditionalFields($this->submittedData, $task);
1262 }
1263 }
1264 // Set disable flag
1265 $task->setDisabled($this->submittedData['disable']);
1266 // Set description
1267 $task->setDescription($this->submittedData['description']);
1268 // Set description
1269 $task->setTaskGroup($this->submittedData['task_group']);
1270 // Add to database
1271 $result = $this->scheduler->addTask($task);
1272 if ($result) {
1273 $this->getBackendUser()->writelog(4, 0, 0, 0, 'Scheduler task "%s" (UID: %s, Class: "%s") was added', [$task->getTaskTitle(), $task->getTaskUid(), $task->getTaskClassName()]);
1274 $this->addMessage($this->getLanguageService()->getLL('msg.addSuccess'));
1275
1276 // set the uid of the just created task so that we
1277 // can continue editing after initial saving
1278 $this->submittedData['uid'] = $task->getTaskUid();
1279 } else {
1280 $this->addMessage($this->getLanguageService()->getLL('msg.addError'), FlashMessage::ERROR);
1281 }
1282 }
1283 }
1284
1285 /*************************
1286 *
1287 * INPUT PROCESSING UTILITIES
1288 *
1289 *************************/
1290 /**
1291 * Checks the submitted data and performs some pre-processing on it
1292 *
1293 * @return bool true if everything was ok, false otherwise
1294 */
1295 protected function preprocessData()
1296 {
1297 $result = true;
1298 // Validate id
1299 $this->submittedData['uid'] = empty($this->submittedData['uid']) ? 0 : (int)$this->submittedData['uid'];
1300 // Validate selected task class
1301 if (!class_exists($this->submittedData['class'])) {
1302 $this->addMessage($this->getLanguageService()->getLL('msg.noTaskClassFound'), FlashMessage::ERROR);
1303 }
1304 // Check start date
1305 if (empty($this->submittedData['start'])) {
1306 $this->addMessage($this->getLanguageService()->getLL('msg.noStartDate'), FlashMessage::ERROR);
1307 $result = false;
1308 } else {
1309 try {
1310 $this->submittedData['start'] = (int)$this->submittedData['start'];
1311 } catch (\Exception $e) {
1312 $this->addMessage($this->getLanguageService()->getLL('msg.invalidStartDate'), FlashMessage::ERROR);
1313 $result = false;
1314 }
1315 }
1316 // Check end date, if recurring task
1317 if ((int)$this->submittedData['type'] === AbstractTask::TYPE_RECURRING && !empty($this->submittedData['end'])) {
1318 try {
1319 $this->submittedData['end'] = (int)$this->submittedData['end'];
1320 if ($this->submittedData['end'] < $this->submittedData['start']) {
1321 $this->addMessage($this->getLanguageService()->getLL('msg.endDateSmallerThanStartDate'), FlashMessage::ERROR);
1322 $result = false;
1323 }
1324 } catch (\Exception $e) {
1325 $this->addMessage($this->getLanguageService()->getLL('msg.invalidEndDate'), FlashMessage::ERROR);
1326 $result = false;
1327 }
1328 }
1329 // Set default values for interval and cron command
1330 $this->submittedData['interval'] = 0;
1331 $this->submittedData['croncmd'] = '';
1332 // Check type and validity of frequency, if recurring
1333 if ((int)$this->submittedData['type'] === AbstractTask::TYPE_RECURRING) {
1334 $frequency = trim($this->submittedData['frequency']);
1335 if (empty($frequency)) {
1336 // Empty frequency, not valid
1337 $this->addMessage($this->getLanguageService()->getLL('msg.noFrequency'), FlashMessage::ERROR);
1338 $result = false;
1339 } else {
1340 $cronErrorCode = 0;
1341 $cronErrorMessage = '';
1342 // Try interpreting the cron command
1343 try {
1344 \TYPO3\CMS\Scheduler\CronCommand\NormalizeCommand::normalize($frequency);
1345 $this->submittedData['croncmd'] = $frequency;
1346 } catch (\Exception $e) {
1347 // Store the exception's result
1348 $cronErrorMessage = $e->getMessage();
1349 $cronErrorCode = $e->getCode();
1350 // Check if the frequency is a valid number
1351 // If yes, assume it is a frequency in seconds, and unset cron error code
1352 if (is_numeric($frequency)) {
1353 $this->submittedData['interval'] = (int)$frequency;
1354 unset($cronErrorCode);
1355 }
1356 }
1357 // If there's a cron error code, issue validation error message
1358 if (!empty($cronErrorCode)) {
1359 $this->addMessage(sprintf($this->getLanguageService()->getLL('msg.frequencyError'), $cronErrorMessage, $cronErrorCode), FlashMessage::ERROR);
1360 $result = false;
1361 }
1362 }
1363 }
1364 // Validate additional input fields
1365 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields'])) {
1366 /** @var $providerObject \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface */
1367 $providerObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][$this->submittedData['class']]['additionalFields']);
1368 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
1369 // The validate method will return true if all went well, but that must not
1370 // override previous false values => AND the returned value with the existing one
1371 $result &= $providerObject->validateAdditionalFields($this->submittedData, $this);
1372 }
1373 }
1374 return $result;
1375 }
1376
1377 /*************************
1378 *
1379 * APPLICATION LOGIC UTILITIES
1380 *
1381 *************************/
1382 /**
1383 * This method is used to add a message to the internal queue
1384 *
1385 * @param string $message The message itself
1386 * @param int $severity Message level (according to FlashMessage class constants)
1387 * @return void
1388 */
1389 public function addMessage($message, $severity = FlashMessage::OK)
1390 {
1391 $this->moduleTemplate->addFlashMessage($message, '', $severity);
1392 }
1393
1394 /**
1395 * This method fetches a list of all classes that have been registered with the Scheduler
1396 * For each item the following information is provided, as an associative array:
1397 *
1398 * ['extension'] => Key of the extension which provides the class
1399 * ['filename'] => Path to the file containing the class
1400 * ['title'] => String (possibly localized) containing a human-readable name for the class
1401 * ['provider'] => Name of class that implements the interface for additional fields, if necessary
1402 *
1403 * The name of the class itself is used as the key of the list array
1404 *
1405 * @return array List of registered classes
1406 */
1407 protected function getRegisteredClasses()
1408 {
1409 $list = [];
1410 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'])) {
1411 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'] as $class => $registrationInformation) {
1412 $title = isset($registrationInformation['title']) ? $this->getLanguageService()->sL($registrationInformation['title']) : '';
1413 $description = isset($registrationInformation['description']) ? $this->getLanguageService()->sL($registrationInformation['description']) : '';
1414 $list[$class] = [
1415 'extension' => $registrationInformation['extension'],
1416 'title' => $title,
1417 'description' => $description,
1418 'provider' => isset($registrationInformation['additionalFields']) ? $registrationInformation['additionalFields'] : ''
1419 ];
1420 }
1421 }
1422 return $list;
1423 }
1424
1425 /**
1426 * This method fetches list of all group that have been registered with the Scheduler
1427 *
1428 * @return array List of registered groups
1429 */
1430 protected function getRegisteredTaskGroups()
1431 {
1432 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1433 ->getQueryBuilderForTable('tx_scheduler_task_group');
1434
1435 return $queryBuilder
1436 ->select('*')
1437 ->from('tx_scheduler_task_group')
1438 ->orderBy('sorting')
1439 ->execute()
1440 ->fetchAll();
1441 }
1442
1443 /*************************
1444 *
1445 * RENDERING UTILITIES
1446 *
1447 *************************/
1448 /**
1449 * Gets the filled markers that are used in the HTML template.
1450 *
1451 * @return array The filled marker array
1452 */
1453 protected function getTemplateMarkers()
1454 {
1455 return [
1456 'CONTENT' => $this->content,
1457 'TITLE' => $this->getLanguageService()->getLL('title')
1458 ];
1459 }
1460
1461 /**
1462 * Create the panel of buttons for submitting the form or otherwise perform operations.
1463 */
1464 protected function getButtons()
1465 {
1466 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
1467 // CSH
1468 $helpButton = $buttonBar->makeHelpButton()
1469 ->setModuleName('_MOD_' . $this->moduleName)
1470 ->setFieldName('');
1471 $buttonBar->addButton($helpButton);
1472 // Add and Reload
1473 if (empty($this->CMD) || $this->CMD === 'list' || $this->CMD === 'delete' || $this->CMD === 'stop' || $this->CMD === 'toggleHidden' || $this->CMD === 'setNextExecutionTime') {
1474 $reloadButton = $buttonBar->makeLinkButton()
1475 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload'))
1476 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL))
1477 ->setHref($this->moduleUri);
1478 $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1479 if ($this->MOD_SETTINGS['function'] === 'scheduler' && !empty($this->getRegisteredClasses())) {
1480 $addButton = $buttonBar->makeLinkButton()
1481 ->setTitle($this->getLanguageService()->getLL('action.add'))
1482 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL))
1483 ->setHref($this->moduleUri . '&CMD=add');
1484 $buttonBar->addButton($addButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
1485 }
1486 }
1487 // Close and Save
1488 if ($this->CMD === 'add' || $this->CMD === 'edit') {
1489 // Close
1490 $closeButton = $buttonBar->makeLinkButton()
1491 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:cancel'))
1492 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-close', Icon::SIZE_SMALL))
1493 ->setOnClick('document.location=' . GeneralUtility::quoteJSvalue($this->moduleUri))
1494 ->setHref('#');
1495 $buttonBar->addButton($closeButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
1496 // Save, SaveAndClose, SaveAndNew
1497 $saveButtonDropdown = $buttonBar->makeSplitButton();
1498 $saveButton = $buttonBar->makeInputButton()
1499 ->setName('CMD')
1500 ->setValue('save')
1501 ->setForm('tx_scheduler_form')
1502 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL))
1503 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:save'));
1504 $saveButtonDropdown->addItem($saveButton);
1505 $saveAndNewButton = $buttonBar->makeInputButton()
1506 ->setName('CMD')
1507 ->setValue('savenew')
1508 ->setForm('tx_scheduler_form')
1509 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save-new', Icon::SIZE_SMALL))
1510 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:saveAndCreateNewDoc'));
1511 $saveButtonDropdown->addItem($saveAndNewButton);
1512 $saveAndCloseButton = $buttonBar->makeInputButton()
1513 ->setName('CMD')
1514 ->setValue('saveclose')
1515 ->setForm('tx_scheduler_form')
1516 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save-close', Icon::SIZE_SMALL))
1517 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:saveAndClose'));
1518 $saveButtonDropdown->addItem($saveAndCloseButton);
1519 $buttonBar->addButton($saveButtonDropdown, ButtonBar::BUTTON_POSITION_LEFT, 3);
1520 }
1521 // Edit
1522 if ($this->CMD === 'edit') {
1523 $deleteButton = $buttonBar->makeInputButton()
1524 ->setName('CMD')
1525 ->setValue('delete')
1526 ->setForm('tx_scheduler_form')
1527 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL))
1528 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:delete'));
1529 $buttonBar->addButton($deleteButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
1530 }
1531 // Shortcut
1532 $shortcutButton = $buttonBar->makeShortcutButton()
1533 ->setModuleName($this->moduleName)
1534 ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
1535 ->setSetVariables(['function']);
1536 $buttonBar->addButton($shortcutButton);
1537 }
1538
1539 /**
1540 * @return string
1541 */
1542 protected function getServerTime()
1543 {
1544 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' T (e';
1545 return date($dateFormat) . ', GMT ' . date('P') . ')';
1546 }
1547
1548 /**
1549 * Returns the global BackendUserAuthentication object.
1550 *
1551 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1552 */
1553 protected function getBackendUser()
1554 {
1555 return $GLOBALS['BE_USER'];
1556 }
1557 }