Updated PEAR and PEAR packages.
[timetracker.git] / WEB-INF / lib / pear / PEAR / Command / Mirror.php
1 <?php
2 /**
3  * PEAR_Command_Mirror (download-all command)
4  *
5  * PHP versions 4 and 5
6  *
7  * @category   pear
8  * @package    PEAR
9  * @author     Alexander Merz <alexmerz@php.net>
10  * @copyright  1997-2009 The Authors
11  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
12  * @link       http://pear.php.net/package/PEAR
13  * @since      File available since Release 1.2.0
14  */
15
16 /**
17  * base class
18  */
19 require_once 'PEAR/Command/Common.php';
20
21 /**
22  * PEAR commands for providing file mirrors
23  *
24  * @category   pear
25  * @package    PEAR
26  * @author     Alexander Merz <alexmerz@php.net>
27  * @copyright  1997-2009 The Authors
28  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
29  * @version    Release: 1.10.1
30  * @link       http://pear.php.net/package/PEAR
31  * @since      Class available since Release 1.2.0
32  */
33 class PEAR_Command_Mirror extends PEAR_Command_Common
34 {
35     var $commands = array(
36         'download-all' => array(
37             'summary' => 'Downloads each available package from the default channel',
38             'function' => 'doDownloadAll',
39             'shortcut' => 'da',
40             'options' => array(
41                 'channel' =>
42                     array(
43                     'shortopt' => 'c',
44                     'doc' => 'specify a channel other than the default channel',
45                     'arg' => 'CHAN',
46                     ),
47                 ),
48             'doc' => '
49 Requests a list of available packages from the default channel ({config default_channel})
50 and downloads them to current working directory.  Note: only
51 packages within preferred_state ({config preferred_state}) will be downloaded'
52             ),
53         );
54
55     /**
56      * PEAR_Command_Mirror constructor.
57      *
58      * @access public
59      * @param object PEAR_Frontend a reference to an frontend
60      * @param object PEAR_Config a reference to the configuration data
61      */
62     function __construct(&$ui, &$config)
63     {
64         parent::__construct($ui, $config);
65     }
66
67     /**
68      * For unit-testing
69      */
70     function &factory($a)
71     {
72         $a = &PEAR_Command::factory($a, $this->config);
73         return $a;
74     }
75
76     /**
77     * retrieves a list of avaible Packages from master server
78     * and downloads them
79     *
80     * @access public
81     * @param string $command the command
82     * @param array $options the command options before the command
83     * @param array $params the stuff after the command name
84     * @return bool true if successful
85     * @throw PEAR_Error
86     */
87     function doDownloadAll($command, $options, $params)
88     {
89         $savechannel = $this->config->get('default_channel');
90         $reg = &$this->config->getRegistry();
91         $channel = isset($options['channel']) ? $options['channel'] :
92             $this->config->get('default_channel');
93         if (!$reg->channelExists($channel)) {
94             $this->config->set('default_channel', $savechannel);
95             return $this->raiseError('Channel "' . $channel . '" does not exist');
96         }
97         $this->config->set('default_channel', $channel);
98
99         $this->ui->outputData('Using Channel ' . $this->config->get('default_channel'));
100         $chan = $reg->getChannel($channel);
101         if (PEAR::isError($chan)) {
102             return $this->raiseError($chan);
103         }
104
105         if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
106               $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
107             $rest = &$this->config->getREST('1.0', array());
108             $remoteInfo = array_flip($rest->listPackages($base, $channel));
109         }
110
111         if (PEAR::isError($remoteInfo)) {
112             return $remoteInfo;
113         }
114
115         $cmd = &$this->factory("download");
116         if (PEAR::isError($cmd)) {
117             return $cmd;
118         }
119
120         $this->ui->outputData('Using Preferred State of ' .
121             $this->config->get('preferred_state'));
122         $this->ui->outputData('Gathering release information, please wait...');
123
124         /**
125          * Error handling not necessary, because already done by
126          * the download command
127          */
128         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
129         $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo));
130         PEAR::staticPopErrorHandling();
131         $this->config->set('default_channel', $savechannel);
132         if (PEAR::isError($err)) {
133             $this->ui->outputData($err->getMessage());
134         }
135
136         return true;
137     }
138 }