MailZu 0.8RC3
[bMailZu.git] / lib / pear / PEAR / Command / Mirror.php
blob9c4b2afdf390b39c7b316278f6982b72bf09f9b8
1 <?php
2 /**
3 * PEAR_Command_Mirror (download-all command)
5 * PHP versions 4 and 5
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.
13 * @category pear
14 * @package PEAR
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
23 /**
24 * base class
26 require_once 'PEAR/Command/Common.php';
28 /**
29 * PEAR commands for providing file mirrors
31 * @category pear
32 * @package PEAR
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
42 // {{{ properties
44 var $commands = array(
45 'download-all' => array(
46 'summary' => 'Downloads each available package from the default channel',
47 'function' => 'doDownloadAll',
48 'shortcut' => 'da',
49 'options' => array(
50 'channel' =>
51 array(
52 'shortopt' => 'c',
53 'doc' => 'specify a channel other than the default channel',
54 'arg' => 'CHAN',
57 'doc' => '
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'
64 // }}}
66 // {{{ constructor
68 /**
69 * PEAR_Command_Mirror constructor.
71 * @access public
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);
80 // }}}
82 /**
83 * For unit-testing
85 function &factory($a)
87 $a = &PEAR_Command::factory($a, $this->config);
88 return $a;
91 // {{{ doDownloadAll()
92 /**
93 * retrieves a list of avaible Packages from master server
94 * and downloads them
96 * @access public
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
101 * @throw PEAR_Error
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));
123 } else {
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)) {
129 return $remoteInfo;
131 $cmd = &$this->factory("download");
132 if (PEAR::isError($cmd)) {
133 return $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());
149 return true;
152 // }}}