Редакция 69 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
69 | alex-w | 1 | <?php |
2 | /** |
||
3 | * PEAR_Command_Mirror (download-all command) |
||
4 | * |
||
5 | * PHP versions 4 and 5 |
||
6 | * |
||
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. |
||
12 | * |
||
13 | * @category pear |
||
14 | * @package PEAR |
||
15 | * @author Alexander Merz <alexmerz@php.net> |
||
16 | * @copyright 1997-2008 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.20 2008/04/11 01:16:40 dufuz Exp $ |
||
19 | * @link http://pear.php.net/package/PEAR |
||
20 | * @since File available since Release 1.2.0 |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * base class |
||
25 | */ |
||
26 | require_once 'PEAR/Command/Common.php'; |
||
27 | |||
28 | /** |
||
29 | * PEAR commands for providing file mirrors |
||
30 | * |
||
31 | * @category pear |
||
32 | * @package PEAR |
||
33 | * @author Alexander Merz <alexmerz@php.net> |
||
34 | * @copyright 1997-2008 The PHP Group |
||
35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
||
36 | * @version Release: 1.7.2 |
||
37 | * @link http://pear.php.net/package/PEAR |
||
38 | * @since Class available since Release 1.2.0 |
||
39 | */ |
||
40 | class PEAR_Command_Mirror extends PEAR_Command_Common |
||
41 | { |
||
42 | // {{{ properties |
||
43 | |||
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', |
||
55 | ), |
||
56 | ), |
||
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' |
||
61 | ), |
||
62 | ); |
||
63 | |||
64 | // }}} |
||
65 | |||
66 | // {{{ constructor |
||
67 | |||
68 | /** |
||
69 | * PEAR_Command_Mirror constructor. |
||
70 | * |
||
71 | * @access public |
||
72 | * @param object PEAR_Frontend a reference to an frontend |
||
73 | * @param object PEAR_Config a reference to the configuration data |
||
74 | */ |
||
75 | function PEAR_Command_Mirror(&$ui, &$config) |
||
76 | { |
||
77 | parent::PEAR_Command_Common($ui, $config); |
||
78 | } |
||
79 | |||
80 | // }}} |
||
81 | |||
82 | /** |
||
83 | * For unit-testing |
||
84 | */ |
||
85 | function &factory($a) |
||
86 | { |
||
87 | $a = &PEAR_Command::factory($a, $this->config); |
||
88 | return $a; |
||
89 | } |
||
90 | |||
91 | // {{{ doDownloadAll() |
||
92 | /** |
||
93 | * retrieves a list of avaible Packages from master server |
||
94 | * and downloads them |
||
95 | * |
||
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 |
||
102 | */ |
||
103 | function doDownloadAll($command, $options, $params) |
||
104 | { |
||
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'); |
||
112 | } |
||
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); |
||
118 | } |
||
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, $channel)); |
||
123 | } else { |
||
124 | $remote = &$this->config->getRemote(); |
||
125 | $stable = ($this->config->get('preferred_state') == 'stable'); |
||
126 | $remoteInfo = $remote->call("package.listAll", true, $stable, false); |
||
127 | } |
||
128 | if (PEAR::isError($remoteInfo)) { |
||
129 | return $remoteInfo; |
||
130 | } |
||
131 | $cmd = &$this->factory("download"); |
||
132 | if (PEAR::isError($cmd)) { |
||
133 | return $cmd; |
||
134 | } |
||
135 | $this->ui->outputData('Using Preferred State of ' . |
||
136 | $this->config->get('preferred_state')); |
||
137 | $this->ui->outputData('Gathering release information, please wait...'); |
||
138 | /** |
||
139 | * Error handling not necessary, because already done by |
||
140 | * the download command |
||
141 | */ |
||
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()); |
||
148 | } |
||
149 | return true; |
||
150 | } |
||
151 | |||
152 | // }}} |
||
153 | } |