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