[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Report / InstallStatusReport.php
1 <?php
2 namespace TYPO3\CMS\Install\Report;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Localization\LanguageService;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Install\Service\Exception;
20 use TYPO3\CMS\Reports\Status;
21
22 /**
23 * Provides an installation status report.
24 */
25 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
26 {
27 /**
28 * Compiles a collection of system status checks as a status report.
29 *
30 * @return Status[]
31 */
32 public function getStatus()
33 {
34 return [
35 'FileSystem' => $this->getFileSystemStatus(),
36 'RemainingUpdates' => $this->getRemainingUpdatesStatus(),
37 'NewVersion' => $this->getNewVersionStatus(),
38 ];
39 }
40
41 /**
42 * Checks for several directories being writable.
43 *
44 * @return Status Indicates status of the file system
45 */
46 protected function getFileSystemStatus()
47 {
48 $languageService = $this->getLanguageService();
49 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
50 $message = '';
51 $severity = Status::OK;
52 // Requirement level
53 // -1 = not required, but if it exists may be writable or not
54 // 0 = not required, if it exists the dir should be writable
55 // 1 = required, don't has to be writable
56 // 2 = required, has to be writable
57 $checkWritable = [
58 'typo3temp/' => 2,
59 'typo3temp/assets/' => 2,
60 'typo3temp/assets/compressed/' => 2,
61 // only needed when GraphicalFunctions is used
62 'typo3temp/assets/images/' => 0,
63 // used in PageGenerator (inlineStyle2Temp) and Backend + Language JS files
64 'typo3temp/assets/css/' => 2,
65 'typo3temp/assets/js/' => 2,
66 // fallback storage of FAL
67 'typo3temp/assets/_processed_/' => 0,
68 'typo3temp/var/' => 2,
69 'typo3temp/var/transient/' => 2,
70 'typo3temp/var/charset/' => 2,
71 'typo3temp/var/locks/' => 2,
72 'typo3conf/' => 2,
73 'typo3conf/ext/' => 0,
74 'typo3conf/l10n/' => 0,
75 'uploads/' => 2,
76 'uploads/media/' => 0,
77 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
78 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0,
79 ];
80
81 if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall']) {
82 $checkWritable[TYPO3_mainDir . 'ext/'] = -1;
83 }
84
85 foreach ($checkWritable as $relPath => $requirementLevel) {
86 if (!@is_dir(PATH_site . $relPath)) {
87 // If the directory is missing, try to create it
88 GeneralUtility::mkdir(PATH_site . $relPath);
89 }
90 if (!@is_dir(PATH_site . $relPath)) {
91 if ($requirementLevel > 0) {
92 // directory is required
93 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
94 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
95 $severity = Status::ERROR;
96 } else {
97 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
98 if ($requirementLevel == 0) {
99 $message .= ' ' . $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
100 }
101 $message .= '<br />';
102 if ($severity < Status::WARNING) {
103 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
104 $severity = Status::WARNING;
105 }
106 }
107 } else {
108 if (!is_writable((PATH_site . $relPath))) {
109 switch ($requirementLevel) {
110 case 0:
111 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
112 if ($severity < Status::WARNING) {
113 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
114 $severity = Status::WARNING;
115 }
116 break;
117 case 2:
118 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
119 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
120 $severity = Status::ERROR;
121 break;
122 default:
123 }
124 }
125 }
126 }
127 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
128 }
129
130 /**
131 * Checks if there are still updates to perform
132 *
133 * @return Status Represents whether the installation is completely updated yet
134 */
135 protected function getRemainingUpdatesStatus()
136 {
137 $languageService = $this->getLanguageService();
138 $value = $languageService->getLL('status_updateComplete');
139 $message = '';
140 $severity = Status::OK;
141 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
142 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
143 // check if there are update wizards left to perform
144 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'])) {
145 $versionAsInt = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
146 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] as $identifier => $className) {
147 $updateObject = GeneralUtility::makeInstance($className, $identifier, $versionAsInt, null, $this);
148 if ($updateObject->shouldRenderWizard()) {
149 // at least one wizard was found
150 $value = $languageService->getLL('status_updateIncomplete');
151 $severity = Status::WARNING;
152 $url = (string)$uriBuilder->buildUriFromRoute('tools_toolsupgrade');
153 $message = sprintf($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.install_update'), '<a href="' . htmlspecialchars($url) . '">', '</a>');
154 break;
155 }
156 }
157 }
158
159 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
160 }
161
162 /**
163 * Checks if there is a new minor TYPO3 version to update to.
164 *
165 * @return Status Represents whether there is a new version available online
166 */
167 protected function getNewVersionStatus()
168 {
169 $languageService = $this->getLanguageService();
170 /** @var \TYPO3\CMS\Install\Service\CoreVersionService $coreVersionService */
171 $coreVersionService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\CoreVersionService::class);
172
173 // No updates for development versions
174 if (!$coreVersionService->isInstalledVersionAReleasedVersion()) {
175 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_isDevelopmentVersion'), Status::NOTICE);
176 }
177
178 // If fetching version matrix fails we can not do anything except print out the current version
179 try {
180 $coreVersionService->updateVersionMatrix();
181 } catch (Exception\RemoteFetchException $remoteFetchException) {
182 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remoteFetchException'), Status::NOTICE);
183 }
184
185 try {
186 $isUpdateAvailable = $coreVersionService->isYoungerPatchReleaseAvailable();
187 $isMaintainedVersion = $coreVersionService->isVersionActivelyMaintained();
188 } catch (Exception\CoreVersionServiceException $coreVersionServiceException) {
189 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_patchLevelNotFoundInReleaseMatrix'), Status::WARNING);
190 }
191
192 if (!$isUpdateAvailable && $isMaintainedVersion) {
193 // Everything is fine, working with the latest version
194 $message = '';
195 $status = Status::OK;
196 } elseif ($isUpdateAvailable) {
197 // There is an update available
198 $newVersion = $coreVersionService->getYoungestPatchRelease();
199 if ($coreVersionService->isUpdateSecurityRelevant()) {
200 $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersionSecurityRelevant'), $newVersion);
201 $status = Status::ERROR;
202 } else {
203 $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersion'), $newVersion);
204 $status = Status::WARNING;
205 }
206 } else {
207 // Version is not maintained
208 $message = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_versionOutdated');
209 $status = Status::ERROR;
210 }
211
212 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $message, $status);
213 }
214
215 /**
216 * @return LanguageService
217 */
218 protected function getLanguageService()
219 {
220 return $GLOBALS['LANG'];
221 }
222 }