Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
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
-
 
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
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Alexander Merz <alexmerz@php.net>
9
 * @author     Alexander Merz <alexmerz@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright  1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
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
12
 * @link       http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.2.0
13
 * @since      File available since Release 1.2.0
21
 */
14
 */
Line 22... Line 15...
22
 
15
 
Line 29... Line 22...
29
 * PEAR commands for providing file mirrors
22
 * PEAR commands for providing file mirrors
30
 *
23
 *
31
 * @category   pear
24
 * @category   pear
32
 * @package    PEAR
25
 * @package    PEAR
33
 * @author     Alexander Merz <alexmerz@php.net>
26
 * @author     Alexander Merz <alexmerz@php.net>
34
 * @copyright  1997-2006 The PHP Group
27
 * @copyright  1997-2009 The Authors
35
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
28
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
36
 * @version    Release: 1.5.1
29
 * @version    Release: 1.10.1
37
 * @link       http://pear.php.net/package/PEAR
30
 * @link       http://pear.php.net/package/PEAR
38
 * @since      Class available since Release 1.2.0
31
 * @since      Class available since Release 1.2.0
39
 */
32
 */
40
class PEAR_Command_Mirror extends PEAR_Command_Common
33
class PEAR_Command_Mirror extends PEAR_Command_Common
41
{
34
{
42
    // {{{ properties
-
 
43
 
-
 
44
    var $commands = array(
35
    var $commands = array(
45
        'download-all' => array(
36
        'download-all' => array(
46
            'summary' => 'Downloads each available package from the default channel',
37
            'summary' => 'Downloads each available package from the default channel',
47
            'function' => 'doDownloadAll',
38
            'function' => 'doDownloadAll',
48
            'shortcut' => 'da',
39
            'shortcut' => 'da',
Line 59... Line 50...
59
and downloads them to current working directory.  Note: only
50
and downloads them to current working directory.  Note: only
60
packages within preferred_state ({config preferred_state}) will be downloaded'
51
packages within preferred_state ({config preferred_state}) will be downloaded'
61
            ),
52
            ),
62
        );
53
        );
Line 63... Line -...
63
 
-
 
64
    // }}}
-
 
65
 
-
 
66
    // {{{ constructor
-
 
67
 
54
 
68
    /**
55
    /**
69
     * PEAR_Command_Mirror constructor.
56
     * PEAR_Command_Mirror constructor.
70
     *
57
     *
71
     * @access public
58
     * @access public
72
     * @param object PEAR_Frontend a reference to an frontend
59
     * @param object PEAR_Frontend a reference to an frontend
73
     * @param object PEAR_Config a reference to the configuration data
60
     * @param object PEAR_Config a reference to the configuration data
74
     */
61
     */
75
    function PEAR_Command_Mirror(&$ui, &$config)
62
    function __construct(&$ui, &$config)
76
    {
63
    {
77
        parent::PEAR_Command_Common($ui, $config);
64
        parent::__construct($ui, $config);
Line 78... Line -...
78
    }
-
 
79
 
-
 
80
    // }}}
65
    }
81
 
66
 
82
    /**
67
    /**
83
     * For unit-testing
68
     * For unit-testing
84
     */
69
     */
85
    function &factory($a)
70
    function &factory($a)
86
    {
71
    {
87
        $a = &PEAR_Command::factory($a, $this->config);
72
        $a = &PEAR_Command::factory($a, $this->config);
Line 88... Line -...
88
        return $a;
-
 
89
    }
73
        return $a;
90
 
74
    }
91
    // {{{ doDownloadAll()
75
 
92
    /**
76
    /**
93
    * retrieves a list of avaible Packages from master server
77
    * retrieves a list of avaible Packages from master server
94
    * and downloads them
78
    * and downloads them
95
    *
79
    *
96
    * @access public
80
    * @access public
97
    * @param string $command the command
81
    * @param string $command the command
98
    * @param array $options the command options before the command
82
    * @param array $options the command options before the command
99
    * @param array $params the stuff after the command name
83
    * @param array $params the stuff after the command name
100
    * @return bool true if succesful
84
    * @return bool true if successful
101
    * @throw PEAR_Error 
85
    * @throw PEAR_Error
102
    */
86
    */
103
    function doDownloadAll($command, $options, $params)
87
    function doDownloadAll($command, $options, $params)
Line 109... Line 93...
109
        if (!$reg->channelExists($channel)) {
93
        if (!$reg->channelExists($channel)) {
110
            $this->config->set('default_channel', $savechannel);
94
            $this->config->set('default_channel', $savechannel);
111
            return $this->raiseError('Channel "' . $channel . '" does not exist');
95
            return $this->raiseError('Channel "' . $channel . '" does not exist');
112
        }
96
        }
113
        $this->config->set('default_channel', $channel);
97
        $this->config->set('default_channel', $channel);
-
 
98
 
114
        $this->ui->outputData('Using Channel ' . $this->config->get('default_channel'));
99
        $this->ui->outputData('Using Channel ' . $this->config->get('default_channel'));
115
        $chan = $reg->getChannel($channel);
100
        $chan = $reg->getChannel($channel);
116
        if (PEAR::isError($chan)) {
101
        if (PEAR::isError($chan)) {
117
            return $this->raiseError($chan);
102
            return $this->raiseError($chan);
118
        }
103
        }
-
 
104
 
119
        if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
105
        if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
120
              $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
106
              $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
121
            $rest = &$this->config->getREST('1.0', array());
107
            $rest = &$this->config->getREST('1.0', array());
122
            $remoteInfo = array_flip($rest->listPackages($base));
108
            $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
        }
109
        }
-
 
110
 
128
        if (PEAR::isError($remoteInfo)) {
111
        if (PEAR::isError($remoteInfo)) {
129
            return $remoteInfo;
112
            return $remoteInfo;
130
        }
113
        }
-
 
114
 
131
        $cmd = &$this->factory("download");
115
        $cmd = &$this->factory("download");
132
        if (PEAR::isError($cmd)) {
116
        if (PEAR::isError($cmd)) {
133
            return $cmd;
117
            return $cmd;
134
        }
118
        }
-
 
119
 
135
        $this->ui->outputData('Using Preferred State of ' .
120
        $this->ui->outputData('Using Preferred State of ' .
136
            $this->config->get('preferred_state'));
121
            $this->config->get('preferred_state'));
137
        $this->ui->outputData('Gathering release information, please wait...');
122
        $this->ui->outputData('Gathering release information, please wait...');
-
 
123
 
138
        /**
124
        /**
139
         * Error handling not necessary, because already done by 
125
         * Error handling not necessary, because already done by
140
         * the download command
126
         * the download command
141
         */
127
         */
142
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
128
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
143
        $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo));
129
        $err = $cmd->run('download', array('downloadonly' => true), array_keys($remoteInfo));
144
        PEAR::staticPopErrorHandling();
130
        PEAR::staticPopErrorHandling();
145
        $this->config->set('default_channel', $savechannel);
131
        $this->config->set('default_channel', $savechannel);
146
        if (PEAR::isError($err)) {
132
        if (PEAR::isError($err)) {
147
            $this->ui->outputData($err->getMessage());
133
            $this->ui->outputData($err->getMessage());
148
        }
134
        }
-
 
135
 
149
        return true;
136
        return true;
150
    }
137
    }
151
 
-
 
152
    // }}}
-
 
153
}
138
}