function doSearch($command, $options, $params)
{
if ((!isset($params[0]) || empty($params[0])) && (!isset($params[1]) || empty($params[1]))) {
return $this->raiseError('no valid search string supplied');
}
$channelinfo = isset($options['channelinfo']);
$reg =& $this->config->getRegistry();
if (isset($options['allchannels'])) {
// search all channels
unset($options['allchannels']);
$channels = $reg->getChannels();
$errors = array();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
foreach ($channels as $channel) {
if ($channel->getName() != '__uri') {
$options['channel'] = $channel->getName();
$ret = $this->doSearch($command, $options, $params);
if (PEAR::isError($ret)) {
$errors[] = $ret;
}
}
}
PEAR::staticPopErrorHandling();
if (count($errors) !== 0) {
// for now, only give first error
return PEAR::raiseError($errors[0]);
}
return true;
}
$savechannel = $channel = $this->config->get('default_channel');
$package = strtolower($params[0]);
$summary = isset($params[1]) ? $params[1] : false;
if (isset($options['channel'])) {
$reg =& $this->config->getRegistry();
$channel = $options['channel'];
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
$this->config->set('default_channel', $channel);
}
$chan = $reg->getChannel($channel);
if (PEAR::isError($e = $this->_checkChannelForStatus($channel, $chan))) {
return $e;
}
if ($chan->supportsREST($this->config->get('preferred_mirror')) && ($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror')))) {
$rest =& $this->config->getREST('1.0', array());
$available = $rest->listAll($base, false, false, $package, $summary, $chan->getName());
}
if (PEAR::isError($available)) {
$this->config->set('default_channel', $savechannel);
return $this->raiseError($available);
}
if (!$available && !$channelinfo) {
// clean exit when not found, no error !
$data = 'no packages found that match pattern "' . $package . '", for channel ' . $channel . '.';
$this->ui->outputData($data);
$this->config->set('default_channel', $channel);
return true;
}
if ($channelinfo) {
$data = array('caption' => 'Matched packages, channel ' . $channel . ':', 'border' => true, 'headline' => array('Channel', 'Package', 'Stable/(Latest)', 'Local'), 'channel' => $channel);
} else {
$data = array('caption' => 'Matched packages, channel ' . $channel . ':', 'border' => true, 'headline' => array('Package', 'Stable/(Latest)', 'Local'), 'channel' => $channel);
}
if (!$available && $channelinfo) {
unset($data['headline']);
$data['data'] = 'No packages found that match pattern "' . $package . '".';
$available = array();
}
foreach ($available as $name => $info) {
$installed = $reg->packageInfo($name, null, $channel);
$desc = $info['summary'];
if (isset($params[$name])) {
$desc .= "\n\n" . $info['description'];
}
if (!isset($info['stable']) || !$info['stable']) {
$version_remote = 'none';
} else {
if ($info['unstable']) {
$version_remote = $info['unstable'];
} else {
$version_remote = $info['stable'];
}
$version_remote .= ' (' . $info['state'] . ')';
}
$version = is_array($installed['version']) ? $installed['version']['release'] : $installed['version'];
if ($channelinfo) {
$packageinfo = array($channel, $name, $version_remote, $version, $desc);
} else {
$packageinfo = array($name, $version_remote, $version, $desc);
}
$data['data'][$info['category']][] = $packageinfo;
}
$this->ui->outputData($data, $command);
$this->config->set('default_channel', $channel);
return true;
}