018b9219927210a233c025e4078e23e619cfbdb6
[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\Backend\Utility\BackendUtility;
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\Reports\Status;
22
23 /**
24 * Provides an installation status report.
25 */
26 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
27 {
28 /**
29 * Compiles a collection of system status checks as a status report.
30 *
31 * @return Status[]
32 */
33 public function getStatus()
34 {
35 return [
36 'FileSystem' => $this->getFileSystemStatus(),
37 'RemainingUpdates' => $this->getRemainingUpdatesStatus(),
38 'NewVersion' => $this->getNewVersionStatus(),
39 ];
40 }
41
42 /**
43 * Checks for several directories being writable.
44 *
45 * @return Status Indicates status of the file system
46 */
47 protected function getFileSystemStatus()
48 {
49 $languageService = $this->getLanguageService();
50 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
51 $message = '';
52 $severity = Status::OK;
53 // Requirement level
54 // -1 = not required, but if it exists may be writable or not
55 // 0 = not required, if it exists the dir should be writable
56 // 1 = required, don't has to be writable
57 // 2 = required, has to be writable
58 $checkWritable = [
59 'typo3temp/' => 2,
60 'typo3temp/assets/' => 2,
61 'typo3temp/assets/compressed/' => 2,
62 // only needed when GraphicalFunctions is used
63 'typo3temp/assets/images/' => 0,
64 // used in PageGenerator (inlineStyle2Temp) and Backend + Language JS files
65 'typo3temp/assets/css/' => 2,
66 'typo3temp/assets/js/' => 2,
67 // fallback storage of FAL
68 'typo3temp/assets/_processed_/' => 0,
69 'typo3temp/var/' => 2,
70 'typo3temp/var/transient/' => 2,
71 'typo3temp/var/charset/' => 2,
72 'typo3temp/var/locks/' => 2,
73 'typo3conf/' => 2,
74 'typo3conf/ext/' => 0,
75 'typo3conf/l10n/' => 0,
76 'uploads/' => 2,
77 'uploads/media/' => 0,
78 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
79 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0,
80 ];
81
82 if ($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall']) {
83 $checkWritable[TYPO3_mainDir . 'ext/'] = -1;
84 }
85
86 foreach ($checkWritable as $relPath => $requirementLevel) {
87 if (!@is_dir(PATH_site . $relPath)) {
88 // If the directory is missing, try to create it
89 GeneralUtility::mkdir(PATH_site . $relPath);
90 }
91 if (!@is_dir(PATH_site . $relPath)) {
92 if ($requirementLevel > 0) {
93 // directory is required
94 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
95 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
96 $severity = Status::ERROR;
97 } else {
98 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
99 if ($requirementLevel == 0) {
100 $message .= ' ' . $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
101 }
102 $message .= '<br />';
103 if ($severity < Status::WARNING) {
104 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
105 $severity = Status::WARNING;
106 }
107 }
108 } else {
109 if (!is_writable((PATH_site . $relPath))) {
110 switch ($requirementLevel) {
111 case 0:
112 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
113 if ($severity < Status::WARNING) {
114 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
115 $severity = Status::WARNING;
116 }
117 break;
118 case 2:
119 $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
120 $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
121 $severity = Status::ERROR;
122 break;
123 default:
124 }
125 }
126 }
127 }
128 return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
129 }
130
131 /**
132 * Checks if there are still updates to perform
133 *
134 * @return Status Represents whether the installation is completely updated yet
135 */
136 protected function getRemainingUpdatesStatus()
137 {
138 $languageService = $this->getLanguageService();
139 $value = $languageService->getLL('status_updateComplete');
140 $message = '';
141 $severity = Status::OK;
142
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 = BackendUtility::getModuleUrl('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 }