‪TYPO3CMS  10.4
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 
28 
33 {
39  protected ‪$lastRunInformation = [];
40 
44  public function ‪__construct()
45  {
46  $this->lastRunInformation = GeneralUtility::makeInstance(Registry::class)->get('tx_scheduler', 'lastRun', []);
47  }
48 
49  public function ‪getItem(‪SystemInformationToolbarCollectorEvent $event): void
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  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
58 
59  if (!$this->‪schedulerWasExecuted()) {
60  // Display system message if the Scheduler has never yet run
61  $systemInformationToolbarItem->addSystemMessage(
62  sprintf(
63  $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systemmessage.noLastRun'),
64  (string)$uriBuilder->buildUriFromRoute(
65  'system_txschedulerM1',
66  [
67  'id' => 0,
68  'SET' => [
69  'function' => 'check'
70  ]
71  ]
72  )
73  ),
75  0,
76  'system_txschedulerM1',
77  http_build_query([
78  'id' => 0,
79  'SET' => [
80  'function' => 'check'
81  ]
82  ])
83  );
84  } else {
85  // Display information about the last Scheduler execution
86  if (!$this->‪lastRunInfoExists()) {
87  // Show warning if the information of the last run is incomplete
88  $message = $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.incompleteLastRun');
90  } else {
91  $startDate = date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $this->lastRunInformation['start']);
92  $startTime = date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $this->lastRunInformation['start']);
93  $duration = ‪BackendUtility::calcAge(
94  $this->lastRunInformation['end'] - $this->lastRunInformation['start'],
95  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
96  );
97  $severity = '';
98  $label = 'automatically';
99  if ($this->lastRunInformation['type'] === 'manual') {
100  $label = 'manually';
102  }
103  $type = $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.' . $label);
104  $message = sprintf($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systeminformation.lastRunValue'), $startDate, $startTime, $duration, $type);
105  }
106  $systemInformationToolbarItem->addSystemInformation(
107  $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systeminformation.lastRunLabel'),
108  $message,
109  'actions-play',
110  $severity
111  );
112  }
113  }
114 
120  private function ‪schedulerWasExecuted(): bool
121  {
122  return !empty($this->lastRunInformation);
123  }
124 
130  private function ‪lastRunInfoExists(): bool
131  {
132  return !empty($this->lastRunInformation['end'])
133  || !empty($this->lastRunInformation['start'])
134  || !empty($this->lastRunInformation['type']);
135  }
136 
142  private function ‪hasConfiguredTasks(): bool
143  {
144  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_scheduler_task');
145  $queryBuilder->getRestrictions()->removeAll();
146  $queryBuilder
147  ->count('uid')
148  ->from('tx_scheduler_task')
149  ->where(
150  $queryBuilder->expr()->eq('deleted', 0)
151  );
152  return $queryBuilder->execute()->fetchColumn() > 0;
153  }
154 
158  private function ‪getLanguageService(): LanguageService
159  {
160  return ‪$GLOBALS['LANG'];
161  }
162 }
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_INFO
‪const STATUS_INFO
Definition: InformationStatus.php:35
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent
Definition: SystemInformationToolbarCollectorEvent.php:27
‪TYPO3\CMS\Backend\Utility\BackendUtility\calcAge
‪static string calcAge($seconds, $labels='min|hrs|days|yrs|min|hour|day|year')
Definition: BackendUtility.php:1017
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider
Definition: ToolbarItemProvider.php:33
‪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\getLanguageService
‪LanguageService getLanguageService()
Definition: ToolbarItemProvider.php:157
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_WARNING
‪const STATUS_WARNING
Definition: InformationStatus.php:45
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\getItem
‪getItem(SystemInformationToolbarCollectorEvent $event)
Definition: ToolbarItemProvider.php:48
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\schedulerWasExecuted
‪bool schedulerWasExecuted()
Definition: ToolbarItemProvider.php:119
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\lastRunInfoExists
‪bool lastRunInfoExists()
Definition: ToolbarItemProvider.php:129
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus
Definition: InformationStatus.php:24
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\hasConfiguredTasks
‪bool hasConfiguredTasks()
Definition: ToolbarItemProvider.php:141
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent\getToolbarItem
‪getToolbarItem()
Definition: SystemInformationToolbarCollectorEvent.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Scheduler\SystemInformation\ToolbarItemProvider\__construct
‪__construct()
Definition: ToolbarItemProvider.php:43
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46