Редакция 69 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 87 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * PEAR_Command_Mirror (download-all command)
|
3 | * PEAR_Command_Mirror (download-all command)
|
4 | *
|
4 | *
|
5 | * PHP versions 4 and 5
|
5 | * PHP versions 4 and 5
|
6 | *
|
6 | *
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
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:
|
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
|
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
|
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.
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
12 | *
|
12 | *
|
13 | * @category pear
|
13 | * @category pear
|
14 | * @package PEAR
|
14 | * @package PEAR
|
15 | * @author Alexander Merz <alexmerz@php.net>
|
15 | * @author Alexander Merz <alexmerz@php.net>
|
16 | * @copyright 1997-2008 The PHP Group
|
16 | * @copyright 1997-2008 The PHP Group
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
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 $
|
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
|
19 | * @link http://pear.php.net/package/PEAR
|
20 | * @since File available since Release 1.2.0
|
20 | * @since File available since Release 1.2.0
|
21 | */
|
21 | */
|
22 | 22 | ||
23 | /**
|
23 | /**
|
24 | * base class
|
24 | * base class
|
25 | */
|
25 | */
|
26 | require_once 'PEAR/Command/Common.php'; |
26 | require_once 'PEAR/Command/Common.php'; |
27 | 27 | ||
28 | /**
|
28 | /**
|
29 | * PEAR commands for providing file mirrors
|
29 | * PEAR commands for providing file mirrors
|
30 | *
|
30 | *
|
31 | * @category pear
|
31 | * @category pear
|
32 | * @package PEAR
|
32 | * @package PEAR
|
33 | * @author Alexander Merz <alexmerz@php.net>
|
33 | * @author Alexander Merz <alexmerz@php.net>
|
34 | * @copyright 1997-2008 The PHP Group
|
34 | * @copyright 1997-2008 The PHP Group
|
35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
35 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
36 | * @version Release: 1.7.2
|
36 | * @version Release: 1.7.2
|
37 | * @link http://pear.php.net/package/PEAR
|
37 | * @link http://pear.php.net/package/PEAR
|
38 | * @since Class available since Release 1.2.0
|
38 | * @since Class available since Release 1.2.0
|
39 | */
|
39 | */
|
40 | class PEAR_Command_Mirror extends PEAR_Command_Common |
40 | class PEAR_Command_Mirror extends PEAR_Command_Common |
41 | {
|
41 | {
|
42 | // {{{ properties
|
42 | // {{{ properties
|
43 | 43 | ||
44 | var $commands = array( |
44 | var $commands = array( |
45 | 'download-all' => array( |
45 | 'download-all' => array( |
46 | 'summary' => 'Downloads each available package from the default channel', |
46 | 'summary' => 'Downloads each available package from the default channel', |
47 | 'function' => 'doDownloadAll', |
47 | 'function' => 'doDownloadAll', |
48 | 'shortcut' => 'da', |
48 | 'shortcut' => 'da', |
49 | 'options' => array( |
49 | 'options' => array( |
50 | 'channel' => |
50 | 'channel' => |
51 | array( |
51 | array( |
52 | 'shortopt' => 'c', |
52 | 'shortopt' => 'c', |
53 | 'doc' => 'specify a channel other than the default channel', |
53 | 'doc' => 'specify a channel other than the default channel', |
54 | 'arg' => 'CHAN', |
54 | 'arg' => 'CHAN', |
55 | ), |
55 | ), |
56 | ), |
56 | ), |
57 | 'doc' => ' |
57 | 'doc' => ' |
58 | Requests a list of available packages from the default channel ({config 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
|
59 | and downloads them to current working directory. Note: only
|
60 | packages within preferred_state ({config preferred_state}) will be downloaded'
|
60 | packages within preferred_state ({config preferred_state}) will be downloaded'
|
61 | ), |
61 | ), |
62 | ); |
62 | ); |
63 | 63 | ||
64 | // }}}
|
64 | // }}}
|
65 | 65 | ||
66 | // {{{ constructor
|
66 | // {{{ constructor
|
67 | 67 | ||
68 | /**
|
68 | /**
|
69 | * PEAR_Command_Mirror constructor.
|
69 | * PEAR_Command_Mirror constructor.
|
70 | *
|
70 | *
|
71 | * @access public
|
71 | * @access public
|
72 | * @param object PEAR_Frontend a reference to an frontend
|
72 | * @param object PEAR_Frontend a reference to an frontend
|
73 | * @param object PEAR_Config a reference to the configuration data
|
73 | * @param object PEAR_Config a reference to the configuration data
|
74 | */
|
74 | */
|
75 | function PEAR_Command_Mirror(&$ui, &$config) |
75 | function PEAR_Command_Mirror(&$ui, &$config) |
76 | {
|
76 | {
|
77 | parent::PEAR_Command_Common($ui, $config); |
77 | parent::PEAR_Command_Common($ui, $config); |
78 | }
|
78 | }
|
79 | 79 | ||
80 | // }}}
|
80 | // }}}
|
81 | 81 | ||
82 | /**
|
82 | /**
|
83 | * For unit-testing
|
83 | * For unit-testing
|
84 | */
|
84 | */
|
85 | function &factory($a) |
85 | function &factory($a) |
86 | {
|
86 | {
|
87 | $a = &PEAR_Command::factory($a, $this->config); |
87 | $a = &PEAR_Command::factory($a, $this->config); |
88 | return $a; |
88 | return $a; |
89 | }
|
89 | }
|
90 | 90 | ||
91 | // {{{ doDownloadAll()
|
91 | // {{{ doDownloadAll()
|
92 | /**
|
92 | /**
|
93 | * retrieves a list of avaible Packages from master server
|
93 | * retrieves a list of avaible Packages from master server
|
94 | * and downloads them
|
94 | * and downloads them
|
95 | *
|
95 | *
|
96 | * @access public
|
96 | * @access public
|
97 | * @param string $command the command
|
97 | * @param string $command the command
|
98 | * @param array $options the command options before the command
|
98 | * @param array $options the command options before the command
|
99 | * @param array $params the stuff after the command name
|
99 | * @param array $params the stuff after the command name
|
100 | * @return bool true if succesful
|
100 | * @return bool true if succesful
|
101 | * @throw PEAR_Error
|
101 | * @throw PEAR_Error
|
102 | */
|
102 | */
|
103 | function doDownloadAll($command, $options, $params) |
103 | function doDownloadAll($command, $options, $params) |
104 | {
|
104 | {
|
105 | $savechannel = $this->config->get('default_channel'); |
105 | $savechannel = $this->config->get('default_channel'); |
106 | $reg = &$this->config->getRegistry(); |
106 | $reg = &$this->config->getRegistry(); |
107 | $channel = isset($options['channel']) ? $options['channel'] : |
107 | $channel = isset($options['channel']) ? $options['channel'] : |
108 | $this->config->get('default_channel'); |
108 | $this->config->get('default_channel'); |
109 | if (!$reg->channelExists($channel)) { |
109 | if (!$reg->channelExists($channel)) { |
110 | $this->config->set('default_channel', $savechannel); |
110 | $this->config->set('default_channel', $savechannel); |
111 | return $this->raiseError('Channel "' . $channel . '" does not exist'); |
111 | return $this->raiseError('Channel "' . $channel . '" does not exist'); |
112 | }
|
112 | }
|
113 | $this->config->set('default_channel', $channel); |
113 | $this->config->set('default_channel', $channel); |
114 | $this->ui->outputData('Using Channel ' . $this->config->get('default_channel')); |
114 | $this->ui->outputData('Using Channel ' . $this->config->get('default_channel')); |
115 | $chan = $reg->getChannel($channel); |
115 | $chan = $reg->getChannel($channel); |
116 | if (PEAR::isError($chan)) { |
116 | if (PEAR::isError($chan)) { |
117 | return $this->raiseError($chan); |
117 | return $this->raiseError($chan); |
118 | }
|
118 | }
|
119 | if ($chan->supportsREST($this->config->get('preferred_mirror')) && |
119 | if ($chan->supportsREST($this->config->get('preferred_mirror')) && |
120 | $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) { |
120 | $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) { |
121 | $rest = &$this->config->getREST('1.0', array()); |
121 | $rest = &$this->config->getREST('1.0', array()); |
122 | $remoteInfo = array_flip($rest->listPackages($base, $channel)); |
122 | $remoteInfo = array_flip($rest->listPackages($base, $channel)); |
123 | } else { |
123 | } else { |
124 | $remote = &$this->config->getRemote(); |
124 | $remote = &$this->config->getRemote(); |
125 | $stable = ($this->config->get('preferred_state') == 'stable'); |
125 | $stable = ($this->config->get('preferred_state') == 'stable'); |
126 | $remoteInfo = $remote->call("package.listAll", true, $stable, false); |
126 | $remoteInfo = $remote->call("package.listAll", true, $stable, false); |
127 | }
|
127 | }
|
128 | if (PEAR::isError($remoteInfo)) { |
128 | if (PEAR::isError($remoteInfo)) { |
129 | return $remoteInfo; |
129 | return $remoteInfo; |
130 | }
|
130 | }
|
131 | $cmd = &$this->factory("download"); |
131 | $cmd = &$this->factory("download"); |
132 | if (PEAR::isError($cmd)) { |
132 | if (PEAR::isError($cmd)) { |
133 | return $cmd; |
133 | return $cmd; |
134 | }
|
134 | }
|
135 | $this->ui->outputData('Using Preferred State of ' . |
135 | $this->ui->outputData('Using Preferred State of ' . |
136 | $this->config->get('preferred_state')); |
136 | $this->config->get('preferred_state')); |
137 | $this->ui->outputData('Gathering release information, please wait...'); |
137 | $this->ui->outputData('Gathering release information, please wait...'); |
138 | /**
|
138 | /**
|
139 | * Error handling not necessary, because already done by
|
139 | * Error handling not necessary, because already done by
|
140 | * the download command
|
140 | * the download command
|
141 | */
|
141 | */
|
142 | PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); |
142 | PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); |
143 | $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo)); |
143 | $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo)); |
144 | PEAR::staticPopErrorHandling(); |
144 | PEAR::staticPopErrorHandling(); |
145 | $this->config->set('default_channel', $savechannel); |
145 | $this->config->set('default_channel', $savechannel); |
146 | if (PEAR::isError($err)) { |
146 | if (PEAR::isError($err)) { |
147 | $this->ui->outputData($err->getMessage()); |
147 | $this->ui->outputData($err->getMessage()); |
148 | }
|
148 | }
|
149 | return true; |
149 | return true; |
150 | }
|
150 | }
|
151 | 151 | ||
152 | // }}}
|
152 | // }}}
|
153 | }
|
153 | }
|
154 | 154 |