‪TYPO3CMS  10.4
ServicesListReport.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 
30 {
34  protected ‪$reportsModule;
35 
42  {
43  $this->reportsModule = ‪$reportsModule;
44  $this->‪getLanguageService()->includeLLFile('EXT:reports/Resources/Private/Language/locallang_servicereport.xlf');
45  }
46 
52  public function ‪getReport()
53  {
54  // Rendering of the output via fluid
55  $view = GeneralUtility::makeInstance(StandaloneView::class);
56  $view->getRequest()->setControllerExtensionName('Reports');
57  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
58  'EXT:reports/Resources/Private/Templates/ServicesListReport.html'
59  ));
60 
61  $view->assignMultiple([
62  'servicesList' => $this->‪getServicesList(),
63  'searchPaths' => $this->‪getExecutablesSearchPathList()
64  ]);
65 
66  return $view->render();
67  }
68 
74  protected function ‪getServicesList()
75  {
76  $servicesList = [];
77  $services = $this->‪getInstalledServices();
78  foreach ($services as $serviceType => $installedServices) {
79  $servicesList[] = $this->‪getServiceTypeList($serviceType, $installedServices);
80  }
81  return $servicesList;
82  }
83 
91  protected function ‪getServiceTypeList($serviceType, $services)
92  {
93  $lang = $this->‪getLanguageService();
94  $serviceList = [];
95  $serviceList['Type'] = sprintf($lang->getLL('service_type'), $serviceType);
96 
97  $serviceList['Services'] = [];
98  foreach ($services as $serviceKey => $serviceInformation) {
99  $serviceList['Services'][] = $this->‪getServiceRow($serviceKey, $serviceInformation);
100  }
101 
102  return $serviceList;
103  }
104 
112  protected function ‪getServiceRow($serviceKey, $serviceInformation)
113  {
114  $result = [
115  'Key' => $serviceKey,
116  'Information' => $serviceInformation,
117  'Subtypes' => $serviceInformation['serviceSubTypes'] ? implode(', ', $serviceInformation['serviceSubTypes']) : '-',
118  'OperatingSystem' => $serviceInformation['os'] ?: $this->‪getLanguageService()->getLL('any'),
119  'RequiredExecutables' => $serviceInformation['exec'] ?: '-',
120  'AvailabilityClass' => 'danger',
121  'Available' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:no'),
122  ];
123 
124  try {
125  $serviceDetails = ‪ExtensionManagementUtility::findServiceByKey($serviceKey);
126  if ($serviceDetails['available']) {
127  $result['AvailabilityClass'] = 'success';
128  $result['Available'] = $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes');
129  }
130  } catch (‪Exception $e) {
131  }
132 
133  return $result;
134  }
135 
141  protected function ‪getExecutablesSearchPathList()
142  {
143  $searchPaths = ‪CommandUtility::getPaths(true);
144  $result = [];
145 
146  foreach ($searchPaths as $path => $isValid) {
147  $searchPathData = $this->‪getServicePathStatus($isValid);
148  $result[] = [
149  'class' => $searchPathData['statusCSSClass'],
150  'accessible' => 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:' . $searchPathData['accessible'],
151  'path' => GeneralUtility::fixWindowsFilePath($path),
152  ];
153  }
154 
155  return $result;
156  }
157 
171  protected function ‪getInstalledServices()
172  {
173  $filteredServices = [];
174  foreach (‪$GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
175  // If the (first) key of the service list is not the same as the service type,
176  // it's a "true" service type. Keep it and sort it.
177  if (key($serviceList) !== $serviceType) {
178  uasort($serviceList, [$this, 'sortServices']);
179  $filteredServices[$serviceType] = $serviceList;
180  }
181  }
182  return $filteredServices;
183  }
184 
193  protected function ‪sortServices(array $a, array $b)
194  {
195  $result = 0;
196  // If priorities are the same, test quality
197  if ($a['priority'] === $b['priority']) {
198  if ($a['quality'] !== $b['quality']) {
199  // Service with highest quality should come first,
200  // thus it must be marked as smaller
201  $result = $a['quality'] > $b['quality'] ? -1 : 1;
202  }
203  } else {
204  // Service with highest priority should come first,
205  // thus it must be marked as smaller
206  $result = $a['priority'] > $b['priority'] ? -1 : 1;
207  }
208  return $result;
209  }
210 
216  private function ‪getServicePathStatus($isValid): array
217  {
218  $statusCSSClass = 'danger';
219  $accessible = 'no';
220 
221  if ($isValid) {
222  $statusCSSClass = 'success';
223  $accessible = 'yes';
224  }
225  return [
226  'statusCSSClass' => $statusCSSClass,
227  'accessible' => $accessible
228  ];
229  }
230 
236  protected function ‪getLanguageService()
237  {
238  return ‪$GLOBALS['LANG'];
239  }
240 }
‪TYPO3\CMS\Reports\ReportInterface
Definition: ReportInterface.php:22
‪TYPO3\CMS\Reports\Report
Definition: ServicesListReport.php:16
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServiceTypeList
‪array getServiceTypeList($serviceType, $services)
Definition: ServicesListReport.php:90
‪TYPO3\CMS\Reports\Report\ServicesListReport\getReport
‪string getReport()
Definition: ServicesListReport.php:51
‪TYPO3\CMS\Reports\Report\ServicesListReport\$reportsModule
‪ReportController $reportsModule
Definition: ServicesListReport.php:33
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServiceRow
‪array getServiceRow($serviceKey, $serviceInformation)
Definition: ServicesListReport.php:111
‪TYPO3\CMS\Reports\Report\ServicesListReport\getExecutablesSearchPathList
‪array getExecutablesSearchPathList()
Definition: ServicesListReport.php:140
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Utility\CommandUtility\getPaths
‪static array getPaths($addInvalid=false)
Definition: CommandUtility.php:273
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Reports\Report\ServicesListReport
Definition: ServicesListReport.php:30
‪TYPO3\CMS\Reports\Report\ServicesListReport\getServicesList
‪array getServicesList()
Definition: ServicesListReport.php:73
‪TYPO3\CMS\Reports\Report\ServicesListReport\__construct
‪__construct(ReportController $reportsModule)
Definition: ServicesListReport.php:40
‪TYPO3\CMS\Reports\Report\ServicesListReport\getInstalledServices
‪array getInstalledServices()
Definition: ServicesListReport.php:170
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\findServiceByKey
‪static array findServiceByKey($serviceKey)
Definition: ExtensionManagementUtility.php:1170
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Reports\Report\ServicesListReport\sortServices
‪int sortServices(array $a, array $b)
Definition: ServicesListReport.php:192
‪$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:215
‪TYPO3\CMS\Reports\Report\ServicesListReport\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: ServicesListReport.php:235
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:49
‪TYPO3\CMS\Reports\Controller\ReportController
Definition: ReportController.php:39