lastRunInformation = $registry->get('tx_scheduler', 'lastRun', []); } #[AsEventListener('scheduler/show-latest-errors')] public function getItem(SystemInformationToolbarCollectorEvent $event): void { $systemInformationToolbarItem = $event->getToolbarItem(); // No tasks configured, so nothing is shown at all if (!$this->hasConfiguredTasks()) { return; } $languageService = $this->getLanguageService(); if (!$this->schedulerWasExecuted()) { // Display system message if the Scheduler has never yet run $moduleIdentifier = 'scheduler'; $systemInformationToolbarItem->addSystemMessage( sprintf( $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systemmessage.noLastRun'), (string)$this->uriBuilder->buildUriFromRoute($moduleIdentifier) ), InformationStatus::WARNING, 1, $moduleIdentifier, ); } else { // Display information about the last Scheduler execution if (!$this->lastRunInfoExists()) { // Show warning if the information of the last run is incomplete $message = $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.incompleteLastRun'); $severity = InformationStatus::WARNING; } else { $start = DateTimeFactory::createFromTimestamp($this->lastRunInformation['start']); $end = DateTimeFactory::createFromTimestamp($this->lastRunInformation['end']); $startDate = $start->format($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']); $startTime = $start->format($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']); $duration = (new DateFormatter())->formatDateInterval( $end->diff($start, true), $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears') ); $severity = InformationStatus::NOTICE; $label = 'automatically'; if ($this->lastRunInformation['type'] === 'manual') { $label = 'manually'; } $type = $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.' . $label); $message = sprintf($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systeminformation.lastRunValue'), $startDate, $startTime, $duration, $type); } $systemInformationToolbarItem->addSystemInformation( 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:systeminformation.lastRunLabel', $message, 'actions-play', $severity ); } } /** * Check whether the scheduler was already executed */ private function schedulerWasExecuted(): bool { return !empty($this->lastRunInformation); } /** * Check if the last scheduler run array contains all information */ private function lastRunInfoExists(): bool { return !empty($this->lastRunInformation['end']) || !empty($this->lastRunInformation['start']) || !empty($this->lastRunInformation['type']); } /** * See if there are any tasks configured at all. */ private function hasConfiguredTasks(): bool { return GeneralUtility::makeInstance(SchedulerTaskRepository::class)->hasTasks(); } private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }