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