[TASK] Merge submodule fluid into core
[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
89 return $status;
90 }
91
92 /**
93 * Check main repository status: existance, has extensions, last update younger than 7 days
94 *
95 * @return \TYPO3\CMS\Reports\Report\Status\Status
96 */
97 protected function getMainRepositoryStatus() {
98 /** @var $mainRepository \TYPO3\CMS\Extensionmanager\Domain\Model\Repository */
99 $mainRepository = $this->repositoryRepository->findOneTypo3OrgRepository();
100
101 if (is_null($mainRepository) === TRUE) {
102 $value = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notFound.value');
103 $message = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notFound.message');
104 $severity = \TYPO3\CMS\Reports\Status::ERROR;
105 } elseif ($mainRepository->getLastUpdate()->getTimestamp() < $GLOBALS['EXEC_TIME'] - 24 * 60 * 60 * 7) {
106 $value = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notUpToDate.value');
107 $message = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notUpToDate.message');
108 $severity = \TYPO3\CMS\Reports\Status::NOTICE;
109 } else {
110 $value = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.upToDate.value');
111 $message = '';
112 $severity = \TYPO3\CMS\Reports\Status::OK;
113 }
114
115 /** @var $status \TYPO3\CMS\Reports\Status */
116 $status = $this->objectManager->get(
117 'TYPO3\\CMS\\Reports\\Status',
118 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.title'),
119 $value,
120 $message,
121 $severity
122 );
123
124 return $status;
125 }
126
127 /**
128 * Get security status of loaded and installed extensions
129 *
130 * @return \stdClass with properties 'loaded' and 'existing' containing a TYPO3\CMS\Reports\Report\Status\Status object
131 */
132 protected function getSecurityStatusOfExtensions() {
133 $extensionInformation = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
134 $loadedInsecure = array();
135 $existingInsecure = array();
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 $terObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
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[] = array(
150 'extensionKey' => $extensionKey,
151 'version' => $terObject->getVersion(),
152 );
153 } else {
154 $existingInsecure[] = array(
155 'extensionKey' => $extensionKey,
156 'version' => $terObject->getVersion(),
157 );
158 }
159 }
160 }
161 }
162
163 $result = new \stdClass();
164
165 if (count($loadedInsecure) === 0) {
166 $value = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.noInsecureExtensionLoaded.value');
167 $message = '';
168 $severity = \TYPO3\CMS\Reports\Status::OK;
169 } else {
170 $value = sprintf(
171 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.value'),
172 count($loadedInsecure)
173 );
174 $extensionList = array();
175 foreach ($loadedInsecure as $insecureExtension) {
176 $extensionList[] = sprintf(
177 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.message.extension'),
178 $insecureExtension['extensionKey'],
179 $insecureExtension['version']
180 );
181 }
182 $message = sprintf(
183 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.message'),
184 implode('', $extensionList)
185 );
186 $severity = \TYPO3\CMS\Reports\Status::ERROR;
187 }
188 $result->loaded = $this->objectManager->get(
189 'TYPO3\\CMS\\Reports\\Status',
190 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.title'),
191 $value,
192 $message,
193 $severity
194 );
195
196 if (count($existingInsecure) === 0) {
197 $value = $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.noInsecureExtensionExists.value');
198 $message = '';
199 $severity = \TYPO3\CMS\Reports\Status::OK;
200 } else {
201 $value = sprintf(
202 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.value'),
203 count($existingInsecure)
204 );
205 $extensionList = array();
206 foreach ($existingInsecure as $insecureExtension) {
207 $extensionList[] = sprintf(
208 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.message.extension'),
209 $insecureExtension['extensionKey'],
210 $insecureExtension['version']
211 );
212 }
213 $message = sprintf(
214 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.message'),
215 implode('', $extensionList)
216 );
217 $severity = \TYPO3\CMS\Reports\Status::WARNING;
218 }
219 $result->existing = $this->objectManager->get(
220 'TYPO3\\CMS\\Reports\\Status',
221 $GLOBALS['LANG']->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.title'),
222 $value,
223 $message,
224 $severity
225 );
226
227 return $result;
228 }
229 }
230 ?>