‪TYPO3CMS  9.5
ServicesListReport.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 
24 
29 {
33  protected ‪$reportsModule;
34 
41  {
42  $this->reportsModule = ‪$reportsModule;
43  $this->‪getLanguageService()->includeLLFile('EXT:reports/Resources/Private/Language/locallang_servicereport.xlf');
44  }
45 
51  public function ‪getReport()
52  {
53  // Rendering of the output via fluid
54  $view = GeneralUtility::makeInstance(StandaloneView::class);
55  $view->getRequest()->setControllerExtensionName('Reports');
56  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
57  'EXT:reports/Resources/Private/Templates/ServicesListReport.html'
58  ));
59 
60  $view->assignMultiple([
61  'servicesList' => $this->‪getServicesList(),
62  'searchPaths' => $this->‪getExecutablesSearchPathList()
63  ]);
64 
65  return $view->render();
66  }
67 
73  protected function ‪getServicesList()
74  {
75  $servicesList = [];
76  $services = $this->‪getInstalledServices();
77  foreach ($services as $serviceType => $installedServices) {
78  $servicesList[] = $this->‪getServiceTypeList($serviceType, $installedServices);
79  }
80  return $servicesList;
81  }
82 
90  protected function ‪getServiceTypeList($serviceType, $services)
91  {
92  $lang = $this->‪getLanguageService();
93  $serviceList = [];
94  $serviceList['Type'] = sprintf($lang->getLL('service_type'), $serviceType);
95 
96  $serviceList['Services'] = [];
97  foreach ($services as $serviceKey => $serviceInformation) {
98  $serviceList['Services'][] = $this->‪getServiceRow($serviceKey, $serviceInformation);
99  }
100 
101  return $serviceList;
102  }
103 
111  protected function ‪getServiceRow($serviceKey, $serviceInformation)
112  {
113  $result = [
114  'Key' => $serviceKey,
115  'Information' => $serviceInformation,
116  'Subtypes' => $serviceInformation['serviceSubTypes'] ? implode(', ', $serviceInformation['serviceSubTypes']) : '-',
117  'OperatingSystem' => $serviceInformation['os'] ?: $this->‪getLanguageService()->getLL('any'),
118  'RequiredExecutables' => $serviceInformation['exec'] ?: '-',
119  'AvailabilityClass' => 'danger',
120  'Available' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:no'),
121  ];
122 
123  try {
124  $serviceDetails = ‪ExtensionManagementUtility::findServiceByKey($serviceKey);
125  if ($serviceDetails['available']) {
126  $result['AvailabilityClass'] = 'success';
127  $result['Available'] = $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes');
128  }
129  } catch (‪Exception $e) {
130  }
131 
132  return $result;
133  }
134 
140  protected function ‪getExecutablesSearchPathList()
141  {
142  $searchPaths = ‪CommandUtility::getPaths(true);
143  $result = [];
144 
145  foreach ($searchPaths as $path => $isValid) {
146  $searchPathData = $this->‪getServicePathStatus($isValid);
147  $result[] = [
148  'class' => $searchPathData['statusCSSClass'],
149  'accessible' => 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:' . $searchPathData['accessible'],
150  'path' => GeneralUtility::fixWindowsFilePath($path),
151  ];
152  }
153 
154  return $result;
155  }
156 
170  protected function ‪getInstalledServices()
171  {
172  $filteredServices = [];
173  foreach (‪$GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
174  // If the (first) key of the service list is not the same as the service type,
175  // it's a "true" service type. Keep it and sort it.
176  if (key($serviceList) !== $serviceType) {
177  uasort($serviceList, [$this, 'sortServices']);
178  $filteredServices[$serviceType] = $serviceList;
179  }
180  }
181  return $filteredServices;
182  }
183 
192  protected function ‪sortServices(array $a, array $b)
193  {
194  $result = 0;
195  // If priorities are the same, test quality
196  if ($a['priority'] === $b['priority']) {
197  if ($a['quality'] !== $b['quality']) {
198  // Service with highest quality should come first,
199  // thus it must be marked as smaller
200  $result = $a['quality'] > $b['quality'] ? -1 : 1;
201  }
202  } else {
203  // Service with highest priority should come first,
204  // thus it must be marked as smaller
205  $result = $a['priority'] > $b['priority'] ? -1 : 1;
206  }
207  return $result;
208  }
209 
215  private function ‪getServicePathStatus($isValid): array
216  {
217  $statusCSSClass = 'danger';
218  $accessible = 'no';
219 
220  if ($isValid) {
221  $statusCSSClass = 'success';
222  $accessible = 'yes';
223  }
224  return [
225  'statusCSSClass' => $statusCSSClass,
226  'accessible' => $accessible
227  ];
228  }
229 
235  protected function ‪getLanguageService()
236  {
237  return ‪$GLOBALS['LANG'];
238  }
239 }
‪TYPO3\CMS\Reports\ReportInterface
Definition: ReportInterface.php:21
‪TYPO3\CMS\Reports\Report
Definition: ServicesListReport.php:2
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServiceTypeList
‪array getServiceTypeList($serviceType, $services)
Definition: ServicesListReport.php:89
‪TYPO3\CMS\Reports\Report\ServicesListReport\getReport
‪string getReport()
Definition: ServicesListReport.php:50
‪TYPO3\CMS\Reports\Report\ServicesListReport\$reportsModule
‪ReportController $reportsModule
Definition: ServicesListReport.php:32
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServiceRow
‪array getServiceRow($serviceKey, $serviceInformation)
Definition: ServicesListReport.php:110
‪TYPO3\CMS\Reports\Report\ServicesListReport\getExecutablesSearchPathList
‪array getExecutablesSearchPathList()
Definition: ServicesListReport.php:139
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Utility\CommandUtility\getPaths
‪static array getPaths($addInvalid=false)
Definition: CommandUtility.php:272
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Reports\Report\ServicesListReport
Definition: ServicesListReport.php:29
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServicesList
‪array getServicesList()
Definition: ServicesListReport.php:72
‪TYPO3\CMS\Reports\Report\ServicesListReport\__construct
‪__construct(ReportController $reportsModule)
Definition: ServicesListReport.php:39
‪TYPO3\CMS\Reports\Report\ServicesListReport\getInstalledServices
‪array getInstalledServices()
Definition: ServicesListReport.php:169
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\findServiceByKey
‪static array findServiceByKey($serviceKey)
Definition: ExtensionManagementUtility.php:1162
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Reports\Report\ServicesListReport\sortServices
‪int sortServices(array $a, array $b)
Definition: ServicesListReport.php:191
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServicePathStatus
‪array getServicePathStatus($isValid)
Definition: ServicesListReport.php:214
‪TYPO3\CMS\Reports\Report\ServicesListReport\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: ServicesListReport.php:234
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:48
‪TYPO3\CMS\Reports\Controller\ReportController
Definition: ReportController.php:37