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