function _getPackageDownloadUrl($parr)
{
$curchannel = $this->config->get('default_channel');
$this->configSet('default_channel', $parr['channel']);
// getDownloadURL returns an array. On error, it only contains information
// on the latest release as array(version, info). On success it contains
// array(version, info, download url string)
$state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
if (!$this->_registry->channelExists($parr['channel'])) {
do {
if ($this->config->get('auto_discover') && $this->discover($parr['channel'])) {
break;
}
$this->configSet('default_channel', $curchannel);
return PEAR::raiseError('Unknown remote channel: ' . $parr['channel']);
} while (false);
}
$chan =& $this->_registry->getChannel($parr['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$version = $this->_registry->packageInfo($parr['package'], 'version', $parr['channel']);
$stability = $this->_registry->packageInfo($parr['package'], 'stability', $parr['channel']);
// package is installed - use the installed release stability level
if (!isset($parr['state']) && $stability !== null) {
$state = $stability['release'];
}
PEAR::staticPopErrorHandling();
$base2 = false;
$preferred_mirror = $this->config->get('preferred_mirror');
if (!$chan->supportsREST($preferred_mirror) || !($base2 = $chan->getBaseURL('REST1.3', $preferred_mirror)) && !($base = $chan->getBaseURL('REST1.0', $preferred_mirror))) {
return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
}
if ($base2) {
$rest =& $this->config->getREST('1.3', $this->_options);
$base = $base2;
} else {
$rest =& $this->config->getREST('1.0', $this->_options);
}
$downloadVersion = false;
if (!isset($parr['version']) && !isset($parr['state']) && $version && !PEAR::isError($version) && !isset($this->_options['downloadonly'])) {
$downloadVersion = $version;
}
$url = $rest->getDownloadURL($base, $parr, $state, $downloadVersion, $chan->getName());
if (PEAR::isError($url)) {
$this->configSet('default_channel', $curchannel);
return $url;
}
if ($parr['channel'] != $curchannel) {
$this->configSet('default_channel', $curchannel);
}
if (!is_array($url)) {
return $url;
}
$url['raw'] = false;
// no checking is necessary for REST
if (!is_array($url['info'])) {
return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' . 'this should never happen');
}
if (!isset($this->_options['force']) && !isset($this->_options['downloadonly']) && $version && !PEAR::isError($version) && !isset($parr['group'])) {
if (version_compare($version, $url['version'], '=')) {
return PEAR::raiseError($this->_registry->parsedPackageNameToString($parr, true) . ' is already installed and is the same as the ' . 'released version ' . $url['version'], -976);
}
if (version_compare($version, $url['version'], '>')) {
return PEAR::raiseError($this->_registry->parsedPackageNameToString($parr, true) . ' is already installed and is newer than detected ' . 'released version ' . $url['version'], -976);
}
}
if (isset($url['info']['required']) || $url['compatible']) {
require_once 'PEAR/PackageFile/v2.php';
$pf = new PEAR_PackageFile_v2();
$pf->setRawChannel($parr['channel']);
if ($url['compatible']) {
$pf->setRawCompatible($url['compatible']);
}
} else {
require_once 'PEAR/PackageFile/v1.php';
$pf = new PEAR_PackageFile_v1();
}
$pf->setRawPackage($url['package']);
$pf->setDeps($url['info']);
if ($url['compatible']) {
$pf->setCompatible($url['compatible']);
}
$pf->setRawState($url['stability']);
$url['info'] =& $pf;
if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
$ext = '.tar';
} else {
$ext = '.tgz';
}
if (is_array($url) && isset($url['url'])) {
$url['url'] .= $ext;
}
return $url;
}