3 * PEAR_Command_Mirror (download-all command)
7 * LICENSE: This source file is subject to version 3.0 of the PHP license
8 * that is available through the world-wide-web at the following URI:
9 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
10 * the PHP License and are unable to obtain it through the web, please
11 * send a note to license@php.net so we can mail you a copy immediately.
15 * @author Alexander Merz <alexmerz@php.net>
16 * @copyright 1997-2006 The PHP Group
17 * @license http://www.php.net/license/3_0.txt PHP License 3.0
18 * @version CVS: $Id: Mirror.php,v 1.18 2006/03/02 18:14:13 cellog Exp $
19 * @link http://pear.php.net/package/PEAR
20 * @since File available since Release 1.2.0
26 require_once 'PEAR/Command/Common.php';
29 * PEAR commands for providing file mirrors
33 * @author Alexander Merz <alexmerz@php.net>
34 * @copyright 1997-2006 The PHP Group
35 * @license http://www.php.net/license/3_0.txt PHP License 3.0
36 * @version Release: 1.4.11
37 * @link http://pear.php.net/package/PEAR
38 * @since Class available since Release 1.2.0
40 class PEAR_Command_Mirror
extends PEAR_Command_Common
44 var $commands = array(
45 'download-all' => array(
46 'summary' => 'Downloads each available package from the default channel',
47 'function' => 'doDownloadAll',
53 'doc' => 'specify a channel other than the default channel',
58 Requests a list of available packages from the default channel ({config default_channel})
59 and downloads them to current working directory. Note: only
60 packages within preferred_state ({config preferred_state}) will be downloaded'
69 * PEAR_Command_Mirror constructor.
72 * @param object PEAR_Frontend a reference to an frontend
73 * @param object PEAR_Config a reference to the configuration data
75 function PEAR_Command_Mirror(&$ui, &$config)
77 parent
::PEAR_Command_Common($ui, $config);
87 $a = &PEAR_Command
::factory($a, $this->config
);
91 // {{{ doDownloadAll()
93 * retrieves a list of avaible Packages from master server
97 * @param string $command the command
98 * @param array $options the command options before the command
99 * @param array $params the stuff after the command name
100 * @return bool true if succesful
103 function doDownloadAll($command, $options, $params)
105 $savechannel = $this->config
->get('default_channel');
106 $reg = &$this->config
->getRegistry();
107 $channel = isset($options['channel']) ?
$options['channel'] :
108 $this->config
->get('default_channel');
109 if (!$reg->channelExists($channel)) {
110 $this->config
->set('default_channel', $savechannel);
111 return $this->raiseError('Channel "' . $channel . '" does not exist');
113 $this->config
->set('default_channel', $channel);
114 $this->ui
->outputData('Using Channel ' . $this->config
->get('default_channel'));
115 $chan = $reg->getChannel($channel);
116 if (PEAR
::isError($chan)) {
117 return $this->raiseError($chan);
119 if ($chan->supportsREST($this->config
->get('preferred_mirror')) &&
120 $base = $chan->getBaseURL('REST1.0', $this->config
->get('preferred_mirror'))) {
121 $rest = &$this->config
->getREST('1.0', array());
122 $remoteInfo = array_flip($rest->listPackages($base));
124 $remote = &$this->config
->getRemote();
125 $stable = ($this->config
->get('preferred_state') == 'stable');
126 $remoteInfo = $remote->call("package.listAll", true, $stable, false);
128 if (PEAR
::isError($remoteInfo)) {
131 $cmd = &$this->factory("download");
132 if (PEAR
::isError($cmd)) {
135 $this->ui
->outputData('Using Preferred State of ' .
136 $this->config
->get('preferred_state'));
137 $this->ui
->outputData('Gathering release information, please wait...');
139 * Error handling not necessary, because already done by
140 * the download command
142 PEAR
::staticPushErrorHandling(PEAR_ERROR_RETURN
);
143 $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo));
144 PEAR
::staticPopErrorHandling();
145 $this->config
->set('default_channel', $savechannel);
146 if (PEAR
::isError($err)) {
147 $this->ui
->outputData($err->getMessage());