‪TYPO3CMS  ‪main
ToolbarItemProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
29 
34 {
38  protected array ‪$lastRunInformation = [];
39 
43  public function ‪__construct()
44  {
45  $this->lastRunInformation = GeneralUtility::makeInstance(Registry::class)->get('tx_scheduler', 'lastRun', []);
46  }
47 
48  #[AsEventListener('scheduler/show-latest-errors')]
50  {
51  $systemInformationToolbarItem = $event->‪getToolbarItem();
52  // No tasks configured, so nothing is shown at all
53  if (!$this->‪hasConfiguredTasks()) {
54  return;
55  }
56  $languageService = $this->‪getLanguageService();
57 
58  if (!$this->‪schedulerWasExecuted()) {
59  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
60  // Display system message if the Scheduler has never yet run
61  $moduleIdentifier = 'scheduler_setupcheck';
62  $systemInformationToolbarItem->addSystemMessage(
63  sprintf(
64  $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systemmessage.noLastRun'),
65  (string)$uriBuilder->buildUriFromRoute($moduleIdentifier)
66  ),
67  InformationStatus::WARNING,
68  1,
69  $moduleIdentifier,
70  );
71  } else {
72  // Display information about the last Scheduler execution
73  if (!$this->‪lastRunInfoExists()) {
74  // Show warning if the information of the last run is incomplete
75  $message = $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.incompleteLastRun');
76  $severity = InformationStatus::WARNING;
77  } else {
78  $startDate = date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $this->lastRunInformation['start']);
79  $startTime = date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $this->lastRunInformation['start']);
80  $duration = BackendUtility::calcAge(
81  $this->lastRunInformation['end'] - $this->lastRunInformation['start'],
82  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
83  );
84  $severity = InformationStatus::NOTICE;
85  $label = 'automatically';
86  if ($this->lastRunInformation['type'] === 'manual') {
87  $label = 'manually';
88  $severity = InformationStatus::INFO;
89  }
90  $type = $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.' . $label);
91  $message = sprintf($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systeminformation.lastRunValue'), $startDate, $startTime, $duration, $type);
92  }
93  $systemInformationToolbarItem->addSystemInformation(
94  'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systeminformation.lastRunLabel',
95  $message,
96  'actions-play',
97  $severity
98  );
99  }
100  }
101 
105  private function ‪schedulerWasExecuted(): bool
106  {
107  return !empty($this->lastRunInformation);
108  }
109 
113  private function ‪lastRunInfoExists(): bool
114  {
115  return !empty($this->lastRunInformation['end'])
116  || !empty($this->lastRunInformation['start'])
117  || !empty($this->lastRunInformation['type']);
118  }
119 
123  private function ‪hasConfiguredTasks(): bool
124  {
125  return GeneralUtility::makeInstance(SchedulerTaskRepository::class)->hasTasks();
126  }
127 
129  {
130  return ‪$GLOBALS['LANG'];
131  }
132 }
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\schedulerWasExecuted
‪schedulerWasExecuted()
Definition: ToolbarItemProvider.php:105
‪TYPO3\CMS\Core\Attribute\AsEventListener
Definition: AsEventListener.php:25
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent
Definition: SystemInformationToolbarCollectorEvent.php:27
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Scheduler\Domain\Repository\SchedulerTaskRepository
Definition: SchedulerTaskRepository.php:36
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider
Definition: ToolbarItemProvider.php:34
‪TYPO3\CMS\Backend\Toolbar\InformationStatus
‪InformationStatus
Definition: InformationStatus.php:24
‪TYPO3\CMS\Scheduler\SystemInformation
Definition: ToolbarItemProvider.php:18
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\$lastRunInformation
‪array $lastRunInformation
Definition: ToolbarItemProvider.php:38
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\hasConfiguredTasks
‪hasConfiguredTasks()
Definition: ToolbarItemProvider.php:123
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\getItem
‪getItem(SystemInformationToolbarCollectorEvent $event)
Definition: ToolbarItemProvider.php:49
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\getLanguageService
‪getLanguageService()
Definition: ToolbarItemProvider.php:128
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent\getToolbarItem
‪getToolbarItem()
Definition: SystemInformationToolbarCollectorEvent.php:30
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\__construct
‪__construct()
Definition: ToolbarItemProvider.php:43
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\lastRunInfoExists
‪lastRunInfoExists()
Definition: ToolbarItemProvider.php:113
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52