8e2e06a1765f2275ced8d17da7365c52a76c753c
[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::getLabelsPath() => 0,
80 $sitePath . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
81 $sitePath . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0,
82 ];
83
84 // Check for writable extension folder files in non-composer mode only
85 if (!Environment::isComposerMode()) {
86 $checkWritable[Environment::getExtensionsPath()] = 0;
87 if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall']) {
88 $checkWritable[Environment::getBackendPath() . '/ext/'] = -1;
89 }
90 }
91
92 foreach ($checkWritable as $path => $requirementLevel) {
93 $relPath = substr($path, strlen($rootPath) + 1);
94 if (!@is_dir($path)) {
95 // If the directory is missing, try to create it
96 GeneralUtility::mkdir($path);
97 }
98 if (!@is_dir($path)) {
99 if ($requirementLevel > 0) {
100 // directory is required
101 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
102 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
103 $severity = Status::ERROR;
104 } else {
105 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
106 if ($requirementLevel == 0) {
107 $message .= ' ' . $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
108 }
109 $message .= '<br />';
110 if ($severity < Status::WARNING) {
111 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
112 $severity = Status::WARNING;
113 }
114 }
115 } else {
116 if (!is_writable($path)) {
117 switch ($requirementLevel) {
118 case 0:
119 $message .= sprintf(
120 $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'),
121 $path
122 ) . '<br />';
123 if ($severity < Status::WARNING) {
124 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
125 $severity = Status::WARNING;
126 }
127 break;
128 case 2:
129 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
130 $message .= sprintf(
131 $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'),
132 $path
133 ) . '<br />';
134 $severity = Status::ERROR;
135 break;
136 default:
137 }
138 }
139 }
140 }
141 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
142 }
143
144 /**
145 * Checks if there are still updates to perform
146 *
147 * @return Status Represents whether the installation is completely updated yet
148 */
149 protected function getRemainingUpdatesStatus()
150 {
151 $languageService = $this->getLanguageService();
152 $value = $languageService->getLL('status_updateComplete');
153 $message = '';
154 $severity = Status::OK;
155 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
156 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
157 // check if there are update wizards left to perform
158 $upgradeWizardsService = GeneralUtility::makeInstance(UpgradeWizardsService::class);
159 $incompleteWizards = $upgradeWizardsService->getUpgradeWizardsList();
160 if (count($incompleteWizards)) {
161 // At least one incomplete wizard was found
162 $value = $languageService->getLL('status_updateIncomplete');
163 $severity = Status::WARNING;
164 $url = (string)$uriBuilder->buildUriFromRoute('tools_toolsupgrade');
165 $message = sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.install_update'), '<a href="' . htmlspecialchars($url) . '">', '</a>');
166 }
167
168 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
169 }
170
171 /**
172 * Checks if there is a new minor TYPO3 version to update to.
173 *
174 * @return Status Represents whether there is a new version available online
175 */
176 protected function getNewVersionStatus()
177 {
178 $languageService = $this->getLanguageService();
179 /** @var \TYPO3\CMS\Install\Service\CoreVersionService $coreVersionService */
180 $coreVersionService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\CoreVersionService::class);
181
182 // No updates for development versions
183 if (!$coreVersionService->isInstalledVersionAReleasedVersion()) {
184 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_isDevelopmentVersion'), Status::NOTICE);
185 }
186
187 try {
188 $isUpdateAvailable = $coreVersionService->isYoungerPatchReleaseAvailable();
189 $isMaintainedVersion = $coreVersionService->isVersionActivelyMaintained();
190 } catch (Exception\RemoteFetchException $remoteFetchException) {
191 return GeneralUtility::makeInstance(
192 Status::class,
193 'TYPO3',
194 TYPO3_version,
195 $languageService->sL(
196 'LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remoteFetchException'
197 ),
198 Status::NOTICE
199 );
200 }
201
202 if (!$isUpdateAvailable && $isMaintainedVersion) {
203 // Everything is fine, working with the latest version
204 $message = '';
205 $status = Status::OK;
206 } elseif ($isUpdateAvailable) {
207 // There is an update available
208 $newVersion = $coreVersionService->getYoungestPatchRelease();
209 if ($coreVersionService->isUpdateSecurityRelevant()) {
210 $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersionSecurityRelevant'), $newVersion);
211 $status = Status::ERROR;
212 } else {
213 $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersion'), $newVersion);
214 $status = Status::WARNING;
215 }
216 } else {
217 // Version is not maintained
218 $message = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_versionOutdated');
219 $status = Status::ERROR;
220 }
221
222 return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $message, $status);
223 }
224
225 /**
226 * @return LanguageService
227 */
228 protected function getLanguageService()
229 {
230 return $GLOBALS['LANG'];
231 }
232 }