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