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