fix for bug in pear's Registry class, check causes check_install.php to run forever, if the registries install_dir does NOT exist

This commit is contained in:
Ralf Becker 2007-06-14 18:58:38 +00:00
parent f241911ce7
commit f07036567f

View File

@ -11,6 +11,7 @@
/* $Id$ */ /* $Id$ */
@set_time_limit(0);
$run_by_webserver = !!$_SERVER['PHP_SELF']; $run_by_webserver = !!$_SERVER['PHP_SELF'];
$is_windows = strtoupper(substr(PHP_OS,0,3)) == 'WIN'; $is_windows = strtoupper(substr(PHP_OS,0,3)) == 'WIN';
@ -247,19 +248,24 @@
if (!class_exists('PEAR_Config')) return false; if (!class_exists('PEAR_Config')) return false;
$config = new PEAR_Config('',$pear_config); $config = new PEAR_Config('',$pear_config);
//echo "<pre>config = ".print_r($config,true)."</pre>\n"; //echo "<pre>config = ".print_r($config,true)."</pre>\n";
$channel = $config->get('default_channel'); $channel = $config->get('default_channel');
//echo "<pre>channel = ".print_r($channel,true)."</pre>\n"; //echo "<pre>channel = ".print_r($channel,true)."</pre>\n";
if (!method_exists($config,'getRegistry')) return false; // PEAR version to old if (!method_exists($config,'getRegistry')) return false; // PEAR version to old
$reg = &$config->getRegistry(); $reg = &$config->getRegistry();
//echo "<pre>reg = ".print_r($reg,true)."</pre>\n"; //echo "<pre>reg = ".print_r($reg,true)."</pre>\n";
// a bug in pear causes an endless loop if the install-dir does not exist
// bug reported: http://pear.php.net/bugs/bug.php?id=11317
if (!file_exists($reg->install_dir)) return false;
$installed = $reg->packageInfo(null,null,$channel); $installed = $reg->packageInfo(null,null,$channel);
//echo "<pre>installed =".print_r($installed,true)."</pre>\n"; //echo "<pre>installed =".print_r($installed,true)."</pre>\n";
$packages = array(); $packages = array();
foreach($installed as $package) foreach($installed as $package)
{ {
$name = isset($package['package']) ? $package['package'] : $package['name']; $name = isset($package['package']) ? $package['package'] : $package['name'];
@ -286,11 +292,13 @@
{ {
$pear_packages = get_installed_pear_packages(); $pear_packages = get_installed_pear_packages();
} }
$version_available = false;
// check if egw-pear is availible and packages is included // check if egw-pear is availible and packages is included
if ($package && is_dir('../egw-pear') && file_exists('../egw-pear/'.str_replace('_','/',$package).'.php')) if ($package && is_dir('../egw-pear') && file_exists('../egw-pear/'.str_replace('_','/',$package).'.php'))
{ {
$available = true; $available = true;
$version_availible = '999.egw-pear'; $version_available = '999.egw-pear';
} }
// packages found in the pear registry --> use that info // packages found in the pear registry --> use that info
elseif ($pear_packages) elseif ($pear_packages)
@ -299,30 +307,30 @@
// check if package is installed // check if package is installed
if ($package && isset($pear_packages[$package])) $available = true; if ($package && isset($pear_packages[$package])) $available = true;
// check if it's the right version // check if it's the right version
$version_availible = $pear_packages[$package ? $package : 'PEAR']; $version_available = $pear_packages[$package ? $package : 'PEAR'];
} }
else // use the old checks as fallback else // use the old checks as fallback
{ {
if (is_null($pear_available)) if (is_null($pear_available))
{ {
$pear_available = @include('PEAR.php'); $pear_available = @include_once('PEAR.php');
if (!class_exists('PEAR')) $pear_available = false; if (!class_exists('PEAR')) $pear_available = false;
} }
if ($pear_available && $package) if ($pear_available && $package)
{ {
$file = str_replace('_','/',$package).'.php'; $file = str_replace('_','/',$package).'.php';
$available = @include($file);
$available = @include_once($file);
if (!class_exists($package)) $available = false; if (!class_exists($package)) $available = false;
} }
} }
// is the right version availible // is the right version availible
$available = $pear_available && (!$package || $available) && (!$min_version || version_compare($min_version,$version_availible) <= 0); $available = $pear_available && (!$package || $available) && (!$min_version || version_compare($min_version,$version_available) <= 0);
echo '<div>'.($available ? $passed_icon : $warning_icon).' <span'.($available ? '' : ' class="setup_warning"').'>'. echo '<div>'.($available ? $passed_icon : $warning_icon).' <span'.($available ? '' : ' class="setup_warning"').'>'.
lang('Checking PEAR%1 is installed',($package?'::'.$package:'').($min_version?" ($min_version)":'')).': '. lang('Checking PEAR%1 is installed',($package?'::'.$package:'').($min_version?" ($min_version)":'')).': '.
($available ? ($version_availible ? $version_availible : lang('True')) : lang('False'))."</span></div>\n"; ($available ? ($version_available ? $version_available : lang('True')) : lang('False'))."</span></div>\n";
if (!$available) // give further info only if not availible if (!$available) // give further info only if not availible
{ {
@ -334,14 +342,14 @@
echo ' '.lang('PEAR (%1) is a PHP repository and is usually in a package called %2.', echo ' '.lang('PEAR (%1) is a PHP repository and is usually in a package called %2.',
'<a href="http://pear.php.net" target="_blank">pear.php.net</a>','php-pear'); '<a href="http://pear.php.net" target="_blank">pear.php.net</a>','php-pear');
} }
elseif ($min_version && !$version_availible) elseif ($min_version && !$version_available)
{ {
echo ' '.lang('We could not determine the version of %1, please make sure it is at least %2',$package,$min_version); 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) elseif ($min_version && version_compare($min_version,$version_available) > 0)
{ {
echo ' '.lang('Your installed version of %1 is %2, required is at least %3, please run: ', echo ' '.lang('Your installed version of %1 is %2, required is at least %3, please run: ',
$package,$version_availible,$min_version).' pear update '.$package; $package,$version_available,$min_version).' pear update '.$package;
} }
elseif ($package) elseif ($package)
{ {