_checkChannelForStatus() public method

public _checkChannelForStatus ( $channel, $chan )
Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see lib/Faett/Core/Interfaces/Faett_Core_Interfaces_Service#packageInfo($packageName, $channel)
  */
 public function packageInfo($packageName, $channel)
 {
     // store the default channel
     $savechannel = $this->_config->get('default_channel');
     // check if the cannel already exists
     if ($this->_registry->channelExists($channel)) {
         $this->_config->set('default_channel', $channel);
     } else {
         // throw a new exception
         throw Faett_Core_Exceptions_UnknownChannelException::create('Channel ' . $channel . ' does not exist');
     }
     // load the channel from the registry
     $chan = $this->_registry->getChannel($channel);
     // initialize a REST command for checking the channel's state
     $cmd = new PEAR_Command_Remote($this->_ui, $this->_config);
     if (PEAR::isError($e = $cmd->_checkChannelForStatus($channel, $chan))) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_UnknownChannelStateException::create($e->getMessage());
     }
     // get the channel's base URL
     $base = $chan->getBaseURL('REST1.0', $this->_config->get('preferred_mirror'));
     // check if the channel's server is REST enabled
     $restSupport = $chan->supportsREST($this->_config->get('preferred_mirror'));
     // check if the channel is REST enabled
     if ($restSupport && $base) {
         // load the channel data and the package information
         $rest = $this->_config->getREST('1.0', array());
         $info = $rest->packageInfo($base, $packageName);
     } else {
         $r = $this->_config->getRemote();
         $info = $r->call('package.info', $packageName);
     }
     // check if the package information was loaded successfully
     if (PEAR::isError($info)) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_PackageInfoException::create($info->getMessage());
     }
     // if no packge name was found log an error message
     if (!isset($info['name'])) {
         // reset the default channel
         $this->_config->set('default_channel', $savechannel);
         // throw a new exception
         throw Faett_Core_Exceptions_PackageInfoException::create('Can\'t find a package name');
     }
     // check if the package is installed
     $installed = $this->_registry->packageInfo($info['name'], null, $channel);
     // if yes, set the information
     $info['installed'] = $installed['version'] ? $installed['version'] : '';
     if (is_array($info['installed'])) {
         $info['installed'] = $info['installed']['release'];
     }
     // return the package information
     return $info;
 }
    function doListCategory($command, $options, $params)
    {
        if (count($params) < 1) {
            return PEAR::raiseError('Not enough parameters, use: '.$command.' <category> [<category>...]');
        }
        if (count($params) > 1) {
            $errors = array();
            foreach($params as $pkg) {
                $ret = $this->doListCategory($command, $options, array($pkg));
                if ($ret !== true) {
                    $errors[] = $ret;
                    return $ret;
                }
            }
            if (count($errors) !== 0) {
                // for now, only give first error
                return $errors[0];
            }
            return true;
        }
        $category = $params[0];
            
        $savechannel = $channel = $this->config->get('default_channel');
        $reg = &$this->config->getRegistry();
        if (isset($options['channel'])) {
            $channel = $options['channel'];
            if ($reg->channelExists($channel)) {
                $this->config->set('default_channel', $channel);
            } else {
                return $this->raiseError("Channel \"$channel\" does not exist");
            }
        }
        $chan = $reg->getChannel($channel);
        // we need Remote::_checkChannelForStatus()
        require_once 'PEAR/Command/Remote.php';
        //$cmd = new PEAR_Command_Remote($this->ui, $this->config);
        //if (PEAR::isError($e = $cmd->_checkChannelForStatus($channel, $chan))) {
        if (PEAR::isError($e = PEAR_Command_Remote::_checkChannelForStatus($channel, $chan))) {
            return $e;
        }
        if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
              $base = $chan->getBaseURL('REST1.1', $this->config->get('preferred_mirror'))) {
            $rest = &$this->config->getREST('1.1', array());
        } elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
              $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
            $rest = &$this->config->getREST('1.0', array());
        } else {
            return PEAR::raiseError($command.' only works for REST servers');
        }
        $packages = $rest->listCategory($base, $category, true);
        if (PEAR::isError($packages)) {
            $this->config->set('default_channel', $savechannel);
            return $this->raiseError('The package list could not be fetched from the remote server. Please try again. (Debug info: "' . $packages->getMessage() . '")');
        }

        $data = array(
            'caption' => 'Channel '.$channel.' Category '.$category.' All packages:',
            'border' => true,
            'headline' => array('Channel', 'Package', 'Local', 'Remote', 'Summary'),
            'channel' => $channel,
            );
        if (count($packages) === 0) {
            unset($data['headline']);
            $data['data'] = 'No packages registered';
        } else {
            $data['data'] = array();
            foreach ($packages as $package_data) {
                $package = $package_data['_content'];
                $info = $package_data['info'];
                if (!isset($info['v'])) {
                    $remote = '-';
                } else {
                    $remote = $info['v'].' ('.$info['st'].')';
                }
                $summary = $info['s'];
                if ($reg->packageExists($package, $channel)) {
                    $local = sprintf('%s (%s)',
                        $reg->packageInfo($package, 'version', $channel),
                        $reg->packageInfo($package, 'release_state', $channel));
                } else {
                    $local = '-';
                }
                $data['data'][] = array($channel, $package, $local, $remote, $summary);
            }
        }

        $this->config->set('default_channel', $savechannel);
        $this->ui->outputData($data, $command);
        return true;
    }
 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');
     }
     $reg =& $this->config->getRegistry();
     if ($options['allchannels'] == true) {
         // search all channels
         unset($options['allchannels']);
         $channels = $reg->getChannels();
         foreach ($channels as $channel) {
             if ($channel->getName() != '__uri') {
                 $options['channel'] = $channel->getName();
                 $ret = $this->doSearch($command, $options, $params);
                 if ($ret !== true) {
                     return $ret;
                 }
             }
         }
         return true;
     }
     require_once 'PEAR/Command/Remote.php';
     $cmd = new PEAR_Command_Remote(&$this->ui, &$this->config);
     $savechannel = $channel = $this->config->get('default_channel');
     $package = $params[0];
     $summary = isset($params[1]) ? $params[1] : false;
     if (isset($options['channel'])) {
         $reg =& $this->config->getRegistry();
         $channel = $options['channel'];
         if ($reg->channelExists($channel)) {
             $this->config->set('default_channel', $channel);
         } else {
             return $this->raiseError('Channel "' . $channel . '" does not exist');
         }
     }
     $chan = $reg->getChannel($channel);
     if (PEAR::isError($e = $cmd->_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 = $this->REST_listAll(&$rest, $base, false, false, $package, $summary);
     } else {
         $r =& $this->config->getRemote();
         $available = $r->call('package.search', $package, $summary, true, $this->config->get('preferred_state') == 'stable', true);
     }
     if (PEAR::isError($available)) {
         $this->config->set('default_channel', $savechannel);
         return $this->raiseError($available);
     }
     $data = array('caption' => 'Matched packages, channel ' . $channel . ':', 'border' => true, 'headline' => array('Channel', 'Package', 'Stable/(Latest)', 'Local'));
     // clean exit, no error !
     if (!$available) {
         unset($data['headline']);
         $data['data'] = 'No packages found that match pattern "' . $package . '".';
     } else {
         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'];
             $data['data'][$info['category']][] = array($channel, $name, $version_remote, $version, $desc);
         }
     }
     $this->ui->outputData($data, $command);
     $this->config->set('default_channel', $channel);
     return true;
 }