| 94 |
jpm |
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>
|
| 187 |
mathias |
10 |
* @copyright 1997-2009 The Authors
|
|
|
11 |
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
| 94 |
jpm |
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>
|
| 187 |
mathias |
27 |
* @copyright 1997-2009 The Authors
|
|
|
28 |
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
|
|
29 |
* @version Release: 1.10.1
|
| 94 |
jpm |
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 |
*/
|
| 187 |
mathias |
62 |
function __construct(&$ui, &$config)
|
| 94 |
jpm |
63 |
{
|
| 187 |
mathias |
64 |
parent::__construct($ui, $config);
|
| 94 |
jpm |
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
|
| 187 |
mathias |
84 |
* @return bool true if successful
|
|
|
85 |
* @throw PEAR_Error
|
| 94 |
jpm |
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);
|
| 187 |
mathias |
98 |
|
| 94 |
jpm |
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 |
}
|
| 187 |
mathias |
104 |
|
| 94 |
jpm |
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());
|
| 187 |
mathias |
108 |
$remoteInfo = array_flip($rest->listPackages($base, $channel));
|
| 94 |
jpm |
109 |
}
|
| 187 |
mathias |
110 |
|
| 94 |
jpm |
111 |
if (PEAR::isError($remoteInfo)) {
|
|
|
112 |
return $remoteInfo;
|
|
|
113 |
}
|
| 187 |
mathias |
114 |
|
| 94 |
jpm |
115 |
$cmd = &$this->factory("download");
|
|
|
116 |
if (PEAR::isError($cmd)) {
|
|
|
117 |
return $cmd;
|
|
|
118 |
}
|
| 187 |
mathias |
119 |
|
| 94 |
jpm |
120 |
$this->ui->outputData('Using Preferred State of ' .
|
|
|
121 |
$this->config->get('preferred_state'));
|
|
|
122 |
$this->ui->outputData('Gathering release information, please wait...');
|
| 187 |
mathias |
123 |
|
| 94 |
jpm |
124 |
/**
|
| 187 |
mathias |
125 |
* Error handling not necessary, because already done by
|
| 94 |
jpm |
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 |
}
|
| 187 |
mathias |
135 |
|
| 94 |
jpm |
136 |
return true;
|
|
|
137 |
}
|
|
|
138 |
}
|