3 * PEAR_Command_Mirror (download-all command)
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 * @version CVS: $Id: Mirror.php 313023 2011-07-06 19:17:11Z dufuz $
13 * @link http://pear.php.net/package/PEAR
14 * @since File available since Release 1.2.0
20 require_once 'PEAR/Command/Common.php';
23 * PEAR commands for providing file mirrors
27 * @author Alexander Merz <alexmerz@php.net>
28 * @copyright 1997-2009 The Authors
29 * @license http://opensource.org/licenses/bsd-license.php New BSD License
30 * @version Release: 1.9.4
31 * @link http://pear.php.net/package/PEAR
32 * @since Class available since Release 1.2.0
34 class PEAR_Command_Mirror extends PEAR_Command_Common
36 var $commands = array(
37 'download-all' => array(
38 'summary' => 'Downloads each available package from the default channel',
39 'function' => 'doDownloadAll',
45 'doc' => 'specify a channel other than the default channel',
50 Requests a list of available packages from the default channel ({config default_channel})
51 and downloads them to current working directory. Note: only
52 packages within preferred_state ({config preferred_state}) will be downloaded'
57 * PEAR_Command_Mirror constructor.
60 * @param object PEAR_Frontend a reference to an frontend
61 * @param object PEAR_Config a reference to the configuration data
63 function PEAR_Command_Mirror(&$ui, &$config)
65 parent::PEAR_Command_Common($ui, $config);
73 $a = &PEAR_Command::factory($a, $this->config);
78 * retrieves a list of avaible Packages from master server
82 * @param string $command the command
83 * @param array $options the command options before the command
84 * @param array $params the stuff after the command name
85 * @return bool true if succesful
88 function doDownloadAll($command, $options, $params)
90 $savechannel = $this->config->get('default_channel');
91 $reg = &$this->config->getRegistry();
92 $channel = isset($options['channel']) ? $options['channel'] :
93 $this->config->get('default_channel');
94 if (!$reg->channelExists($channel)) {
95 $this->config->set('default_channel', $savechannel);
96 return $this->raiseError('Channel "' . $channel . '" does not exist');
98 $this->config->set('default_channel', $channel);
100 $this->ui->outputData('Using Channel ' . $this->config->get('default_channel'));
101 $chan = $reg->getChannel($channel);
102 if (PEAR::isError($chan)) {
103 return $this->raiseError($chan);
106 if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
107 $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
108 $rest = &$this->config->getREST('1.0', array());
109 $remoteInfo = array_flip($rest->listPackages($base, $channel));
112 if (PEAR::isError($remoteInfo)) {
116 $cmd = &$this->factory("download");
117 if (PEAR::isError($cmd)) {
121 $this->ui->outputData('Using Preferred State of ' .
122 $this->config->get('preferred_state'));
123 $this->ui->outputData('Gathering release information, please wait...');
126 * Error handling not necessary, because already done by
127 * the download command
129 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
130 $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo));
131 PEAR::staticPopErrorHandling();
132 $this->config->set('default_channel', $savechannel);
133 if (PEAR::isError($err)) {
134 $this->ui->outputData($err->getMessage());