‪TYPO3CMS  9.5
ExtensionStatus.php
Go to the documentation of this file.
1 <?php
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 
22 {
26  protected ‪$ok = '';
27 
31  protected ‪$upToDate = '';
32 
36  protected ‪$error = '';
37 
41  protected ‪$objectManager;
42 
46  protected ‪$repositoryRepository;
47 
51  protected ‪$listUtility;
52 
56  protected ‪$languageService;
57 
61  public function ‪__construct()
62  {
63  $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
64  $this->repositoryRepository = $this->objectManager->get(\‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository::class);
65  $this->listUtility = $this->objectManager->get(\‪TYPO3\CMS\Extensionmanager\Utility\ListUtility::class);
66  $this->languageService = $this->objectManager->get(\‪TYPO3\CMS\Core\Localization\LanguageService::class);
67  $this->languageService->includeLLFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
68  }
69 
75  public function ‪getStatus()
76  {
77  $status = [];
78  $status['mainRepositoryStatus'] = $this->‪getMainRepositoryStatus();
79 
80  $extensionStatus = $this->‪getSecurityStatusOfExtensions();
81  $status['extensionsSecurityStatusInstalled'] = $extensionStatus->loaded ?? [];
82  $status['extensionsSecurityStatusNotInstalled'] = $extensionStatus->existing ?? [];
83  $status['extensionsOutdatedStatusInstalled'] = $extensionStatus->loadedoutdated ?? [];
84  $status['extensionsOutdatedStatusNotInstalled'] = $extensionStatus->existingoutdated ?? [];
85 
86  return $status;
87  }
88 
94  protected function ‪getMainRepositoryStatus()
95  {
97  $mainRepository = $this->repositoryRepository->findOneTypo3OrgRepository();
98 
99  if ($mainRepository === null) {
100  $value = $this->languageService->getLL('report.status.mainRepository.notFound.value');
101  $message = $this->languageService->getLL('report.status.mainRepository.notFound.message');
103  } elseif ($mainRepository->getLastUpdate()->getTimestamp() < ‪$GLOBALS['EXEC_TIME'] - 24 * 60 * 60 * 7) {
104  $value = $this->languageService->getLL('report.status.mainRepository.notUpToDate.value');
105  $message = $this->languageService->getLL('report.status.mainRepository.notUpToDate.message');
107  } else {
108  $value = $this->languageService->getLL('report.status.mainRepository.upToDate.value');
109  $message = '';
111  }
112 
114  $status = $this->objectManager->get(
115  \‪TYPO3\CMS\Reports\Status::class,
116  $this->languageService->getLL('report.status.mainRepository.title'),
117  $value,
118  $message,
119  $severity
120  );
121 
122  return $status;
123  }
124 
130  protected function ‪getSecurityStatusOfExtensions()
131  {
132  $extensionInformation = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
133  $loadedInsecure = [];
134  $existingInsecure = [];
135  $loadedOutdated = [];
136  $existingOutdated = [];
137  foreach ($extensionInformation as $extensionKey => $information) {
138  if (
139  array_key_exists('terObject', $information)
140  && $information['terObject'] instanceof \‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
141  ) {
143  $terObject = $information['terObject'];
144  $insecureStatus = $terObject->getReviewState();
145  if ($insecureStatus === -1) {
146  if (
147  array_key_exists('installed', $information)
148  && $information['installed'] === true
149  ) {
150  $loadedInsecure[] = [
151  'extensionKey' => $extensionKey,
152  'version' => $terObject->getVersion(),
153  ];
154  } else {
155  $existingInsecure[] = [
156  'extensionKey' => $extensionKey,
157  'version' => $terObject->getVersion(),
158  ];
159  }
160  } elseif ($insecureStatus === -2) {
161  if (
162  array_key_exists('installed', $information)
163  && $information['installed'] === true
164  ) {
165  $loadedOutdated[] = [
166  'extensionKey' => $extensionKey,
167  'version' => $terObject->getVersion(),
168  ];
169  } else {
170  $existingOutdated[] = [
171  'extensionKey' => $extensionKey,
172  'version' => $terObject->getVersion(),
173  ];
174  }
175  }
176  }
177  }
178 
179  $result = new \stdClass();
180 
181  if (empty($loadedInsecure)) {
182  $value = $this->languageService->getLL('report.status.loadedExtensions.noInsecureExtensionLoaded.value');
183  $message = '';
185  } else {
186  $value = sprintf(
187  $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.value'),
188  count($loadedInsecure)
189  );
190  $extensionList = [];
191  foreach ($loadedInsecure as $insecureExtension) {
192  $extensionList[] = sprintf(
193  $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.message.extension'),
194  $insecureExtension['extensionKey'],
195  $insecureExtension['version']
196  );
197  }
198  $message = sprintf(
199  $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.message'),
200  implode('', $extensionList)
201  );
203  }
204  $result->loaded = $this->objectManager->get(
205  \‪TYPO3\CMS\Reports\Status::class,
206  $this->languageService->getLL('report.status.loadedExtensions.title'),
207  $value,
208  $message,
209  $severity
210  );
211 
212  if (empty($existingInsecure)) {
213  $value = $this->languageService->getLL('report.status.existingExtensions.noInsecureExtensionExists.value');
214  $message = '';
216  } else {
217  $value = sprintf(
218  $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.value'),
219  count($existingInsecure)
220  );
221  $extensionList = [];
222  foreach ($existingInsecure as $insecureExtension) {
223  $extensionList[] = sprintf(
224  $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.message.extension'),
225  $insecureExtension['extensionKey'],
226  $insecureExtension['version']
227  );
228  }
229  $message = sprintf(
230  $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.message'),
231  implode('', $extensionList)
232  );
234  }
235  $result->existing = $this->objectManager->get(
236  \‪TYPO3\CMS\Reports\Status::class,
237  $this->languageService->getLL('report.status.existingExtensions.title'),
238  $value,
239  $message,
240  $severity
241  );
242 
243  if (empty($loadedOutdated)) {
244  $value = $this->languageService->getLL('report.status.loadedOutdatedExtensions.noOutdatedExtensionLoaded.value');
245  $message = '';
247  } else {
248  $value = sprintf(
249  $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.value'),
250  count($loadedOutdated)
251  );
252  $extensionList = [];
253  foreach ($loadedOutdated as $outdatedExtension) {
254  $extensionList[] = sprintf(
255  $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message.extension'),
256  $outdatedExtension['extensionKey'],
257  $outdatedExtension['version']
258  );
259  }
260  $message = sprintf(
261  $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message'),
262  implode('', $extensionList)
263  );
265  }
266  $result->loadedoutdated = $this->objectManager->get(
267  \‪TYPO3\CMS\Reports\Status::class,
268  $this->languageService->getLL('report.status.loadedOutdatedExtensions.title'),
269  $value,
270  $message,
271  $severity
272  );
273 
274  if (empty($existingOutdated)) {
275  $value = $this->languageService->getLL('report.status.existingOutdatedExtensions.noOutdatedExtensionExists.value');
276  $message = '';
278  } else {
279  $value = sprintf(
280  $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.value'),
281  count($existingOutdated)
282  );
283  $extensionList = [];
284  foreach ($existingOutdated as $outdatedExtension) {
285  $extensionList[] = sprintf(
286  $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.message.extension'),
287  $outdatedExtension['extensionKey'],
288  $outdatedExtension['version']
289  );
290  }
291  $message = sprintf(
292  $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.message'),
293  implode('', $extensionList)
294  );
296  }
297  $result->existingoutdated = $this->objectManager->get(
298  \‪TYPO3\CMS\Reports\Status::class,
299  $this->languageService->getLL('report.status.existingOutdatedExtensions.title'),
300  $value,
301  $message,
302  $severity
303  );
304 
305  return $result;
306  }
307 }
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:21
‪TYPO3\CMS\Extensionmanager\Report
Definition: ExtensionStatus.php:2
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Reports\Status\NOTICE
‪const NOTICE
Definition: Status.php:23
‪TYPO3
‪TYPO3\CMS\Reports\Status\ERROR
‪const ERROR
Definition: Status.php:27
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$ok
‪string $ok
Definition: ExtensionStatus.php:25
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\__construct
‪__construct()
Definition: ExtensionStatus.php:54
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$repositoryRepository
‪TYPO3 CMS Extensionmanager Domain Repository RepositoryRepository $repositoryRepository
Definition: ExtensionStatus.php:41
‪TYPO3\CMS\Reports\Status\OK
‪const OK
Definition: Status.php:25
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$languageService
‪TYPO3 CMS Core Localization LanguageService $languageService
Definition: ExtensionStatus.php:49
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$objectManager
‪TYPO3 CMS Extbase Object ObjectManager $objectManager
Definition: ExtensionStatus.php:37
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$error
‪string $error
Definition: ExtensionStatus.php:33
‪TYPO3\CMS\Reports\Status\WARNING
‪const WARNING
Definition: Status.php:26
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getSecurityStatusOfExtensions
‪stdClass getSecurityStatusOfExtensions()
Definition: ExtensionStatus.php:123
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$listUtility
‪TYPO3 CMS Extensionmanager Utility ListUtility $listUtility
Definition: ExtensionStatus.php:45
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$upToDate
‪string $upToDate
Definition: ExtensionStatus.php:29
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getStatus
‪array getStatus()
Definition: ExtensionStatus.php:68
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus
Definition: ExtensionStatus.php:22
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getMainRepositoryStatus
‪TYPO3 CMS Reports Status getMainRepositoryStatus()
Definition: ExtensionStatus.php:87