PEAR_Command_Remote::_checkChannelForStatus PHP Method

_checkChannelForStatus() public method

public _checkChannelForStatus ( $channel, $chan )
    function _checkChannelForStatus($channel, $chan)
    {
        if (PEAR::isError($chan)) {
            $this->raiseError($chan);
        }
        if (!is_a($chan, 'PEAR_ChannelFile')) {
            return $this->raiseError('Internal corruption error: invalid channel "' . $channel . '"');
        }
        $rest = new PEAR_REST($this->config);
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
        $mirror = $this->config->get('preferred_mirror', null, $channel);
        $a = $rest->downloadHttp('http://' . $channel . '/channel.xml', $chan->lastModified());
        PEAR::staticPopErrorHandling();
        if (!PEAR::isError($a) && $a) {
            $this->ui->outputData('WARNING: channel "' . $channel . '" has ' . 'updated its protocols, use "' . PEAR_RUNTYPE . ' channel-update ' . $channel . '" to update');
        }
    }

Usage Example

 /**
  * (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;
 }
All Usage Examples Of PEAR_Command_Remote::_checkChannelForStatus