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