‪TYPO3CMS  ‪main
SchedulerSetupCheckController.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 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use ‪TYPO3\CMS\Backend\Attribute\Controller as BackendController;
30 
35 #[BackendController]
37 {
38  public function ‪__construct(
39  private readonly ‪Registry $registry,
40  private readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
41  ) {
42  }
43 
44  public function ‪handle(ServerRequestInterface $request): ResponseInterface
45  {
46  $languageService = $this->‪getLanguageService();
47  $view = $this->moduleTemplateFactory->create($request);
48  $view->assign('dateFormat', [
49  'day' => ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?? 'd-m-y',
50  'time' => ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] ?? 'H:i',
51  ]);
52 
53  // Display information about last automated run, as stored in the system registry.
54  $lastRun = $this->registry->get('tx_scheduler', 'lastRun');
55  $lastRunMessageLabel = 'msg.noLastRun';
56  $lastRunMessageLabelArguments = [];
57  $lastRunSeverity = ‪InfoboxViewHelper::STATE_WARNING;
58  if (is_array($lastRun)) {
59  if (empty($lastRun['end']) || empty($lastRun['start']) || empty($lastRun['type'])) {
60  $lastRunMessageLabel = 'msg.incompleteLastRun';
61  $lastRunSeverity = ‪InfoboxViewHelper::STATE_WARNING;
62  } else {
63  $lastRunMessageLabelArguments = [
64  $lastRun['type'] === 'manual'
65  ? $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.manually')
66  : $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.automatically'),
67  date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['start']),
68  date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['start']),
69  date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $lastRun['end']),
70  date(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $lastRun['end']),
71  ];
72  $lastRunMessageLabel = 'msg.lastRun';
73  $lastRunSeverity = ‪InfoboxViewHelper::STATE_INFO;
74  }
75  }
76 
77  // Information about cli script.
78  $script = $this->‪determineExecutablePath();
79  $isExecutableMessageLabel = 'msg.cliScriptNotExecutable';
80  $isExecutableSeverity = ‪InfoboxViewHelper::STATE_ERROR;
81  $composerMode = !$script && ‪Environment::isComposerMode();
82  if (!$composerMode) {
83  // Check if CLI script is executable or not. Skip this check if running Windows since executable detection
84  // is not reliable on this platform, the script will always appear as *not* executable.
85  $isExecutable = ‪Environment::isWindows() ? true : ($script && is_executable($script));
86  if ($isExecutable) {
87  $isExecutableMessageLabel = 'msg.cliScriptExecutable';
88  $isExecutableSeverity = ‪InfoboxViewHelper::STATE_OK;
89  }
90  }
91 
92  $view->assignMultiple([
93  'composerMode' => $composerMode,
94  'script' => $script,
95  'lastRunMessageLabel' => $lastRunMessageLabel,
96  'lastRunMessageLabelArguments' => $lastRunMessageLabelArguments,
97  'lastRunSeverity' => $lastRunSeverity,
98  'isExecutableMessageLabel' => $isExecutableMessageLabel,
99  'isExecutableSeverity' => $isExecutableSeverity,
100  ]);
101  $view->setTitle(
102  $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
103  $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:function.check')
104  );
105  $view->makeDocHeaderModuleMenu();
106  $this->‪addDocHeaderShortcutButton($view, $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:function.check'));
107  return $view->renderResponse('CheckScreen');
108  }
109 
110  protected function ‪addDocHeaderShortcutButton(‪ModuleTemplate $moduleTemplate, string $name): void
111  {
112  $buttonBar = $moduleTemplate->‪getDocHeaderComponent()->getButtonBar();
113  $shortcutButton = $buttonBar->makeShortcutButton()
114  ->setRouteIdentifier('scheduler_availabletasks')
115  ->setDisplayName($name);
116  $buttonBar->addButton($shortcutButton);
117  }
118 
119  private function ‪determineExecutablePath(): ?string
120  {
122  return GeneralUtility::getFileAbsFileName('EXT:core/bin/typo3');
123  }
124  $composerJsonFile = getenv('TYPO3_PATH_COMPOSER_ROOT') . '/composer.json';
125  if (!file_exists($composerJsonFile) || !($jsonContent = file_get_contents($composerJsonFile))) {
126  return null;
127  }
128  $jsonConfig = @json_decode($jsonContent, true);
129  if (empty($jsonConfig) || !is_array($jsonConfig)) {
130  return null;
131  }
132  $vendorDir = trim($jsonConfig['config']['vendor-dir'] ?? 'vendor', '/');
133  $binDir = trim($jsonConfig['config']['bin-dir'] ?? $vendorDir . '/bin', '/');
134  return sprintf('%s/%s/typo3', getenv('TYPO3_PATH_COMPOSER_ROOT'), $binDir);
135  }
136 
138  {
139  return ‪$GLOBALS['LANG'];
140  }
141 }
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_INFO
‪const STATE_INFO
Definition: InfoboxViewHelper.php:68
‪TYPO3\CMS\Scheduler\Controller
Definition: AvailableSchedulerTasksController.php:18
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Scheduler\Controller\SchedulerSetupCheckController
Definition: SchedulerSetupCheckController.php:37
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Backend\Attribute\Controller
Definition: Controller.php:25
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_ERROR
‪const STATE_ERROR
Definition: InfoboxViewHelper.php:71
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_WARNING
‪const STATE_WARNING
Definition: InfoboxViewHelper.php:70
‪TYPO3\CMS\Scheduler\Controller\SchedulerSetupCheckController\determineExecutablePath
‪determineExecutablePath()
Definition: SchedulerSetupCheckController.php:119
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Scheduler\Controller\SchedulerSetupCheckController\handle
‪handle(ServerRequestInterface $request)
Definition: SchedulerSetupCheckController.php:44
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_OK
‪const STATE_OK
Definition: InfoboxViewHelper.php:69
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪TYPO3\CMS\Scheduler\Controller\SchedulerSetupCheckController\addDocHeaderShortcutButton
‪addDocHeaderShortcutButton(ModuleTemplate $moduleTemplate, string $name)
Definition: SchedulerSetupCheckController.php:110
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper
Definition: InfoboxViewHelper.php:65
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Scheduler\Controller\SchedulerSetupCheckController\getLanguageService
‪getLanguageService()
Definition: SchedulerSetupCheckController.php:137
‪TYPO3\CMS\Scheduler\Controller\SchedulerSetupCheckController\__construct
‪__construct(private readonly Registry $registry, private readonly ModuleTemplateFactory $moduleTemplateFactory,)
Definition: SchedulerSetupCheckController.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static isWindows()
Definition: Environment.php:276