[TASK] Move classAliasMaps into compatibility6 extension part 6
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / Classes / Report / ServicesListReport.php
1 <?php
2 namespace TYPO3\CMS\Sv\Report;
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
17 /**
18 * This class provides a report displaying a list of all installed services
19 * Code inspired by EXT:dam/lib/class.tx_dam_svlist.php by René Fritz
20 *
21 * @author Francois Suter <francois@typo3.org>
22 */
23 class ServicesListReport implements \TYPO3\CMS\Reports\ReportInterface {
24
25 /**
26 * Back-reference to the calling reports module
27 *
28 * @var \TYPO3\CMS\Reports\Controller\ReportController
29 */
30 protected $reportsModule;
31
32 /**
33 * Constructor
34 *
35 * @param \TYPO3\CMS\Reports\Controller\ReportController $reportsModule Back-reference to the calling reports module
36 */
37 public function __construct(\TYPO3\CMS\Reports\Controller\ReportController $reportsModule) {
38 $this->reportsModule = $reportsModule;
39 $GLOBALS['LANG']->includeLLFile('EXT:sv/Resources/Private/Language/locallang.xlf');
40 }
41
42 /**
43 * This method renders the report
44 *
45 * @return string The status report as HTML
46 */
47 public function getReport() {
48 $content = '';
49 $content .= $this->renderHelp();
50 $content .= $this->renderServicesList();
51 $content .= $this->renderExecutablesSearchPathList();
52 return $content;
53 }
54
55 /**
56 * Renders the help comments at the top of the module.
57 *
58 * @return string The help content for this module.
59 */
60 protected function renderHelp() {
61 $help = '<p class="lead">' . $GLOBALS['LANG']->getLL('report_explanation') . '</p>';
62 $help .= '<p class="help">' . $GLOBALS['LANG']->getLL('externals_explanation') . '</p><br />';
63 return $help;
64 }
65
66 /**
67 * This method assembles a list of all installed services
68 *
69 * @return string HTML to display
70 */
71 protected function renderServicesList() {
72 $servicesList = '';
73 $services = $this->getInstalledServices();
74 foreach ($services as $serviceType => $installedServices) {
75 $servicesList .= $this->renderServiceTypeList($serviceType, $installedServices);
76 }
77 return $servicesList;
78 }
79
80 /**
81 * Renders the services list for a single service type.
82 *
83 * @param string $serviceType The service type to render the installed services list for
84 * @param array $services List of services for the given type
85 * @return string Service list as HTML for one service type
86 */
87 protected function renderServiceTypeList($serviceType, $services) {
88 $header = '<h3>' . sprintf($GLOBALS['LANG']->getLL('service_type'), $serviceType) . '</h3>';
89 $serviceList = '
90 <table class="t3-table table tx_sv_reportlist">
91 <thead>
92 <tr>
93 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('service') . '</td>
94 <td>' . $GLOBALS['LANG']->getLL('priority') . '</td>
95 <td>' . $GLOBALS['LANG']->getLL('quality') . '</td>
96 <td style="width: 35%">' . $GLOBALS['LANG']->getLL('subtypes') . '</td>
97 <td>' . $GLOBALS['LANG']->getLL('os') . '</td>
98 <td>' . $GLOBALS['LANG']->getLL('externals') . '</td>
99 <td>' . $GLOBALS['LANG']->getLL('available') . '</td>
100 </tr>
101 </thead>
102 <tbody>';
103
104 foreach ($services as $serviceKey => $serviceInformation) {
105 $serviceList .= $this->renderServiceRow($serviceKey, $serviceInformation);
106 }
107
108 $serviceList .= '
109 </tbody>
110 </table>
111 ';
112 return $header . $serviceList;
113 }
114
115 /**
116 * Renders a single service's row.
117 *
118 * @param string $serviceKey The service key to access the service.
119 * @param array $serviceInformation registration information of the service.
120 * @return string HTML row for the service.
121 */
122 protected function renderServiceRow($serviceKey, $serviceInformation) {
123 $serviceDescription = '
124 <p class="service-header">
125 <span class="service-title">' . $serviceInformation['title'] . '</span> (' . $serviceInformation['extKey'] . ': ' . $serviceKey . ')
126 </p>';
127 if (!empty($serviceInformation['description'])) {
128 $serviceDescription .= '<p class="service-description">' . $serviceInformation['description'] . '</p>';
129 }
130 $serviceSubtypes = $serviceInformation['serviceSubTypes'] ? implode(', ', $serviceInformation['serviceSubTypes']) : '-';
131 $serviceOperatingSystem = $serviceInformation['os'] ?: $GLOBALS['LANG']->getLL('any');
132 $serviceRequiredExecutables = $serviceInformation['exec'] ?: '-';
133 $serviceAvailabilityClass = 'danger';
134 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:no');
135 try {
136 $serviceDetails = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::findServiceByKey($serviceKey);
137 if ($serviceDetails['available']) {
138 $serviceAvailabilityClass = 'success';
139 $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes');
140 }
141 } catch (\TYPO3\CMS\Core\Exception $e) {
142
143 }
144 $serviceRow = '
145 <tr class="service ' . $serviceAvailabilityClass . '">
146 <td class="first-cell">' . $serviceDescription . '</td>
147 <td class="cell">' . $serviceInformation['priority'] . '</td>
148 <td class="cell">' . $serviceInformation['quality'] . '</td>
149 <td class="cell">' . $serviceSubtypes . '</td>
150 <td class="cell">' . $serviceOperatingSystem . '</td>
151 <td class="cell">' . $serviceRequiredExecutables . '</td>
152 <td class="last-cell">' . $serviceAvailable . '</td>
153 </tr>';
154 return $serviceRow;
155 }
156
157 /**
158 * This method assembles a list of all defined executables search paths
159 *
160 * @return string HTML to display
161 */
162 protected function renderExecutablesSearchPathList() {
163 $searchPaths = \TYPO3\CMS\Core\Utility\CommandUtility::getPaths(TRUE);
164 $content = '<h3 class="divider">' . $GLOBALS['LANG']->getLL('search_paths') . '</h3>';
165 if (count($searchPaths) == 0) {
166 $content .= '<p>' . $GLOBALS['LANG']->getLL('no_search_paths') . '</p>';
167 } else {
168 $content .= '
169 <table class="t3-table tx_sv_reportlist">
170 <thead>
171 <tr>
172 <td>' . $GLOBALS['LANG']->getLL('path') . '</td>
173 <td>' . $GLOBALS['LANG']->getLL('valid') . '</td>
174 </tr>
175 </thead>
176 <tbody>';
177 foreach ($searchPaths as $path => $isValid) {
178 $pathAccessibleClass = 'danger';
179 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:no');
180 if ($isValid) {
181 $pathAccessibleClass = 'success';
182 $pathAccessible = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes');
183 }
184 $content .= '
185 <tr class="' . $pathAccessibleClass . '">
186 <td class="first-cell">' . \TYPO3\CMS\Core\Utility\GeneralUtility::fixWindowsFilePath($path) . '</td>
187 <td class="last-cell">' . $pathAccessible . '</td>
188 </tr>';
189 }
190 $content .= '
191 </tbody>
192 </table>';
193 }
194 return $content;
195 }
196
197 /**
198 * This method filters the $T3_SERVICES global array to return a relevant,
199 * ordered list of installed services.
200 *
201 * Every installed service appears twice in $T3_SERVICES: once as a service key
202 * for a given service type, and once a service type all by itself
203 * The list of services to display must avoid these duplicates
204 *
205 * Furthermore, inside each service type, installed services must be
206 * ordered by priority and quality
207 *
208 * @return array List of filtered and ordered services
209 */
210 protected function getInstalledServices() {
211 $filteredServices = array();
212 foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $serviceList) {
213 // If the (first) key of the service list is not the same as the service type,
214 // it's a "true" service type. Keep it and sort it.
215 if (key($serviceList) !== $serviceType) {
216 uasort($serviceList, array($this, 'sortServices'));
217 $filteredServices[$serviceType] = $serviceList;
218 }
219 }
220 return $filteredServices;
221 }
222
223 /**
224 * Utility method used to sort services according to their priority and
225 * quality.
226 *
227 * @param array $a First service to compare
228 * @param array $b Second service to compare
229 * @return int 1, 0 or -1 if a is smaller, equal or greater than b, respectively
230 */
231 protected function sortServices(array $a, array $b) {
232 $result = 0;
233 // If priorities are the same, test quality
234 if ($a['priority'] == $b['priority']) {
235 if ($a['quality'] != $b['quality']) {
236 // Service with highest quality should come first,
237 // thus it must be marked as smaller
238 $result = $a['quality'] > $b['quality'] ? -1 : 1;
239 }
240 } else {
241 // Service with highest priority should come first,
242 // thus it must be marked as smaller
243 $result = $a['priority'] > $b['priority'] ? -1 : 1;
244 }
245 return $result;
246 }
247
248 }