97c4b4bc2a5e4f64b7478f4f9326cc784037c3d6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Report / ExtensionStatus.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Report;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Steffen Kamper <steffen@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Extension status reports
32 */
33 class ExtensionStatus implements \TYPO3\CMS\Reports\StatusProviderInterface {
34
35 /**
36 * @var string
37 */
38 protected $ok = '';
39
40 /**
41 * @var string
42 */
43 protected $upToDate = '';
44
45 /**
46 * @var string
47 */
48 protected $error = '';
49
50 /**
51 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
52 */
53 protected $objectManager = NULL;
54
55 /**
56 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
57 */
58 protected $repositoryRepository = NULL;
59
60 /**
61 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
62 */
63 protected $listUtility = NULL;
64
65 /**
66 * @var \TYPO3\CMS\Lang\LanguageService
67 */
68 protected $languageService = NULL;
69
70 /**
71 * Default constructor
72 */
73 public function __construct() {
74 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
75 $this->repositoryRepository = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\RepositoryRepository');
76 $this->listUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility');
77 $this->languageService = $this->objectManager->get('TYPO3\\CMS\\Lang\\LanguageService');
78 }
79
80 /**
81 * Determines extension manager status
82 *
83 * @return array List of statuses
84 */
85 public function getStatus() {
86 $status = array();
87 $status['mainRepositoryStatus'] = $this->getMainRepositoryStatus();
88
89 $extensionStatus = $this->getSecurityStatusOfExtensions();
90 $status['extensionsSecurityStatusInstalled'] = $extensionStatus->loaded;
91 $status['extensionsSecurityStatusNotInstalled'] = $extensionStatus->existing;
92 $status['extensionsOutdatedStatusInstalled'] = $extensionStatus->loadedoutdated;
93 $status['extensionsOutdatedStatusNotInstalled'] = $extensionStatus->existingoutdated;
94
95 return $status;
96 }
97
98 /**
99 * Check main repository status: existance, has extensions, last update younger than 7 days
100 *
101 * @return \TYPO3\CMS\Reports\Report\Status\Status
102 */
103 protected function getMainRepositoryStatus() {
104 /** @var $mainRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository */
105 $mainRepository = $this->repositoryRepository->findOneTypo3OrgRepository();
106
107 if (is_null($mainRepository) === TRUE) {
108 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notFound.value');
109 $message = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notFound.message');
110 $severity = \TYPO3\CMS\Reports\Status::ERROR;
111 } elseif ($mainRepository->getLastUpdate()->getTimestamp() < $GLOBALS['EXEC_TIME'] - 24 * 60 * 60 * 7) {
112 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notUpToDate.value');
113 $message = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notUpToDate.message');
114 $severity = \TYPO3\CMS\Reports\Status::NOTICE;
115 } else {
116 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.upToDate.value');
117 $message = '';
118 $severity = \TYPO3\CMS\Reports\Status::OK;
119 }
120
121 /** @var $status \TYPO3\CMS\Reports\Status */
122 $status = $this->objectManager->get(
123 'TYPO3\\CMS\\Reports\\Status',
124 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.title'),
125 $value,
126 $message,
127 $severity
128 );
129
130 return $status;
131 }
132
133 /**
134 * Get security status of loaded and installed extensions
135 *
136 * @return \stdClass with properties 'loaded' and 'existing' containing a TYPO3\CMS\Reports\Report\Status\Status object
137 */
138 protected function getSecurityStatusOfExtensions() {
139 $extensionInformation = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
140 $loadedInsecure = array();
141 $existingInsecure = array();
142 $loadedOutdated = array();
143 $existingOutdated = array();
144 foreach ($extensionInformation as $extensionKey => $information) {
145 if (
146 array_key_exists('terObject', $information)
147 && $information['terObject'] instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension
148 ) {
149 /** @var $terObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
150 $terObject = $information['terObject'];
151 $insecureStatus = $terObject->getReviewState();
152 if ($insecureStatus === -1) {
153 if (
154 array_key_exists('installed', $information)
155 && $information['installed'] === TRUE
156 ) {
157 $loadedInsecure[] = array(
158 'extensionKey' => $extensionKey,
159 'version' => $terObject->getVersion(),
160 );
161 } else {
162 $existingInsecure[] = array(
163 'extensionKey' => $extensionKey,
164 'version' => $terObject->getVersion(),
165 );
166 }
167 } elseif ($insecureStatus === -2) {
168 if (
169 array_key_exists('installed', $information)
170 && $information['installed'] === TRUE
171 ) {
172 $loadedOutdated[] = array(
173 'extensionKey' => $extensionKey,
174 'version' => $terObject->getVersion(),
175 );
176 } else {
177 $existingOutdated[] = array(
178 'extensionKey' => $extensionKey,
179 'version' => $terObject->getVersion(),
180 );
181 }
182 }
183 }
184 }
185
186 $result = new \stdClass();
187
188 if (count($loadedInsecure) === 0) {
189 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.noInsecureExtensionLoaded.value');
190 $message = '';
191 $severity = \TYPO3\CMS\Reports\Status::OK;
192 } else {
193 $value = sprintf(
194 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.value'),
195 count($loadedInsecure)
196 );
197 $extensionList = array();
198 foreach ($loadedInsecure as $insecureExtension) {
199 $extensionList[] = sprintf(
200 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.message.extension'),
201 $insecureExtension['extensionKey'],
202 $insecureExtension['version']
203 );
204 }
205 $message = sprintf(
206 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.message'),
207 implode('', $extensionList)
208 );
209 $severity = \TYPO3\CMS\Reports\Status::ERROR;
210 }
211 $result->loaded = $this->objectManager->get(
212 'TYPO3\\CMS\\Reports\\Status',
213 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.title'),
214 $value,
215 $message,
216 $severity
217 );
218
219 if (count($existingInsecure) === 0) {
220 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.noInsecureExtensionExists.value');
221 $message = '';
222 $severity = \TYPO3\CMS\Reports\Status::OK;
223 } else {
224 $value = sprintf(
225 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.value'),
226 count($existingInsecure)
227 );
228 $extensionList = array();
229 foreach ($existingInsecure as $insecureExtension) {
230 $extensionList[] = sprintf(
231 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.message.extension'),
232 $insecureExtension['extensionKey'],
233 $insecureExtension['version']
234 );
235 }
236 $message = sprintf(
237 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.message'),
238 implode('', $extensionList)
239 );
240 $severity = \TYPO3\CMS\Reports\Status::WARNING;
241 }
242 $result->existing = $this->objectManager->get(
243 'TYPO3\\CMS\\Reports\\Status',
244 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.title'),
245 $value,
246 $message,
247 $severity
248 );
249
250 if (count($loadedOutdated) === 0) {
251 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.noOutdatedExtensionLoaded.value');
252 $message = '';
253 $severity = \TYPO3\CMS\Reports\Status::OK;
254 } else {
255 $value = sprintf(
256 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.value'),
257 count($loadedOutdated)
258 );
259 $extensionList = array();
260 foreach ($loadedOutdated as $outdatedExtension) {
261 $extensionList[] = sprintf(
262 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message.extension'),
263 $outdatedExtension['extensionKey'],
264 $outdatedExtension['version']
265 );
266 }
267 $message = sprintf(
268 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message'),
269 implode('', $extensionList)
270 );
271 $severity = \TYPO3\CMS\Reports\Status::WARNING;
272 }
273 $result->loadedoutdated = $this->objectManager->get(
274 'TYPO3\\CMS\\Reports\\Status',
275 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.title'),
276 $value,
277 $message,
278 $severity
279 );
280
281 if (count($existingOutdated) === 0) {
282 $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.noOutdatedExtensionExists.value');
283 $message = '';
284 $severity = \TYPO3\CMS\Reports\Status::OK;
285 } else {
286 $value = sprintf(
287 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.outdatedExtensionExists.value'),
288 count($existingOutdated)
289 );
290 $extensionList = array();
291 foreach ($existingOutdated as $outdatedExtension) {
292 $extensionList[] = sprintf(
293 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.outdatedExtensionExists.message.extension'),
294 $outdatedExtension['extensionKey'],
295 $outdatedExtension['version']
296 );
297 }
298 $message = sprintf(
299 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.outdatedExtensionExists.message'),
300 implode('', $extensionList)
301 );
302 $severity = \TYPO3\CMS\Reports\Status::WARNING;
303 }
304 $result->existingoutdated = $this->objectManager->get(
305 'TYPO3\\CMS\\Reports\\Status',
306 $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.title'),
307 $value,
308 $message,
309 $severity
310 );
311
312 return $result;
313 }
314 }