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 * @link http://pear.php.net/package/PEAR
13 * @since File available since Release 1.2.0
19 require_once 'PEAR/Command/Common.php';
22 * PEAR commands for providing file mirrors
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.3
30 * @link http://pear.php.net/package/PEAR
31 * @since Class available since Release 1.2.0
33 class PEAR_Command_Mirror extends PEAR_Command_Common
35 var $commands = array(
36 'download-all' => array(
37 'summary' => 'Downloads each available package from the default channel',
38 'function' => 'doDownloadAll',
44 'doc' => 'specify a channel other than the default channel',
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'
56 * PEAR_Command_Mirror constructor.
59 * @param object PEAR_Frontend a reference to an frontend
60 * @param object PEAR_Config a reference to the configuration data
62 function __construct(&$ui, &$config)
64 parent::__construct($ui, $config);
72 $a = &PEAR_Command::factory($a, $this->config);
77 * retrieves a list of avaible Packages from master server
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
87 function doDownloadAll($command, $options, $params)
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');
97 $this->config->set('default_channel', $channel);
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);
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));
111 if (PEAR::isError($remoteInfo)) {
115 $cmd = &$this->factory("download");
116 if (PEAR::isError($cmd)) {
120 $this->ui->outputData('Using Preferred State of ' .
121 $this->config->get('preferred_state'));
122 $this->ui->outputData('Gathering release information, please wait...');
125 * Error handling not necessary, because already done by
126 * the download command
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());