[BUGFIX] check for required PHP modules in Reports module
authorJigal van Hemert <jigal@xs4all.nl>
Mon, 19 Sep 2011 23:48:52 +0000 (01:48 +0200)
committerErnesto Baschny <ernst@cron-it.de>
Tue, 20 Sep 2011 13:17:29 +0000 (15:17 +0200)
The 1-2-3 installer checks for the presence of the required PHP modules. The
Reports module needs to perform this check to catch problems in many
situations.

Change-Id: I0b19bfb4d0f6a5bdd48ba8df9869ecfc4dd3a2d6
Fixes: #30054
Releases: 4.6
Reviewed-on: http://review.typo3.org/5094
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-by: Oliver Hader
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
typo3/sysext/reports/reports/locallang.xlf
typo3/sysext/reports/reports/status/class.tx_reports_reports_status_systemstatus.php

index 019eeaf..81fac5d 100644 (file)
                                <source>Web Server</source>
                                <target>Web Server</target>
                        </trans-unit>
+                       <trans-unit id="status_phpModules" approved="yes">
+                               <source>PHP Modules</source>
+                               <target>PHP Modules</target>
+                       </trans-unit>
+                       <trans-unit id="status_phpModulesMissing" approved="yes">
+                               <source>One or more modules are missing.</source>
+                               <target>One or more modules are missing.</target>
+                       </trans-unit>
+                       <trans-unit id="status_phpModulesList" approved="yes">
+                               <source>The following PHP module(s) is/are missing: %s.</source>
+                               <target>The following PHP module(s) is/are missing: %s.</target>
+                       </trans-unit>
+                       <trans-unit id="status_phpModulesInfo" approved="yes">
+                               <source>You need to install and enable these modules to let TYPO3 function correctly.</source>
+                               <target>You need to install and enable these modules to let TYPO3 function correctly.</target>
+                       </trans-unit>
+                       <trans-unit id="status_phpModulesGroup" approved="yes">
+                               <source>one of: %s</source>
+                               <target>one of: %s</target>
+                       </trans-unit>
+                       <trans-unit id="status_phpModulesPresent" approved="yes">
+                               <source>All required modules are installed.</source>
+                               <target>All required modules are installed.</target>
+                       </trans-unit>
                        <trans-unit id="status_installEnabledTemporarily" approved="yes">
                                <source>The Install Tool is temporarily enabled. Delete the file "%s" when you have finished setting up TYPO3. If not used the Install Tool will be disabled automatically in %s minutes.</source>
                                <target>The Install Tool is temporarily enabled. Delete the file "%s" when you have finished setting up TYPO3. If not used the Install Tool will be disabled automatically in %s minutes.</target>
index 98bcf36..15a6615 100644 (file)
  */
 class tx_reports_reports_status_SystemStatus implements tx_reports_StatusProvider {
 
+               // PHP modules which are required. Can be changed by hook in getMissingPhpModules()
+       protected $requiredPhpModules = array(
+               'filter', 'gd', 'json', 'mysql', 'pcre', 'session', 'SPL', 'standard', 'openssl', 'xml', 'zlib'
+       );
+
        /**
         * Determines the Install Tool's status, mainly concerning its protection.
         *
@@ -47,6 +52,7 @@ class tx_reports_reports_status_SystemStatus implements tx_reports_StatusProvide
                        'PhpPeakMemory'       => $this->getPhpPeakMemoryStatus(),
                        'PhpRegisterGlobals'  => $this->getPhpRegisterGlobalsStatus(),
                        'Webserver'           => $this->getWebserverStatus(),
+                       'PhpModules'          => $this->getMissingPhpModules(),
                );
 
                return $statuses;
@@ -204,6 +210,51 @@ class tx_reports_reports_status_SystemStatus implements tx_reports_StatusProvide
                        $_SERVER['SERVER_SOFTWARE']
                );
        }
+
+       /**
+        * Reports whether any of the required PHP modules are missing
+        *
+        * @return tx_reports_reports_status_Status A status of missing PHP modules
+        */
+       protected function getMissingPhpModules() {
+                       // Hook to adjust the required PHP modules
+               $modules = $this->requiredPhpModules;
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules'] as $classData) {
+                               $hookObject = t3lib_div::getUserObj($classData);
+                               $modules = $hookObject->setRequiredPhpModules($modules, $this);
+                       }
+               }
+               $missingPhpModules = array();
+               foreach ($modules as $module) {
+                       if (is_array($module)) {
+                               $detectedSubmodules = FALSE;
+                               foreach ($module as $submodule) {
+                                       if (extension_loaded($submodule)) {
+                                               $detectedSubmodules = TRUE;
+                                       }
+                               }
+                               if ($detectedSubmodules === FALSE) {
+                                       $missingPhpModules[] = sprintf($GLOBALS['LANG']->getLL('status_phpModulesGroup'), '(' . implode(', ', $module) . ')');
+                               }
+                       } elseif (!extension_loaded($module)) {
+                               $missingPhpModules[] = $module;
+                       }
+               }
+               if (count($missingPhpModules) > 0) {
+                       $value = $GLOBALS['LANG']->getLL('status_phpModulesMissing');
+                       $message = sprintf($GLOBALS['LANG']->getLL('status_phpModulesList'), implode(', ', $missingPhpModules));
+                       $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpModulesInfo');
+                       $severity = tx_reports_reports_status_Status::ERROR;
+               } else {
+                       $value = $GLOBALS['LANG']->getLL('status_phpModulesPresent');
+                       $message = '';
+                       $severity = tx_reports_reports_status_Status::OK;
+               }
+               return t3lib_div::makeInstance('tx_reports_reports_status_Status',
+                       $GLOBALS['LANG']->getLL('status_phpModules'), $value, $message, $severity
+               );
+       }
 }