From 5a397b7acbdf110be72907c26baad470f7ade5b5 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 1 Jan 2007 14:33:43 +0000 Subject: [PATCH] imporved pear_check: a) check the version of required pear packages, if given in the key 'version'. It uses the pear registry for that. b) if 'egw-pear' exists AND included the package, it allways fullfils the requirements --- setup/check_install.php | 126 ++++++++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 25 deletions(-) diff --git a/setup/check_install.php b/setup/check_install.php index 777a565427..c1811fa64d 100644 --- a/setup/check_install.php +++ b/setup/check_install.php @@ -14,7 +14,6 @@ $run_by_webserver = !!$_SERVER['PHP_SELF']; $is_windows = strtoupper(substr(PHP_OS,0,3)) == 'WIN'; - if ($run_by_webserver) { $GLOBALS['egw_info'] = array( @@ -223,52 +222,129 @@ { global $passed_icon, $error_icon; - $version_ok = (float) phpversion() >= $args['value']; + $version_ok = version_compare(phpversion(),$args['value']) >= 0; echo '
'.($version_ok ? $passed_icon : $error_icon).' '. lang('Checking required PHP version %1 (recommended %2)',$args['verbose_value'],$args['recommended']).': '. phpversion().' ==> '.($version_ok ? lang('True') : lang('False'))."
\n"; } + /** + * quering the pear registry to find out which pear packages and versions are installed + * + * @return array with package-name => version pairs, eg. array('Log' => '1.9.8','PEAR' => '1.4.11') + */ + function get_installed_pear_packages() + { + $pear_config = ''; // use the system default + // fix for SuSE having the pear.conf only for cli, will fail with open_basedir - no idea what to do then + if (@is_dir('/etc/php5/apache2') && !file_exists('/etc/php5/apache2/pear.conf') && @file_exists('/etc/php5/cli/pear.conf')) + { + $pear_config = '/etc/php5/cli/pear.conf'; + } + @require_once 'PEAR/Config.php'; + + if (!class_exists('PEAR_Config')) return false; + + $config = new PEAR_Config('',$pear_config); + //echo "
config = ".print_r($config,true)."
\n"; + + $channel = $config->get('default_channel'); + //echo "
channel = ".print_r($channel,true)."
\n"; + + $reg = &$config->getRegistry(); + //echo "
reg = ".print_r($reg,true)."
\n"; + + $installed = $reg->packageInfo(null,null,$channel); + //echo "
installed =".print_r($installed,true)."
\n"; + $packages = array(); + foreach($installed as $package) + { + $name = isset($package['package']) ? $package['package'] : $package['name']; + $version = $package['version']; + if (is_array($version)) $version = $version['release']; + + $packages[$name] = $version; + // echo "

$name: ".print_r($package['version'],true)."

\n"; + } + ksort($packages); + + return $packages; + } + function pear_check($package,$args) { global $passed_icon, $warning_icon; static $pear_available = null; + static $pear_packages = null; - if (is_null($pear_available)) - { - $pear_available = @include('PEAR.php'); + $min_version = isset($args['version']) ? $args['version'] : null; - if (!class_exists('PEAR')) $pear_available = false; - - echo '
'.($pear_available ? $passed_icon : $warning_icon).' '. - lang('Checking PEAR%1 is installed','').': '.($pear_available ? lang('True') : lang('False'))."
\n"; - } - if ($pear_available && $package) + if (is_null($pear_packages)) { - $file = str_replace('_','/',$package).'.php'; - $available = @include($file); - - if (!class_exists($package)) $available = false; - - echo '
'.($available ? $passed_icon : $warning_icon).' '. - lang('Checking PEAR%1 is installed','::'.$package).': '.($available ? lang('True') : lang('False'))."
\n"; + $pear_packages = get_installed_pear_packages(); } - $available = $pear_available && (!$package || $available); + // check if egw-pear is availible and packages is included + if ($package && is_dir('../egw-pear') && file_exists('../egw-pear/'.str_replace('_','/',$package).'.php')) + { + $available = true; + $version_availible = '999.egw-pear'; + } + // packages found in the pear registry --> use that info + elseif ($pear_packages) + { + $pear_available = true; + // check if package is installed + if ($package && isset($pear_packages[$package])) $available = true; + // check if it's the right version + $version_availible = $pear_packages[$package ? $package : 'PEAR']; + } + else // use the old checks as fallback + { + if (is_null($pear_available)) + { + $pear_available = @include('PEAR.php'); - if (!$available) + if (!class_exists('PEAR')) $pear_available = false; + } + if ($pear_available && $package) + { + $file = str_replace('_','/',$package).'.php'; + $available = @include($file); + + if (!class_exists($package)) $available = false; + } + } + // is the right version availible + $available = $pear_available && (!$package || $available) && (!$min_version || version_compare($min_version,$version_availible) <= 0); + + echo '
'.($available ? $passed_icon : $warning_icon).' '. + lang('Checking PEAR%1 is installed',($package?'::'.$package:'').($min_version?" ($min_version)":'')).': '. + ($available ? ($version_availible ? $version_availible : lang('True')) : lang('False'))."
\n"; + + if (!$available) // give further info only if not availible { echo '
' . lang('PEAR%1 is needed by: %2.',$package ? '::'.$package : '', is_array($args['from']) ? implode(', ',$args['from']) : $args['from']); - if ($package) - { - echo ' '.lang('You can install it by running:').' pear install '.$package; - } - else + + if (!$pear_available) { echo ' '.lang('PEAR (%1) is a PHP repository and is usually in a package called %2.', 'pear.php.net','php-pear'); } + elseif ($min_version && !$version_availible) + { + echo ' '.lang('We could not determine the version of %1, please make sure it is at least %2',$package,$min_version); + } + elseif ($min_version && version_compare($min_version,$version_availible) > 0) + { + echo ' '.lang('Your installed version of %1 is %2, required is at least %3, please run: ', + $package,$version_availible,$min_version).' pear update '.$package; + } + elseif ($package) + { + echo ' '.lang('You can install it by running:').' pear install '.$package; + } echo "
"; } echo "\n";