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