[BUGFIX] Skip main extension repository check in Composer mode
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Report / ExtensionStatus.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\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\Bootstrap;
18
19 /**
20 * Extension status reports
21 */
22 class ExtensionStatus implements \TYPO3\CMS\Reports\StatusProviderInterface
23 {
24 /**
25 * @var string
26 */
27 protected $ok = '';
28
29 /**
30 * @var string
31 */
32 protected $upToDate = '';
33
34 /**
35 * @var string
36 */
37 protected $error = '';
38
39 /**
40 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
41 */
42 protected $objectManager = null;
43
44 /**
45 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
46 */
47 protected $repositoryRepository = null;
48
49 /**
50 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
51 */
52 protected $listUtility = null;
53
54 /**
55 * @var \TYPO3\CMS\Lang\LanguageService
56 */
57 protected $languageService = null;
58
59 /**
60 * Default constructor
61 */
62 public function __construct()
63 {
64 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
65 $this->repositoryRepository = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class);
66 $this->listUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
67 $this->languageService = $this->objectManager->get(\TYPO3\CMS\Lang\LanguageService::class);
68 $this->languageService->includeLLFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
69 }
70
71 /**
72 * Determines extension manager status
73 *
74 * @return array List of statuses
75 */
76 public function getStatus()
77 {
78 $status = [];
79
80 if (!Bootstrap::usesComposerClassLoading()) {
81 $status['mainRepositoryStatus'] = $this->getMainRepositoryStatus();
82 }
83
84 $extensionStatus = $this->getSecurityStatusOfExtensions();
85 $status['extensionsSecurityStatusInstalled'] = $extensionStatus->loaded;
86 $status['extensionsSecurityStatusNotInstalled'] = $extensionStatus->existing;
87 $status['extensionsOutdatedStatusInstalled'] = $extensionStatus->loadedoutdated;
88 $status['extensionsOutdatedStatusNotInstalled'] = $extensionStatus->existingoutdated;
89
90 return $status;
91 }
92
93 /**
94 * Check main repository status: existence, has extensions, last update younger than 7 days
95 *
96 * @return \TYPO3\CMS\Reports\Report\Status\Status
97 */
98 protected function getMainRepositoryStatus()
99 {
100 /** @var $mainRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository */
101 $mainRepository = $this->repositoryRepository->findOneTypo3OrgRepository();
102
103 if (is_null($mainRepository) === true) {
104 $value = $this->languageService->getLL('report.status.mainRepository.notFound.value');
105 $message = $this->languageService->getLL('report.status.mainRepository.notFound.message');
106 $severity = \TYPO3\CMS\Reports\Status::ERROR;
107 } elseif ($mainRepository->getLastUpdate()->getTimestamp() < $GLOBALS['EXEC_TIME'] - 24 * 60 * 60 * 7) {
108 $value = $this->languageService->getLL('report.status.mainRepository.notUpToDate.value');
109 $message = $this->languageService->getLL('report.status.mainRepository.notUpToDate.message');
110 $severity = \TYPO3\CMS\Reports\Status::NOTICE;
111 } else {
112 $value = $this->languageService->getLL('report.status.mainRepository.upToDate.value');
113 $message = '';
114 $severity = \TYPO3\CMS\Reports\Status::OK;
115 }
116
117 /** @var $status \TYPO3\CMS\Reports\Status */
118 $status = $this->objectManager->get(
119 \TYPO3\CMS\Reports\Status::class,
120 $this->languageService->getLL('report.status.mainRepository.title'),
121 $value,
122 $message,
123 $severity
124 );
125
126 return $status;
127 }
128
129 /**
130 * Get security status of loaded and installed extensions
131 *
132 * @return \stdClass with properties 'loaded' and 'existing' containing a TYPO3\CMS\Reports\Report\Status\Status object
133 */
134 protected function getSecurityStatusOfExtensions()
135 {
136 $extensionInformation = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
137 $loadedInsecure = [];
138 $existingInsecure = [];
139 $loadedOutdated = [];
140 $existingOutdated = [];
141 foreach ($extensionInformation as $extensionKey => $information) {
142 if (
143 array_key_exists('terObject', $information)
144 && $information['terObject'] instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension
145 ) {
146 /** @var $terObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
147 $terObject = $information['terObject'];
148 $insecureStatus = $terObject->getReviewState();
149 if ($insecureStatus === -1) {
150 if (
151 array_key_exists('installed', $information)
152 && $information['installed'] === true
153 ) {
154 $loadedInsecure[] = [
155 'extensionKey' => $extensionKey,
156 'version' => $terObject->getVersion(),
157 ];
158 } else {
159 $existingInsecure[] = [
160 'extensionKey' => $extensionKey,
161 'version' => $terObject->getVersion(),
162 ];
163 }
164 } elseif ($insecureStatus === -2) {
165 if (
166 array_key_exists('installed', $information)
167 && $information['installed'] === true
168 ) {
169 $loadedOutdated[] = [
170 'extensionKey' => $extensionKey,
171 'version' => $terObject->getVersion(),
172 ];
173 } else {
174 $existingOutdated[] = [
175 'extensionKey' => $extensionKey,
176 'version' => $terObject->getVersion(),
177 ];
178 }
179 }
180 }
181 }
182
183 $result = new \stdClass();
184
185 if (empty($loadedInsecure)) {
186 $value = $this->languageService->getLL('report.status.loadedExtensions.noInsecureExtensionLoaded.value');
187 $message = '';
188 $severity = \TYPO3\CMS\Reports\Status::OK;
189 } else {
190 $value = sprintf(
191 $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.value'),
192 count($loadedInsecure)
193 );
194 $extensionList = [];
195 foreach ($loadedInsecure as $insecureExtension) {
196 $extensionList[] = sprintf(
197 $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.message.extension'),
198 $insecureExtension['extensionKey'],
199 $insecureExtension['version']
200 );
201 }
202 $message = sprintf(
203 $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.message'),
204 implode('', $extensionList)
205 );
206 $severity = \TYPO3\CMS\Reports\Status::ERROR;
207 }
208 $result->loaded = $this->objectManager->get(
209 \TYPO3\CMS\Reports\Status::class,
210 $this->languageService->getLL('report.status.loadedExtensions.title'),
211 $value,
212 $message,
213 $severity
214 );
215
216 if (empty($existingInsecure)) {
217 $value = $this->languageService->getLL('report.status.existingExtensions.noInsecureExtensionExists.value');
218 $message = '';
219 $severity = \TYPO3\CMS\Reports\Status::OK;
220 } else {
221 $value = sprintf(
222 $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.value'),
223 count($existingInsecure)
224 );
225 $extensionList = [];
226 foreach ($existingInsecure as $insecureExtension) {
227 $extensionList[] = sprintf(
228 $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.message.extension'),
229 $insecureExtension['extensionKey'],
230 $insecureExtension['version']
231 );
232 }
233 $message = sprintf(
234 $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.message'),
235 implode('', $extensionList)
236 );
237 $severity = \TYPO3\CMS\Reports\Status::WARNING;
238 }
239 $result->existing = $this->objectManager->get(
240 \TYPO3\CMS\Reports\Status::class,
241 $this->languageService->getLL('report.status.existingExtensions.title'),
242 $value,
243 $message,
244 $severity
245 );
246
247 if (empty($loadedOutdated)) {
248 $value = $this->languageService->getLL('report.status.loadedOutdatedExtensions.noOutdatedExtensionLoaded.value');
249 $message = '';
250 $severity = \TYPO3\CMS\Reports\Status::OK;
251 } else {
252 $value = sprintf(
253 $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.value'),
254 count($loadedOutdated)
255 );
256 $extensionList = [];
257 foreach ($loadedOutdated as $outdatedExtension) {
258 $extensionList[] = sprintf(
259 $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message.extension'),
260 $outdatedExtension['extensionKey'],
261 $outdatedExtension['version']
262 );
263 }
264 $message = sprintf(
265 $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message'),
266 implode('', $extensionList)
267 );
268 $severity = \TYPO3\CMS\Reports\Status::WARNING;
269 }
270 $result->loadedoutdated = $this->objectManager->get(
271 \TYPO3\CMS\Reports\Status::class,
272 $this->languageService->getLL('report.status.loadedOutdatedExtensions.title'),
273 $value,
274 $message,
275 $severity
276 );
277
278 if (empty($existingOutdated)) {
279 $value = $this->languageService->getLL('report.status.existingOutdatedExtensions.noOutdatedExtensionExists.value');
280 $message = '';
281 $severity = \TYPO3\CMS\Reports\Status::OK;
282 } else {
283 $value = sprintf(
284 $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.value'),
285 count($existingOutdated)
286 );
287 $extensionList = [];
288 foreach ($existingOutdated as $outdatedExtension) {
289 $extensionList[] = sprintf(
290 $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.message.extension'),
291 $outdatedExtension['extensionKey'],
292 $outdatedExtension['version']
293 );
294 }
295 $message = sprintf(
296 $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.message'),
297 implode('', $extensionList)
298 );
299 $severity = \TYPO3\CMS\Reports\Status::WARNING;
300 }
301 $result->existingoutdated = $this->objectManager->get(
302 \TYPO3\CMS\Reports\Status::class,
303 $this->languageService->getLL('report.status.existingOutdatedExtensions.title'),
304 $value,
305 $message,
306 $severity
307 );
308
309 return $result;
310 }
311 }