05b0898404e852b10b916f3a5ee6dcdd52ea9db1
[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\Core\Environment;
18 use TYPO3\CMS\Core\Localization\LanguageService;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Install\Service\Exception;
21 use TYPO3\CMS\Install\Service\UpgradeWizardsService;
22 use TYPO3\CMS\Reports\Status;
23
24 /**
25 * Provides an installation status report.
26 * @internal This class is only meant to be used within EXT:install and is not part of the TYPO3 Core API.
27 */
28 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
29 {
30 /**
31 * Compiles a collection of system status checks as a status report.
32 *
33 * @return Status[]
34 */
35 public function getStatus()
36 {
37 return [
38 'FileSystem' => $this->getFileSystemStatus(),
39 'RemainingUpdates' => $this->getRemainingUpdatesStatus(),
40 'NewVersion' => $this->getNewVersionStatus(),
41 ];
42 }
43
44 /**
45 * Checks for several directories being writable.
46 *
47 * @return Status Indicates status of the file system
48 */
49 protected function getFileSystemStatus()
50 {
51 $languageService = $this->getLanguageService();
52 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
53 $message = '';
54 $severity = Status::OK;
55 // Requirement level
56 // -1 = not required, but if it exists may be writable or not
57 // 0 = not required, if it exists the dir should be writable
58 // 1 = required, doesn't have to be writable
59 // 2 = required, has to be writable
60 $varPath = Environment::getVarPath();
61 $sitePath = Environment::getPublicPath();
62 $rootPath = Environment::getProjectPath();
63 $checkWritable = [
64 $sitePath . '/typo3temp/' => 2,
65 $sitePath . '/typo3temp/assets/' => 2,
66 $sitePath . '/typo3temp/assets/compressed/' => 2,
67 // only needed when GraphicalFunctions is used
68 $sitePath . '/typo3temp/assets/images/' => 0,
69 // used in PageGenerator (inlineStyle2Temp) and Backend + Language JS files
70 $sitePath . '/typo3temp/assets/css/' => 2,
71 $sitePath . '/typo3temp/assets/js/' => 2,
72 // fallback storage of FAL
73 $sitePath . '/typo3temp/assets/_processed_/' => 0,
74 $varPath => 2,
75 $varPath . '/transient/' => 2,
76 $varPath . '/charset/' => 2,
77 $varPath . '/lock/' => 2,
78 $sitePath . '/typo3conf/' => 2,
79 Environment::getExtensionsPath() => 0,
80 Environment::getLabelsPath() => 0,
81 $sitePath . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
82 $sitePath . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0,
83 ];
84
85 if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall']) {
86 $checkWritable[Environment::getBackendPath() . '/ext/'] = -1;
87 }
88
89 foreach ($checkWritable as $path => $requirementLevel) {
90 $relPath = substr($path, strlen($rootPath) + 1);
91 if (!@is_dir($path)) {
92 // If the directory is missing, try to create it
93 GeneralUtility::mkdir($path);
94 }
95 if (!@is_dir($path)) {
96 if ($requirementLevel > 0) {
97 // directory is required
98 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
99 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
100 $severity = Status::ERROR;
101 } else {
102 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
103 if ($requirementLevel == 0) {
104 $message .= ' ' . $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
105 }
106 $message .= '<br />';
107 if ($severity < Status::WARNING) {
108 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
109 $severity = Status::WARNING;
110 }
111 }
112 } else {
113 if (!is_writable($path)) {
114 switch ($requirementLevel) {
115 case 0:
116 $message .= sprintf(
117 $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'),
118 $path
119 ) . '<br />';
120 if ($severity < Status::WARNING) {
121 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
122 $severity = Status::WARNING;
123 }
124 break;
125 case 2:
126 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
127 $message .= sprintf(
128 $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'),
129 $path
130 ) . '<br />';
131 $severity = Status::ERROR;
132 break;
133 default:
134 }
135 }
136 }
137 }
138 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
139 }
140
141 /**
142 * Checks if there are still updates to perform
143 *
144 * @return Status Represents whether the installation is completely updated yet
145 */
146 protected function getRemainingUpdatesStatus()
147 {
148 $languageService = $this->getLanguageService();
149 $value = $languageService->getLL('status_updateComplete');
150 $message = '';
151 $severity = Status::OK;
152 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
153 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
154 // check if there are update wizards left to perform
155 $upgradeWizardsService = GeneralUtility::makeInstance(UpgradeWizardsService::class);
156 $incompleteWizards = $upgradeWizardsService->getUpgradeWizardsList();
157 if (count($incompleteWizards)) {
158 // At least one incomplete wizard was found
159 $value = $languageService->getLL('status_updateIncomplete');
160 $severity = Status::WARNING;
161 $url = (string)$uriBuilder->buildUriFromRoute('tools_toolsupgrade');
162 $message = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.install_update'), '<a href="' . htmlspecialchars($url) . '">', '</a>');
163 }
164
165 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
166 }
167
168 /**
169 * Checks if there is a new minor TYPO3 version to update to.
170 *
171 * @return Status Represents whether there is a new version available online
172 */
173 protected function getNewVersionStatus()
174 {
175 $languageService = $this->getLanguageService();
176 /** @var \TYPO3\CMS\Install\Service\CoreVersionService $coreVersionService */
177 $coreVersionService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\CoreVersionService::class);
178
179 // No updates for development versions
180 if (!$coreVersionService->isInstalledVersionAReleasedVersion()) {
181 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_isDevelopmentVersion'), Status::NOTICE);
182 }
183
184 try {
185 $isUpdateAvailable = $coreVersionService->isYoungerPatchReleaseAvailable();
186 $isMaintainedVersion = $coreVersionService->isVersionActivelyMaintained();
187 } catch (Exception\RemoteFetchException $remoteFetchException) {
188 return GeneralUtility::makeInstance(
189 Status::class,
190 'TYPO3',
191 TYPO3_version,
192 $languageService->sL(
193 'LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remoteFetchException'
194 ),
195 Status::NOTICE
196 );
197 }
198
199 if (!$isUpdateAvailable && $isMaintainedVersion) {
200 // Everything is fine, working with the latest version
201 $message = '';
202 $status = Status::OK;
203 } elseif ($isUpdateAvailable) {
204 // There is an update available
205 $newVersion = $coreVersionService->getYoungestPatchRelease();
206 if ($coreVersionService->isUpdateSecurityRelevant()) {
207 $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersionSecurityRelevant'), $newVersion);
208 $status = Status::ERROR;
209 } else {
210 $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersion'), $newVersion);
211 $status = Status::WARNING;
212 }
213 } else {
214 // Version is not maintained
215 $message = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_versionOutdated');
216 $status = Status::ERROR;
217 }
218
219 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $message, $status);
220 }
221
222 /**
223 * @return LanguageService
224 */
225 protected function getLanguageService()
226 {
227 return $GLOBALS['LANG'];
228 }
229 }