PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Remote.php

Documentation is available at Remote.php

  1. <?php
  2. /**
  3.  * PEAR_Command_Remote (remote-info, list-upgrades, remote-list, search, list-all, download,
  4.  * clear-cache commands)
  5.  *
  6.  * PHP versions 4 and 5
  7.  *
  8.  * @category   pear
  9.  * @package    PEAR
  10.  * @author     Stig Bakken <ssb@php.net>
  11.  * @author     Greg Beaver <cellog@php.net>
  12.  * @copyright  1997-2009 The Authors
  13.  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
  14.  * @version    CVS: $Id: Remote.php 313023 2011-07-06 19:17:11Z dufuz $
  15.  * @link       http://pear.php.net/package/PEAR
  16.  * @since      File available since Release 0.1
  17.  */
  18.  
  19. /**
  20.  * base class
  21.  */
  22. require_once 'PEAR/Command/Common.php';
  23. require_once 'PEAR/REST.php';
  24.  
  25. /**
  26.  * PEAR commands for remote server querying
  27.  *
  28.  * @category   pear
  29.  * @package    PEAR
  30.  * @author     Stig Bakken <ssb@php.net>
  31.  * @author     Greg Beaver <cellog@php.net>
  32.  * @copyright  1997-2009 The Authors
  33.  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
  34.  * @version    Release: 1.9.4
  35.  * @link       http://pear.php.net/package/PEAR
  36.  * @since      Class available since Release 0.1
  37.  */
  38. {
  39.     var $commands = array(
  40.         'remote-info' => array(
  41.             'summary' => 'Information About Remote Packages',
  42.             'function' => 'doRemoteInfo',
  43.             'shortcut' => 'ri',
  44.             'options' => array(),
  45.             'doc' => '<package>
  46. Get details on a package from the server.',
  47.             ),
  48.         'list-upgrades' => array(
  49.             'summary' => 'List Available Upgrades',
  50.             'function' => 'doListUpgrades',
  51.             'shortcut' => 'lu',
  52.             'options' => array(
  53.                 'channelinfo' => array(
  54.                     'shortopt' => 'i',
  55.                     'doc' => 'output fully channel-aware data, even on failure',
  56.                     ),
  57.             ),
  58.             'doc' => '[preferred_state]
  59. List releases on the server of packages you have installed where
  60. a newer version is available with the same release state (stable etc.)
  61. or the state passed as the second parameter.'
  62.             ),
  63.         'remote-list' => array(
  64.             'summary' => 'List Remote Packages',
  65.             'function' => 'doRemoteList',
  66.             'shortcut' => 'rl',
  67.             'options' => array(
  68.                 'channel' =>
  69.                     array(
  70.                     'shortopt' => 'c',
  71.                     'doc' => 'specify a channel other than the default channel',
  72.                     'arg' => 'CHAN',
  73.                     )
  74.                 ),
  75.             'doc' => '
  76. Lists the packages available on the configured server along with the
  77. latest stable release of each package.',
  78.             ),
  79.         'search' => array(
  80.             'summary' => 'Search remote package database',
  81.             'function' => 'doSearch',
  82.             'shortcut' => 'sp',
  83.             'options' => array(
  84.                 'channel' =>
  85.                     array(
  86.                     'shortopt' => 'c',
  87.                     'doc' => 'specify a channel other than the default channel',
  88.                     'arg' => 'CHAN',
  89.                     ),
  90.                 'allchannels' => array(
  91.                     'shortopt' => 'a',
  92.                     'doc' => 'search packages from all known channels',
  93.                     ),
  94.                 'channelinfo' => array(
  95.                     'shortopt' => 'i',
  96.                     'doc' => 'output fully channel-aware data, even on failure',
  97.                     ),
  98.                 ),
  99.             'doc' => '[packagename] [packageinfo]
  100. Lists all packages which match the search parameters.  The first
  101. parameter is a fragment of a packagename.  The default channel
  102. will be used unless explicitly overridden.  The second parameter
  103. will be used to match any portion of the summary/description',
  104.             ),
  105.         'list-all' => array(
  106.             'summary' => 'List All Packages',
  107.             'function' => 'doListAll',
  108.             'shortcut' => 'la',
  109.             'options' => array(
  110.                 'channel' =>
  111.                     array(
  112.                     'shortopt' => 'c',
  113.                     'doc' => 'specify a channel other than the default channel',
  114.                     'arg' => 'CHAN',
  115.                     ),
  116.                 'channelinfo' => array(
  117.                     'shortopt' => 'i',
  118.                     'doc' => 'output fully channel-aware data, even on failure',
  119.                     ),
  120.                 ),
  121.             'doc' => '
  122. Lists the packages available on the configured server along with the
  123. latest stable release of each package.',
  124.             ),
  125.         'download' => array(
  126.             'summary' => 'Download Package',
  127.             'function' => 'doDownload',
  128.             'shortcut' => 'd',
  129.             'options' => array(
  130.                 'nocompress' => array(
  131.                     'shortopt' => 'Z',
  132.                     'doc' => 'download an uncompressed (.tar) file',
  133.                     ),
  134.                 ),
  135.             'doc' => '<package>...
  136. Download package tarballs.  The files will be named as suggested by the
  137. server, for example if you download the DB package and the latest stable
  138. version of DB is 1.6.5, the downloaded file will be DB-1.6.5.tgz.',
  139.             ),
  140.         'clear-cache' => array(
  141.             'summary' => 'Clear Web Services Cache',
  142.             'function' => 'doClearCache',
  143.             'shortcut' => 'cc',
  144.             'options' => array(),
  145.             'doc' => '
  146. Clear the REST cache. See also the cache_ttl configuration
  147. parameter.
  148. ',
  149.             ),
  150.         );
  151.  
  152.     /**
  153.      * PEAR_Command_Remote constructor.
  154.      *
  155.      * @access public
  156.      */
  157.     function PEAR_Command_Remote(&$ui&$config)
  158.     {
  159.         parent::PEAR_Command_Common($ui$config);
  160.     }
  161.  
  162.     function _checkChannelForStatus($channel$chan)
  163.     {
  164.         if (PEAR::isError($chan)) {
  165.             $this->raiseError($chan);
  166.         }
  167.         if (!is_a($chan'PEAR_ChannelFile')) {
  168.             return $this->raiseError('Internal corruption error: invalid channel "' .
  169.                 $channel '"');
  170.         }
  171.         $rest = new PEAR_REST($this->config);
  172.         $mirror $this->config->get('preferred_mirror'null,
  173.                                      $channel);
  174.         $a $rest->downloadHttp('http://' $channel .
  175.             '/channel.xml'$chan->lastModified());
  176.         PEAR::staticPopErrorHandling();
  177.         if (!PEAR::isError($a&& $a{
  178.             $this->ui->outputData('WARNING: channel "' $channel '" has ' .
  179.                 'updated its protocols, use "' PEAR_RUNTYPE . ' channel-update ' $channel .
  180.                 '" to update');
  181.         }
  182.     }
  183.  
  184.     function doRemoteInfo($command$options$params)
  185.     {
  186.         if (sizeof($params!= 1{
  187.             return $this->raiseError("$command expects one param: the remote package name");
  188.         }
  189.         $savechannel $channel $this->config->get('default_channel');
  190.         $reg &$this->config->getRegistry();
  191.         $package $params[0];
  192.         $parsed $reg->parsePackageName($package$channel);
  193.         if (PEAR::isError($parsed)) {
  194.             return $this->raiseError('Invalid package name "' $package '"');
  195.         }
  196.  
  197.         $channel $parsed['channel'];
  198.         $this->config->set('default_channel'$channel);
  199.         $chan $reg->getChannel($channel);
  200.         if (PEAR::isError($e $this->_checkChannelForStatus($channel$chan))) {
  201.             return $e;
  202.         }
  203.  
  204.         $mirror $this->config->get('preferred_mirror');
  205.         if ($chan->supportsREST($mirror&& $base $chan->getBaseURL('REST1.0'$mirror)) {
  206.             $rest &$this->config->getREST('1.0'array());
  207.             $info $rest->packageInfo($base$parsed['package']$channel);
  208.         }
  209.  
  210.         if (!isset($info)) {
  211.             return $this->raiseError('No supported protocol was found');
  212.         }
  213.  
  214.         if (PEAR::isError($info)) {
  215.             $this->config->set('default_channel'$savechannel);
  216.             return $this->raiseError($info);
  217.         }
  218.  
  219.         if (!isset($info['name'])) {
  220.             return $this->raiseError('No remote package "' $package '" was found');
  221.         }
  222.  
  223.         $installed $reg->packageInfo($info['name']null$channel);
  224.         $info['installed'$installed['version'$installed['version''- no -';
  225.         if (is_array($info['installed'])) {
  226.             $info['installed'$info['installed']['release'];
  227.         }
  228.  
  229.         $this->ui->outputData($info$command);
  230.         $this->config->set('default_channel'$savechannel);
  231.  
  232.         return true;
  233.     }
  234.  
  235.     function doRemoteList($command$options$params)
  236.     {
  237.         $savechannel $channel $this->config->get('default_channel');
  238.         $reg &$this->config->getRegistry();
  239.         if (isset($options['channel'])) {
  240.             $channel $options['channel'];
  241.             if (!$reg->channelExists($channel)) {
  242.                 return $this->raiseError('Channel "' $channel '" does not exist');
  243.             }
  244.  
  245.             $this->config->set('default_channel'$channel);
  246.         }
  247.  
  248.         $chan $reg->getChannel($channel);
  249.         if (PEAR::isError($e $this->_checkChannelForStatus($channel$chan))) {
  250.             return $e;
  251.         }
  252.  
  253.         $list_options = false;
  254.         if ($this->config->get('preferred_state'== 'stable'{
  255.             $list_options = true;
  256.         }
  257.  
  258.         $available = array();
  259.         if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
  260.               $base $chan->getBaseURL('REST1.1'$this->config->get('preferred_mirror'))
  261.         {
  262.             // use faster list-all if available
  263.             $rest &$this->config->getREST('1.1'array());
  264.             $available $rest->listAll($base$list_optionstruefalsefalse$chan->getName());
  265.         elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
  266.               $base $chan->getBaseURL('REST1.0'$this->config->get('preferred_mirror'))) {
  267.             $rest &$this->config->getREST('1.0'array());
  268.             $available $rest->listAll($base$list_optionstruefalsefalse$chan->getName());
  269.         }
  270.  
  271.         if (PEAR::isError($available)) {
  272.             $this->config->set('default_channel'$savechannel);
  273.             return $this->raiseError($available);
  274.         }
  275.  
  276.         $i $j = 0;
  277.         $data = array(
  278.             'caption' => 'Channel ' $channel ' Available packages:',
  279.             'border' => true,
  280.             'headline' => array('Package''Version'),
  281.             'channel' => $channel
  282.             );
  283.  
  284.         if (count($available== 0{
  285.             $data '(no packages available yet)';
  286.         else {
  287.             foreach ($available as $name => $info{
  288.                 $version (isset($info['stable']&& $info['stable']$info['stable''-n/a-';
  289.                 $data['data'][= array($name$version);
  290.             }
  291.         }
  292.         $this->ui->outputData($data$command);
  293.         $this->config->set('default_channel'$savechannel);
  294.         return true;
  295.     }
  296.  
  297.     function doListAll($command$options$params)
  298.     {
  299.         $savechannel $channel $this->config->get('default_channel');
  300.         $reg &$this->config->getRegistry();
  301.         if (isset($options['channel'])) {
  302.             $channel $options['channel'];
  303.             if (!$reg->channelExists($channel)) {
  304.                 return $this->raiseError("Channel \"$channel\" does not exist");
  305.             }
  306.  
  307.             $this->config->set('default_channel'$channel);
  308.         }
  309.  
  310.         $list_options = false;
  311.         if ($this->config->get('preferred_state'== 'stable'{
  312.             $list_options = true;
  313.         }
  314.  
  315.         $chan $reg->getChannel($channel);
  316.         if (PEAR::isError($e $this->_checkChannelForStatus($channel$chan))) {
  317.             return $e;
  318.         }
  319.  
  320.         if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
  321.               $base $chan->getBaseURL('REST1.1'$this->config->get('preferred_mirror'))) {
  322.             // use faster list-all if available
  323.             $rest &$this->config->getREST('1.1'array());
  324.             $available $rest->listAll($base$list_optionsfalsefalsefalse$chan->getName());
  325.         elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
  326.               $base $chan->getBaseURL('REST1.0'$this->config->get('preferred_mirror'))) {
  327.             $rest &$this->config->getREST('1.0'array());
  328.             $available $rest->listAll($base$list_optionsfalsefalsefalse$chan->getName());
  329.         }
  330.  
  331.         if (PEAR::isError($available)) {
  332.             $this->config->set('default_channel'$savechannel);
  333.             return $this->raiseError('The package list could not be fetched from the remote server. Please try again. (Debug info: "' $available->getMessage('")');
  334.         }
  335.  
  336.         $data = array(
  337.             'caption' => 'All packages [Channel ' $channel ']:',
  338.             'border' => true,
  339.             'headline' => array('Package''Latest''Local'),
  340.             'channel' => $channel,
  341.             );
  342.  
  343.         if (isset($options['channelinfo'])) {
  344.             // add full channelinfo
  345.             $data['caption''Channel ' $channel ' All packages:';
  346.             $data['headline'= array('Channel''Package''Latest''Local',
  347.                 'Description''Dependencies');
  348.         }
  349.         $local_pkgs $reg->listPackages($channel);
  350.  
  351.         foreach ($available as $name => $info{
  352.             $installed $reg->packageInfo($namenull$channel);
  353.             if (is_array($installed['version'])) {
  354.                 $installed['version'$installed['version']['release'];
  355.             }
  356.             $desc $info['summary'];
  357.             if (isset($params[$name])) {
  358.                 $desc .= "\n\n".$info['description'];
  359.             }
  360.             if (isset($options['mode']))
  361.             {
  362.                 if ($options['mode'== 'installed' && !isset($installed['version'])) {
  363.                     continue;
  364.                 }
  365.                 if ($options['mode'== 'notinstalled' && isset($installed['version'])) {
  366.                     continue;
  367.                 }
  368.                 if ($options['mode'== 'upgrades'
  369.                       && (!isset($installed['version']|| version_compare($installed['version'],
  370.                       $info['stable']'>='))) {
  371.                     continue;
  372.                 }
  373.             }
  374.             $pos array_search(strtolower($name)$local_pkgs);
  375.             if ($pos !== false{
  376.                 unset($local_pkgs[$pos]);
  377.             }
  378.  
  379.             if (isset($info['stable']&& !$info['stable']{
  380.                 $info['stable'= null;
  381.             }
  382.  
  383.             if (isset($options['channelinfo'])) {
  384.                 // add full channelinfo
  385.                 if ($info['stable'=== $info['unstable']{
  386.                     $state $info['state'];
  387.                 else {
  388.                     $state 'stable';
  389.                 }
  390.                 $latest $info['stable'].' ('.$state.')';
  391.                 $local '';
  392.                 if (isset($installed['version'])) {
  393.                     $inst_state $reg->packageInfo($name'release_state'$channel);
  394.                     $local $installed['version'].' ('.$inst_state.')';
  395.                 }
  396.  
  397.                 $packageinfo = array(
  398.                     $channel,
  399.                     $name,
  400.                     $latest,
  401.                     $local,
  402.                     isset($desc$desc : null,
  403.                     isset($info['deps']$info['deps': null,
  404.                 );
  405.             else {
  406.                 $packageinfo = array(
  407.                     $reg->channelAlias($channel'/' $name,
  408.                     isset($info['stable']$info['stable': null,
  409.                     isset($installed['version']$installed['version': null,
  410.                     isset($desc$desc : null,
  411.                     isset($info['deps']$info['deps': null,
  412.                 );
  413.             }
  414.             $data['data'][$info['category']][$packageinfo;
  415.         }
  416.  
  417.         if (isset($options['mode']&& in_array($options['mode']array('notinstalled''upgrades'))) {
  418.             $this->config->set('default_channel'$savechannel);
  419.             $this->ui->outputData($data$command);
  420.             return true;
  421.         }
  422.  
  423.         foreach ($local_pkgs as $name{
  424.             $info &$reg->getPackage($name$channel);
  425.             $data['data']['Local'][= array(
  426.                 $reg->channelAlias($channel'/' $info->getPackage(),
  427.                 '',
  428.                 $info->getVersion(),
  429.                 $info->getSummary(),
  430.                 $info->getDeps()
  431.                 );
  432.         }
  433.  
  434.         $this->config->set('default_channel'$savechannel);
  435.         $this->ui->outputData($data$command);
  436.         return true;
  437.     }
  438.  
  439.     function doSearch($command$options$params)
  440.     {
  441.         if ((!isset($params[0]|| empty($params[0]))
  442.             && (!isset($params[1]|| empty($params[1])))
  443.         {
  444.             return $this->raiseError('no valid search string supplied');
  445.         }
  446.  
  447.         $channelinfo = isset($options['channelinfo']);
  448.         $reg &$this->config->getRegistry();
  449.         if (isset($options['allchannels'])) {
  450.             // search all channels
  451.             unset($options['allchannels']);
  452.             $channels $reg->getChannels();
  453.             $errors = array();
  454.             foreach ($channels as $channel{
  455.                 if ($channel->getName(!= '__uri'{
  456.                     $options['channel'$channel->getName();
  457.                     $ret $this->doSearch($command$options$params);
  458.                     if (PEAR::isError($ret)) {
  459.                         $errors[$ret;
  460.                     }
  461.                 }
  462.             }
  463.  
  464.             PEAR::staticPopErrorHandling();
  465.             if (count($errors!== 0{
  466.                 // for now, only give first error
  467.                 return PEAR::raiseError($errors[0]);
  468.             }
  469.  
  470.             return true;
  471.         }
  472.  
  473.         $savechannel $channel $this->config->get('default_channel');
  474.         $package strtolower($params[0]);
  475.         $summary = isset($params[1]$params[1: false;
  476.         if (isset($options['channel'])) {
  477.             $reg &$this->config->getRegistry();
  478.             $channel $options['channel'];
  479.             if (!$reg->channelExists($channel)) {
  480.                 return $this->raiseError('Channel "' $channel '" does not exist');
  481.             }
  482.  
  483.             $this->config->set('default_channel'$channel);
  484.         }
  485.  
  486.         $chan $reg->getChannel($channel);
  487.         if (PEAR::isError($e $this->_checkChannelForStatus($channel$chan))) {
  488.             return $e;
  489.         }
  490.  
  491.         if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
  492.               $base $chan->getBaseURL('REST1.0'$this->config->get('preferred_mirror'))) {
  493.             $rest &$this->config->getREST('1.0'array());
  494.             $available $rest->listAll($basefalsefalse$package$summary$chan->getName());
  495.         }
  496.  
  497.         if (PEAR::isError($available)) {
  498.             $this->config->set('default_channel'$savechannel);
  499.             return $this->raiseError($available);
  500.         }
  501.  
  502.         if (!$available && !$channelinfo{
  503.             // clean exit when not found, no error !
  504.             $data 'no packages found that match pattern "' $package '", for channel '.$channel.'.';
  505.             $this->ui->outputData($data);
  506.             $this->config->set('default_channel'$channel);
  507.             return true;
  508.         }
  509.  
  510.         if ($channelinfo{
  511.             $data = array(
  512.                 'caption' => 'Matched packages, channel ' $channel ':',
  513.                 'border' => true,
  514.                 'headline' => array('Channel''Package''Stable/(Latest)''Local'),
  515.                 'channel' => $channel
  516.                 );
  517.         else {
  518.             $data = array(
  519.                 'caption' => 'Matched packages, channel ' $channel ':',
  520.                 'border' => true,
  521.                 'headline' => array('Package''Stable/(Latest)''Local'),
  522.                 'channel' => $channel
  523.                 );
  524.         }
  525.  
  526.         if (!$available && $channelinfo{
  527.             unset($data['headline']);
  528.             $data['data''No packages found that match pattern "' $package '".';
  529.             $available = array();
  530.         }
  531.  
  532.         foreach ($available as $name => $info{
  533.             $installed $reg->packageInfo($namenull$channel);
  534.             $desc $info['summary'];
  535.             if (isset($params[$name]))
  536.                 $desc .= "\n\n".$info['description'];
  537.  
  538.             if (!isset($info['stable']|| !$info['stable']{
  539.                 $version_remote 'none';
  540.             else {
  541.                 if ($info['unstable']{
  542.                     $version_remote $info['unstable'];
  543.                 else {
  544.                     $version_remote $info['stable'];
  545.                 }
  546.                 $version_remote .= ' ('.$info['state'].')';
  547.             }
  548.             $version is_array($installed['version']$installed['version']['release':
  549.                 $installed['version'];
  550.             if ($channelinfo{
  551.                 $packageinfo = array(
  552.                     $channel,
  553.                     $name,
  554.                     $version_remote,
  555.                     $version,
  556.                     $desc,
  557.                 );
  558.             else {
  559.                 $packageinfo = array(
  560.                     $name,
  561.                     $version_remote,
  562.                     $version,
  563.                     $desc,
  564.                 );
  565.             }
  566.             $data['data'][$info['category']][$packageinfo;
  567.         }
  568.  
  569.         $this->ui->outputData($data$command);
  570.         $this->config->set('default_channel'$channel);
  571.         return true;
  572.     }
  573.  
  574.     function &getDownloader($options)
  575.     {
  576.         if (!class_exists('PEAR_Downloader')) {
  577.             require_once 'PEAR/Downloader.php';
  578.         }
  579.         $a &new PEAR_Downloader($this->ui$options$this->config);
  580.         return $a;
  581.     }
  582.  
  583.     function doDownload($command$options$params)
  584.     {
  585.         // make certain that dependencies are ignored
  586.         $options['downloadonly'= 1;
  587.  
  588.         // eliminate error messages for preferred_state-related errors
  589.         /* TODO: Should be an option, but until now download does respect
  590.            prefered state */
  591.         /* $options['ignorepreferred_state'] = 1; */
  592.         // eliminate error messages for preferred_state-related errors
  593.  
  594.         $downloader &$this->getDownloader($options);
  595.         $e $downloader->setDownloadDir(getcwd());
  596.         PEAR::staticPopErrorHandling();
  597.         if (PEAR::isError($e)) {
  598.             return $this->raiseError('Current directory is not writeable, cannot download');
  599.         }
  600.  
  601.         $errors = array();
  602.         $downloaded = array();
  603.         $err $downloader->download($params);
  604.         if (PEAR::isError($err)) {
  605.             return $err;
  606.         }
  607.  
  608.         $errors $downloader->getErrorMsgs();
  609.         if (count($errors)) {
  610.             foreach ($errors as $error{
  611.                 if ($error !== null{
  612.                     $this->ui->outputData($error);
  613.                 }
  614.             }
  615.  
  616.             return $this->raiseError("$command failed");
  617.         }
  618.  
  619.         $downloaded $downloader->getDownloadedPackages();
  620.         foreach ($downloaded as $pkg{
  621.             $this->ui->outputData("File $pkg[file] downloaded"$command);
  622.         }
  623.  
  624.         return true;
  625.     }
  626.  
  627.     function downloadCallback($msg$params = null)
  628.     {
  629.         if ($msg == 'done'{
  630.             $this->bytes_downloaded $params;
  631.         }
  632.     }
  633.  
  634.     function doListUpgrades($command$options$params)
  635.     {
  636.         require_once 'PEAR/Common.php';
  637.         if (isset($params[0]&& !is_array(PEAR_Common::betterStates($params[0]))) {
  638.             return $this->raiseError($params[0' is not a valid state (stable/beta/alpha/devel/etc.) try "pear help list-upgrades"');
  639.         }
  640.  
  641.         $savechannel $channel $this->config->get('default_channel');
  642.         $reg &$this->config->getRegistry();
  643.         foreach ($reg->listChannels(as $channel{
  644.             $inst array_flip($reg->listPackages($channel));
  645.             if (!count($inst)) {
  646.                 continue;
  647.             }
  648.  
  649.             if ($channel == '__uri'{
  650.                 continue;
  651.             }
  652.  
  653.             $this->config->set('default_channel'$channel);
  654.             $state = empty($params[0]$this->config->get('preferred_state'$params[0];
  655.  
  656.             $caption $channel ' Available Upgrades';
  657.             $chan $reg->getChannel($channel);
  658.             if (PEAR::isError($e $this->_checkChannelForStatus($channel$chan))) {
  659.                 return $e;
  660.             }
  661.  
  662.             $latest = array();
  663.             $base2  = false;
  664.             $preferred_mirror $this->config->get('preferred_mirror');
  665.             if ($chan->supportsREST($preferred_mirror&&
  666.                 (
  667.                    //($base2 = $chan->getBaseURL('REST1.4', $preferred_mirror)) ||
  668.                    ($base  $chan->getBaseURL('REST1.0'$preferred_mirror))
  669.                 )
  670.  
  671.             {
  672.                 if ($base2{
  673.                     $rest &$this->config->getREST('1.4'array());
  674.                     $base $base2;
  675.                 else {
  676.                     $rest &$this->config->getREST('1.0'array());
  677.                 }
  678.  
  679.                 if (empty($state|| $state == 'any'{
  680.                     $state = false;
  681.                 else {
  682.                     $caption .= ' (' implode(', 'PEAR_Common::betterStates($statetrue)) ')';
  683.                 }
  684.  
  685.                 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  686.                 $latest $rest->listLatestUpgrades($base$state$inst$channel$reg);
  687.                 PEAR::staticPopErrorHandling();
  688.             }
  689.  
  690.             if (PEAR::isError($latest)) {
  691.                 $this->ui->outputData($latest->getMessage());
  692.                 continue;
  693.             }
  694.  
  695.             $caption .= ':';
  696.             if (PEAR::isError($latest)) {
  697.                 $this->config->set('default_channel'$savechannel);
  698.                 return $latest;
  699.             }
  700.  
  701.             $data = array(
  702.                 'caption' => $caption,
  703.                 'border' => 1,
  704.                 'headline' => array('Channel''Package''Local''Remote''Size'),
  705.                 'channel' => $channel
  706.                 );
  707.  
  708.             foreach ((array)$latest as $pkg => $info{
  709.                 $package strtolower($pkg);
  710.                 if (!isset($inst[$package])) {
  711.                     // skip packages we don't have installed
  712.                     continue;
  713.                 }
  714.  
  715.                 extract($info);
  716.                 $inst_version $reg->packageInfo($package'version'$channel);
  717.                 $inst_state   $reg->packageInfo($package'release_state'$channel);
  718.                 if (version_compare("$version""$inst_version""le")) {
  719.                     // installed version is up-to-date
  720.                     continue;
  721.                 }
  722.  
  723.                 if ($filesize >= 20480{
  724.                     $filesize += 1024 - ($filesize % 1024);
  725.                     $fs sprintf("%dkB"$filesize / 1024);
  726.                 elseif ($filesize > 0{
  727.                     $filesize += 103 - ($filesize % 103);
  728.                     $fs sprintf("%.1fkB"$filesize / 1024.0);
  729.                 else {
  730.                     $fs "  -"// XXX center instead
  731.                 }
  732.  
  733.                 $data['data'][= array($channel$pkg"$inst_version ($inst_state)""$version ($state)"$fs);
  734.             }
  735.  
  736.             if (isset($options['channelinfo'])) {
  737.                 if (empty($data['data'])) {
  738.                     unset($data['headline']);
  739.                     if (count($inst== 0{
  740.                         $data['data''(no packages installed)';
  741.                     else {
  742.                         $data['data''(no upgrades available)';
  743.                     }
  744.                 }
  745.                 $this->ui->outputData($data$command);
  746.             else {
  747.                 if (empty($data['data'])) {
  748.                     $this->ui->outputData('Channel ' $channel ': No upgrades available');
  749.                 else {
  750.                     $this->ui->outputData($data$command);
  751.                 }
  752.             }
  753.         }
  754.  
  755.         $this->config->set('default_channel'$savechannel);
  756.         return true;
  757.     }
  758.  
  759.     function doClearCache($command$options$params)
  760.     {
  761.         $cache_dir $this->config->get('cache_dir');
  762.         $verbose   $this->config->get('verbose');
  763.         $output '';
  764.         if (!file_exists($cache_dir|| !is_dir($cache_dir)) {
  765.             return $this->raiseError("$cache_dir does not exist or is not a directory");
  766.         }
  767.  
  768.         if (!($dp @opendir($cache_dir))) {
  769.             return $this->raiseError("opendir($cache_dir) failed: $php_errormsg");
  770.         }
  771.  
  772.         if ($verbose >= 1{
  773.             $output .= "reading directory $cache_dir\n";
  774.         }
  775.  
  776.         $num = 0;
  777.         while ($ent readdir($dp)) {
  778.             if (preg_match('/rest.cache(file|id)\\z/'$ent)) {
  779.                 $path $cache_dir . DIRECTORY_SEPARATOR . $ent;
  780.                 if (file_exists($path)) {
  781.                     $ok @unlink($path);
  782.                 else {
  783.                     $ok = false;
  784.                     $php_errormsg '';
  785.                 }
  786.  
  787.                 if ($ok{
  788.                     if ($verbose >= 2{
  789.                         $output .= "deleted $path\n";
  790.                     }
  791.                     $num++;
  792.                 elseif ($verbose >= 1{
  793.                     $output .= "failed to delete $path $php_errormsg\n";
  794.                 }
  795.             }
  796.         }
  797.  
  798.         closedir($dp);
  799.         if ($verbose >= 1{
  800.             $output .= "$num cache entries cleared\n";
  801.         }
  802.  
  803.         $this->ui->outputData(rtrim($output)$command);
  804.         return $num;
  805.     }
  806. }

Documentation generated on Wed, 06 Jul 2011 23:31:16 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.