[BUGFIX] Reports module: Available services broken
authorLorenz Ulrich <lorenz.ulrich@visol.ch>
Tue, 4 Oct 2011 16:07:21 +0000 (18:07 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sun, 23 Oct 2011 18:18:34 +0000 (20:18 +0200)
Displaying the available services in the reports module is broken.
This is a regression due to cleaning up the global declarations for
services ($T3_SERVICES) in TYPO4 4.6.

Because of this method t3lib_extMgm::findService cannot be abused
into getting a service by its key explicitly. Hence a new method must
be introduced and used in the available services report.

This patch also introduces method t3lib_extMgm::isServiceAvailable
which refactors part of the services-related code to avoid
duplication.

Change-Id: I15fd7eecaafb52df0599598c5b700e458e63f0d9
Resolves: #30554
Releases: 4.6
Reviewed-on: http://review.typo3.org/5538
Reviewed-by: Lorenz Ulrich
Tested-by: Lorenz Ulrich
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
t3lib/class.t3lib_extmgm.php
typo3/sysext/sv/reports/class.tx_sv_reports_serviceslist.php

index 2e4d067..f1d2e5d 100644 (file)
@@ -1013,7 +1013,7 @@ final class t3lib_extMgm {
         * @param       string          Service type
         * @param       string          Service sub type
         * @param       mixed           Service keys that should be excluded in the search for a service. Array or comma list.
-        * @return      mixed           Service info array if a service was found, FLASE otherwise
+        * @return      mixed           Service info array if a service was found, FALSE otherwise
         * @author      RenĂ© Fritz <r.fritz@colorcube.de>
         */
        public static function findService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) {
@@ -1027,6 +1027,7 @@ final class t3lib_extMgm {
                }
 
                if (is_array($GLOBALS['T3_SERVICES'][$serviceType])) {
+
                        foreach ($GLOBALS['T3_SERVICES'][$serviceType] as $key => $info) {
 
                                if (in_array($key, $excludeServiceKeys)) {
@@ -1034,7 +1035,7 @@ final class t3lib_extMgm {
                                }
 
                                        // select a subtype randomly
-                                       // usefull to start a service by service key without knowing his subtypes - for testing purposes
+                                       // useful to start a service by service key without knowing his subtypes - for testing purposes
                                if ($serviceSubType == '*') {
                                        $serviceSubType = key($info['serviceSubTypes']);
                                }
@@ -1047,17 +1048,8 @@ final class t3lib_extMgm {
                                                continue;
                                        }
 
-                                               // service depends on external programs - check if they exists
-                                       if (trim($info['exec'])) {
-                                               $executables = t3lib_div::trimExplode(',', $info['exec'], 1);
-                                               foreach ($executables as $executable) {
-                                                       if (!t3lib_exec::checkCommand($executable)) {
-                                                               self::deactivateService($serviceType, $key);
-                                                               $info['available'] = FALSE;
-                                                               break;
-                                                       }
-                                               }
-                                       }
+                                               // Check if the service is available
+                                       $info['available'] = self::isServiceAvailable($serviceType, $key, $info);
 
                                                // still available after exec check?
                                        if ($info['available']) {
@@ -1076,6 +1068,57 @@ final class t3lib_extMgm {
        }
 
        /**
+        * Find a specific service identified by its key
+        * Note that this completely bypasses the notions of priority and quality
+        *
+        * @param string $serviceKey Service key
+        * @return array Service info array if a service was found
+        * @throws t3lib_exception
+        */
+       public static function findServiceByKey($serviceKey) {
+               if (is_array($GLOBALS['T3_SERVICES'])) {
+                               // Loop on all service types
+                               // NOTE: we don't care about the actual type, we are looking for a specific key
+                       foreach ($GLOBALS['T3_SERVICES'] as $serviceType => $servicesPerType) {
+                               if (isset($servicesPerType[$serviceKey])) {
+                                       $serviceDetails = $servicesPerType[$serviceKey];
+                                               // Test if service is available
+                                       if (self::isServiceAvailable($serviceType, $serviceKey, $serviceDetails)) {
+                                                       // We have found the right service, return its information
+                                               return $serviceDetails;
+                                       }
+                               }
+                       }
+               }
+               throw new t3lib_exception('Service not found for key: ' . $serviceKey, 1319217244);
+       }
+
+       /**
+        * Check if a given service is available, based on the executable files it depends on
+        *
+        * @param string $serviceType Type of service
+        * @param string $serviceKey Specific key of the service
+        * @param array $serviceDetails Information about the service
+        * @return boolean Service availability
+        */
+       public static function isServiceAvailable($serviceType, $serviceKey, $serviceDetails) {
+
+                       // If the service depends on external programs - check if they exists
+               if (trim($serviceDetails['exec'])) {
+                       $executables = t3lib_div::trimExplode(',', $serviceDetails['exec'], 1);
+                       foreach ($executables as $executable) {
+                                       // If at least one executable file is not available, exit early returning FALSE
+                               if (!t3lib_exec::checkCommand($executable)) {
+                                       self::deactivateService($serviceType, $serviceKey);
+                                       return FALSE;
+                               }
+                       }
+               }
+                       // The service is available
+               return TRUE;
+       }
+
+       /**
         * Deactivate a service
         *
         * @param       string          Service type
index d9860f8..b58da1b 100644 (file)
@@ -152,11 +152,12 @@ class tx_sv_reports_ServicesList implements tx_reports_Report {
                        <p class="service-header">
                                <span class="service-title">' . $serviceInformation['title'] . '</span> (' . $serviceInformation['extKey'] . ': ' . $serviceKey . ')
                        </p>';
+
                if (!empty($serviceInformation['description'])) {
                        $serviceDescription .= '<p class="service-description">' . $serviceInformation['description']. '</p>';
                }
 
-               $sericeSubtypes = empty($serviceInformation['serviceSubTypes']) ?
+               $serviceSubtypes = empty($serviceInformation['serviceSubTypes']) ?
                        '-' :
                        implode(', ', $serviceInformation['serviceSubTypes']);
 
@@ -170,9 +171,15 @@ class tx_sv_reports_ServicesList implements tx_reports_Report {
 
                $serviceAvailabilityClass = 'typo3-message message-error';
                $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
-               if (t3lib_extmgm::findService($serviceKey, '*')) {
-                       $serviceAvailabilityClass = 'typo3-message message-ok';
-                       $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
+               try {
+                       $serviceDetails = t3lib_extmgm::findServiceByKey($serviceKey);
+                       if ($serviceDetails['available']) {
+                               $serviceAvailabilityClass = 'typo3-message message-ok';
+                               $serviceAvailable = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
+                       }
+               }
+               catch (t3lib_exception $e) {
+                       // Nothing to do, the default display is already not available
                }
 
                $serviceRow = '
@@ -180,7 +187,7 @@ class tx_sv_reports_ServicesList implements tx_reports_Report {
                        <td class="first-cell ' . $serviceAvailabilityClass . '">' . $serviceDescription . '</td>
                        <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['priority'] . '</td>
                        <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceInformation['quality'] . '</td>
-                       <td class="cell ' . $serviceAvailabilityClass . '">' . $sericeSubtypes . '</td>
+                       <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceSubtypes . '</td>
                        <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceOperatingSystem . '</td>
                        <td class="cell ' . $serviceAvailabilityClass . '">' . $serviceRequiredExecutables . '</td>
                        <td class="last-cell ' . $serviceAvailabilityClass . '">' . $serviceAvailable . '</td>