| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 // /* vim: set expandtab tabstop=4 shiftwidth=4: */ 3 /** 4 * PEAR_Command_Channels (list-channels, update-channels, channel-delete, channel-add, 5 * channel-update, channel-info, channel-alias, channel-discover commands) 6 * 7 * PHP versions 4 and 5 8 * 9 * LICENSE: This source file is subject to version 3.0 of the PHP license 10 * that is available through the world-wide-web at the following URI: 11 * http://www.php.net/license/3_0.txt. If you did not receive a copy of 12 * the PHP License and are unable to obtain it through the web, please 13 * send a note to license@php.net so we can mail you a copy immediately. 14 * 15 * @category pear 16 * @package PEAR 17 * @author Stig Bakken <ssb@php.net> 18 * @author Greg Beaver <cellog@php.net> 19 * @copyright 1997-2006 The PHP Group 20 * @license http://www.php.net/license/3_0.txt PHP License 3.0 21 * @version CVS: $Id: Channels.php,v 1.44.2.1 2006/07/17 18:24:10 pajoye Exp $ 22 * @link http://pear.php.net/package/PEAR 23 * @since File available since Release 1.4.0a1 24 */ 25 26 /** 27 * base class 28 */ 29 require_once 'PEAR/Command/Common.php'; 30 31 /** 32 * PEAR commands for managing channels. 33 * 34 * @category pear 35 * @package PEAR 36 * @author Greg Beaver <cellog@php.net> 37 * @copyright 1997-2006 The PHP Group 38 * @license http://www.php.net/license/3_0.txt PHP License 3.0 39 * @version Release: 1.4.11 40 * @link http://pear.php.net/package/PEAR 41 * @since Class available since Release 1.4.0a1 42 */ 43 class PEAR_Command_Channels extends PEAR_Command_Common 44 { 45 // {{{ properties 46 47 var $commands = array( 48 'list-channels' => array( 49 'summary' => 'List Available Channels', 50 'function' => 'doList', 51 'shortcut' => 'lc', 52 'options' => array(), 53 'doc' => ' 54 List all available channels for installation. 55 ', 56 ), 57 'update-channels' => array( 58 'summary' => 'Update the Channel List', 59 'function' => 'doUpdateAll', 60 'shortcut' => 'uc', 61 'options' => array(), 62 'doc' => ' 63 List all installed packages in all channels. 64 ' 65 ), 66 'channel-delete' => array( 67 'summary' => 'Remove a Channel From the List', 68 'function' => 'doDelete', 69 'shortcut' => 'cde', 70 'options' => array(), 71 'doc' => '<channel name> 72 Delete a channel from the registry. You may not 73 remove any channel that has installed packages. 74 ' 75 ), 76 'channel-add' => array( 77 'summary' => 'Add a Channel', 78 'function' => 'doAdd', 79 'shortcut' => 'ca', 80 'options' => array(), 81 'doc' => '<channel.xml> 82 Add a private channel to the channel list. Note that all 83 public channels should be synced using "update-channels". 84 Parameter may be either a local file or remote URL to a 85 channel.xml. 86 ' 87 ), 88 'channel-update' => array( 89 'summary' => 'Update an Existing Channel', 90 'function' => 'doUpdate', 91 'shortcut' => 'cu', 92 'options' => array( 93 'force' => array( 94 'shortopt' => 'f', 95 'doc' => 'will force download of new channel.xml if an existing channel name is used', 96 ), 97 'channel' => array( 98 'shortopt' => 'c', 99 'arg' => 'CHANNEL', 100 'doc' => 'will force download of new channel.xml if an existing channel name is used', 101 ), 102 ), 103 'doc' => '[<channel.xml>|<channel name>] 104 Update a channel in the channel list directly. Note that all 105 public channels can be synced using "update-channels". 106 Parameter may be a local or remote channel.xml, or the name of 107 an existing channel. 108 ' 109 ), 110 'channel-info' => array( 111 'summary' => 'Retrieve Information on a Channel', 112 'function' => 'doInfo', 113 'shortcut' => 'ci', 114 'options' => array(), 115 'doc' => '<package> 116 List the files in an installed package. 117 ' 118 ), 119 'channel-alias' => array( 120 'summary' => 'Specify an alias to a channel name', 121 'function' => 'doAlias', 122 'shortcut' => 'cha', 123 'options' => array(), 124 'doc' => '<channel> <alias> 125 Specify a specific alias to use for a channel name. 126 The alias may not be an existing channel name or 127 alias. 128 ' 129 ), 130 'channel-discover' => array( 131 'summary' => 'Initialize a Channel from its server', 132 'function' => 'doDiscover', 133 'shortcut' => 'di', 134 'options' => array(), 135 'doc' => '[<channel.xml>|<channel name>] 136 Initialize a Channel from its server and creates the local channel.xml. 137 ' 138 ), 139 ); 140 141 // }}} 142 // {{{ constructor 143 144 /** 145 * PEAR_Command_Registry constructor. 146 * 147 * @access public 148 */ 149 function PEAR_Command_Channels(&$ui, &$config) 150 { 151 parent::PEAR_Command_Common($ui, $config); 152 } 153 154 // }}} 155 156 // {{{ doList() 157 158 function _sortChannels($a, $b) 159 { 160 return strnatcasecmp($a->getName(), $b->getName()); 161 } 162 163 function doList($command, $options, $params) 164 { 165 $reg = &$this->config->getRegistry(); 166 $registered = $reg->getChannels(); 167 usort($registered, array(&$this, '_sortchannels')); 168 $i = $j = 0; 169 $data = array( 170 'caption' => 'Registered Channels:', 171 'border' => true, 172 'headline' => array('Channel', 'Summary') 173 ); 174 foreach ($registered as $channel) { 175 $data['data'][] = array($channel->getName(), 176 $channel->getSummary()); 177 } 178 if (count($registered)==0) { 179 $data = '(no registered channels)'; 180 } 181 $this->ui->outputData($data, $command); 182 return true; 183 } 184 185 function doUpdateAll($command, $options, $params) 186 { 187 $reg = &$this->config->getRegistry(); 188 $savechannel = $this->config->get('default_channel'); 189 if (isset($options['channel'])) { 190 if (!$reg->channelExists($options['channel'])) { 191 return $this->raiseError('Unknown channel "' . $options['channel'] . '"'); 192 } 193 $this->config->set('default_channel', $options['channel']); 194 } else { 195 $this->config->set('default_channel', 'pear.php.net'); 196 } 197 $remote = &$this->config->getRemote(); 198 $channels = $remote->call('channel.listAll'); 199 if (PEAR::isError($channels)) { 200 $this->config->set('default_channel', $savechannel); 201 return $channels; 202 } 203 if (!is_array($channels) || isset($channels['faultCode'])) { 204 $this->config->set('default_channel', $savechannel); 205 return $this->raiseError("Incorrect channel listing returned from channel '$chan'"); 206 } 207 if (!count($channels)) { 208 $data = 'no updates available'; 209 } 210 $dl = &$this->getDownloader(); 211 if (!class_exists('System')) { 212 require_once 'System.php'; 213 } 214 $tmpdir = System::mktemp(array('-d')); 215 foreach ($channels as $channel) { 216 $channel = $channel[0]; 217 $save = $channel; 218 if ($reg->channelExists($channel, true)) { 219 $this->ui->outputData("Updating channel \"$channel\"", $command); 220 $test = $reg->getChannel($channel, true); 221 if (PEAR::isError($test)) { 222 $this->ui->outputData("Channel '$channel' is corrupt in registry!", $command); 223 $lastmodified = false; 224 } else { 225 $lastmodified = $test->lastModified(); 226 227 } 228 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 229 $contents = $dl->downloadHttp('http://' . $test->getName() . '/channel.xml', 230 $this->ui, $tmpdir, null, $lastmodified); 231 PEAR::staticPopErrorHandling(); 232 if (PEAR::isError($contents)) { 233 $this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' . 234 $test->getName() . '"', $command); 235 continue; 236 } 237 if (!$contents) { 238 $this->ui->outputData("Channel \"$channel\" is up-to-date", $command); 239 continue; 240 } 241 list($contents, $lastmodified) = $contents; 242 $info = implode('', file($contents)); 243 if (!$info) { 244 $this->ui->outputData("Channel \"$channel\" is up-to-date", $command); 245 continue; 246 } 247 if (!class_exists('PEAR_ChannelFile')) { 248 require_once 'PEAR/ChannelFile.php'; 249 } 250 $channelinfo = new PEAR_ChannelFile; 251 $channelinfo->fromXmlString($info); 252 if ($channelinfo->getErrors()) { 253 $this->ui->outputData("Downloaded channel data from channel \"$channel\" " . 254 'is corrupt, skipping', $command); 255 continue; 256 } 257 $channel = $channelinfo; 258 if ($channel->getName() != $save) { 259 $this->ui->outputData('ERROR: Security risk - downloaded channel ' . 260 'definition file for channel "' 261 . $channel->getName() . ' from channel "' . $save . 262 '". To use anyway, use channel-update', $command); 263 continue; 264 } 265 $reg->updateChannel($channel, $lastmodified); 266 } else { 267 if ($reg->isAlias($channel)) { 268 $temp = &$reg->getChannel($channel); 269 if (PEAR::isError($temp)) { 270 return $this->raiseError($temp); 271 } 272 $temp->setAlias($temp->getName(), true); // set the alias to the channel name 273 if ($reg->channelExists($temp->getName())) { 274 $this->ui->outputData('ERROR: existing channel "' . $temp->getName() . 275 '" is aliased to "' . $channel . '" already and cannot be ' . 276 're-aliased to "' . $temp->getName() . '" because a channel with ' . 277 'that name or alias already exists! Please re-alias and try ' . 278 'again.', $command); 279 continue; 280 } 281 } 282 $this->ui->outputData("Adding new channel \"$channel\"", $command); 283 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 284 $contents = $dl->downloadHttp('http://' . $channel . '/channel.xml', 285 $this->ui, $tmpdir, null, false); 286 PEAR::staticPopErrorHandling(); 287 if (PEAR::isError($contents)) { 288 $this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' . 289 $channel . '"', $command); 290 continue; 291 } 292 list($contents, $lastmodified) = $contents; 293 $info = implode('', file($contents)); 294 if (!class_exists('PEAR_ChannelFile')) { 295 require_once 'PEAR/ChannelFile.php'; 296 } 297 $channelinfo = new PEAR_Channelfile; 298 $channelinfo->fromXmlString($info); 299 if ($channelinfo->getErrors()) { 300 $this->ui->outputData("Downloaded channel data from channel \"$channel\"" . 301 ' is corrupt, skipping', $command); 302 continue; 303 } 304 $channel = $channelinfo; 305 if ($channel->getName() != $save) { 306 $this->ui->outputData('ERROR: Security risk - downloaded channel ' . 307 'definition file for channel "' 308 . $channel->getName() . '" from channel "' . $save . 309 '". To use anyway, use channel-update', $command); 310 continue; 311 } 312 $reg->addChannel($channel, $lastmodified); 313 } 314 } 315 $this->config->set('default_channel', $savechannel); 316 $this->ui->outputData('update-channels complete', $command); 317 return true; 318 } 319 320 function doInfo($command, $options, $params) 321 { 322 if (sizeof($params) != 1) { 323 return $this->raiseError("No channel specified"); 324 } 325 $reg = &$this->config->getRegistry(); 326 $channel = strtolower($params[0]); 327 if ($reg->channelExists($channel)) { 328 $chan = $reg->getChannel($channel); 329 if (PEAR::isError($chan)) { 330 return $this->raiseError($chan); 331 } 332 } else { 333 if (strpos($channel, '://')) { 334 $downloader = &$this->getDownloader(); 335 if (!class_exists('System')) { 336 require_once 'System.php'; 337 } 338 $tmpdir = System::mktemp(array('-d')); 339 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 340 $loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir); 341 PEAR::staticPopErrorHandling(); 342 if (PEAR::isError($loc)) { 343 return $this->raiseError('Cannot open "' . $channel . '"'); 344 } else { 345 $contents = implode('', file($loc)); 346 } 347 } else { 348 $fp = @fopen($params[0], 'r'); 349 if (!$fp) { 350 if (@file_exists($params[0])) { 351 return $this->raiseError('Cannot open "' . $params[0] . '"'); 352 } else { 353 return $this->raiseError('Unknown channel "' . $channel . '"'); 354 } 355 } 356 $contents = ''; 357 while (!feof($fp)) { 358 $contents .= fread($fp, 1024); 359 } 360 fclose($fp); 361 } 362 if (!class_exists('PEAR_ChannelFile')) { 363 require_once 'PEAR/ChannelFile.php'; 364 } 365 $chan = new PEAR_ChannelFile; 366 $chan->fromXmlString($contents); 367 $chan->validate(); 368 if ($errs = $chan->getErrors(true)) { 369 foreach ($errs as $err) { 370 $this->ui->outputData($err['level'] . ': ' . $err['message']); 371 } 372 return $this->raiseError('Channel file "' . $params[0] . '" is not valid'); 373 } 374 } 375 if ($chan) { 376 $channel = $chan->getName(); 377 $caption = 'Channel ' . $channel . ' Information:'; 378 $data1 = array( 379 'caption' => $caption, 380 'border' => true); 381 $data1['data']['server'] = array('Name and Server', $chan->getName()); 382 if ($chan->getAlias() != $chan->getName()) { 383 $data1['data']['alias'] = array('Alias', $chan->getAlias()); 384 } 385 $data1['data']['summary'] = array('Summary', $chan->getSummary()); 386 $validate = $chan->getValidationPackage(); 387 $data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']); 388 $data1['data']['vpackageversion'] = 389 array('Validation Package Version', $validate['attribs']['version']); 390 $d = array(); 391 $d['main'] = $data1; 392 393 $data['data'] = array(); 394 $data['caption'] = 'Server Capabilities'; 395 $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base'); 396 $capabilities = $chan->getFunctions('xmlrpc'); 397 $soaps = $chan->getFunctions('soap'); 398 if ($capabilities || $soaps || $chan->supportsREST()) { 399 if ($capabilities) { 400 if (!isset($capabilities[0])) { 401 $capabilities = array($capabilities); 402 } 403 foreach ($capabilities as $protocol) { 404 $data['data'][] = array('xmlrpc', $protocol['attribs']['version'], 405 $protocol['_content']); 406 } 407 } 408 if ($soaps) { 409 if (!isset($soaps[0])) { 410 $soaps = array($soaps); 411 } 412 foreach ($soaps as $protocol) { 413 $data['data'][] = array('soap', $protocol['attribs']['version'], 414 $protocol['_content']); 415 } 416 } 417 if ($chan->supportsREST()) { 418 $funcs = $chan->getFunctions('rest'); 419 if (!isset($funcs[0])) { 420 $funcs = array($funcs); 421 } 422 foreach ($funcs as $protocol) { 423 $data['data'][] = array('rest', $protocol['attribs']['type'], 424 $protocol['_content']); 425 } 426 } 427 } else { 428 $data['data'][] = array('No supported protocols'); 429 } 430 $d['protocols'] = $data; 431 $data['data'] = array(); 432 $mirrors = $chan->getMirrors(); 433 if ($mirrors) { 434 $data['caption'] = 'Channel ' . $channel . ' Mirrors:'; 435 unset($data['headline']); 436 foreach ($mirrors as $mirror) { 437 $data['data'][] = array($mirror['attribs']['host']); 438 $d['mirrors'] = $data; 439 } 440 foreach ($mirrors as $mirror) { 441 $data['data'] = array(); 442 $data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities'; 443 $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base'); 444 $capabilities = $chan->getFunctions('xmlrpc', $mirror['attribs']['host']); 445 $soaps = $chan->getFunctions('soap', $mirror['attribs']['host']); 446 if ($capabilities || $soaps || $chan->supportsREST($mirror['attribs']['host'])) { 447 if ($capabilities) { 448 if (!isset($capabilities[0])) { 449 $capabilities = array($capabilities); 450 } 451 foreach ($capabilities as $protocol) { 452 $data['data'][] = array('xmlrpc', $protocol['attribs']['version'], 453 $protocol['_content']); 454 } 455 } 456 if ($soaps) { 457 if (!isset($soaps[0])) { 458 $soaps = array($soaps); 459 } 460 foreach ($soaps as $protocol) { 461 $data['data'][] = array('soap', $protocol['attribs']['version'], 462 $protocol['_content']); 463 } 464 } 465 if ($chan->supportsREST($mirror['attribs']['host'])) { 466 $funcs = $chan->getFunctions('rest', $mirror['attribs']['host']); 467 if (!isset($funcs[0])) { 468 $funcs = array($funcs); 469 } 470 foreach ($funcs as $protocol) { 471 $data['data'][] = array('rest', $protocol['attribs']['type'], 472 $protocol['_content']); 473 } 474 } 475 } else { 476 $data['data'][] = array('No supported protocols'); 477 } 478 $d['mirrorprotocols'] = $data; 479 } 480 } 481 $this->ui->outputData($d, 'channel-info'); 482 } else { 483 return $this->raiseError('Serious error: Channel "' . $params[0] . 484 '" has a corrupted registry entry'); 485 } 486 } 487 488 // }}} 489 490 function doDelete($command, $options, $params) 491 { 492 if (sizeof($params) != 1) { 493 return $this->raiseError('channel-delete: no channel specified'); 494 } 495 $reg = &$this->config->getRegistry(); 496 if (!$reg->channelExists($params[0])) { 497 return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist'); 498 } 499 $channel = $reg->channelName($params[0]); 500 if ($channel == 'pear.php.net') { 501 return $this->raiseError('Cannot delete the pear.php.net channel'); 502 } 503 if ($channel == 'pecl.php.net') { 504 return $this->raiseError('Cannot delete the pecl.php.net channel'); 505 } 506 if ($channel == '__uri') { 507 return $this->raiseError('Cannot delete the __uri pseudo-channel'); 508 } 509 if (PEAR::isError($err = $reg->listPackages($channel))) { 510 return $err; 511 } 512 if (count($err)) { 513 return $this->raiseError('Channel "' . $channel . 514 '" has installed packages, cannot delete'); 515 } 516 if (!$reg->deleteChannel($channel)) { 517 return $this->raiseError('Channel "' . $channel . '" deletion failed'); 518 } else { 519 $this->config->deleteChannel($channel); 520 $this->ui->outputData('Channel "' . $channel . '" deleted', $command); 521 } 522 } 523 524 function doAdd($command, $options, $params) 525 { 526 if (sizeof($params) != 1) { 527 return $this->raiseError('channel-add: no channel file specified'); 528 } 529 if (strpos($params[0], '://')) { 530 $downloader = &$this->getDownloader(); 531 if (!class_exists('System')) { 532 require_once 'System.php'; 533 } 534 $tmpdir = System::mktemp(array('-d')); 535 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 536 $loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false); 537 PEAR::staticPopErrorHandling(); 538 if (PEAR::isError($loc)) { 539 return $this->raiseError('channel-add: Cannot open "' . $params[0] . '"'); 540 } else { 541 list($loc, $lastmodified) = $loc; 542 $contents = implode('', file($loc)); 543 } 544 } else { 545 $lastmodified = false; 546 $fp = @fopen($params[0], 'r'); 547 if (!$fp) { 548 return $this->raiseError('channel-add: cannot open "' . $params[0] . '"'); 549 } 550 $contents = ''; 551 while (!feof($fp)) { 552 $contents .= fread($fp, 1024); 553 } 554 fclose($fp); 555 } 556 if (!class_exists('PEAR_ChannelFile')) { 557 require_once 'PEAR/ChannelFile.php'; 558 } 559 $channel = new PEAR_ChannelFile; 560 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 561 $result = $channel->fromXmlString($contents); 562 PEAR::staticPopErrorHandling(); 563 if (!$result) { 564 $exit = false; 565 if (count($errors = $channel->getErrors(true))) { 566 foreach ($errors as $error) { 567 $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message'])); 568 if (!$exit) { 569 $exit = $error['level'] == 'error' ? true : false; 570 } 571 } 572 if ($exit) { 573 return $this->raiseError('channel-add: invalid channel.xml file'); 574 } 575 } 576 } 577 $reg = &$this->config->getRegistry(); 578 if ($reg->channelExists($channel->getName())) { 579 return $this->raiseError('channel-add: Channel "' . $channel->getName() . 580 '" exists, use channel-update to update entry'); 581 } 582 $ret = $reg->addChannel($channel, $lastmodified); 583 if (PEAR::isError($ret)) { 584 return $ret; 585 } 586 if (!$ret) { 587 return $this->raiseError('channel-add: adding Channel "' . $channel->getName() . 588 '" to registry failed'); 589 } 590 $this->config->setChannels($reg->listChannels()); 591 $this->config->writeConfigFile(); 592 $this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command); 593 } 594 595 function doUpdate($command, $options, $params) 596 { 597 if (!class_exists('System')) { 598 require_once 'System.php'; 599 } 600 $tmpdir = System::mktemp(array('-d')); 601 $reg = &$this->config->getRegistry(); 602 if (sizeof($params) != 1) { 603 return $this->raiseError("No channel file specified"); 604 } 605 $lastmodified = false; 606 if ((!file_exists($params[0]) || is_dir($params[0])) 607 && $reg->channelExists(strtolower($params[0]))) { 608 $c = $reg->getChannel(strtolower($params[0])); 609 if (PEAR::isError($c)) { 610 return $this->raiseError($c); 611 } 612 $this->ui->outputData('Retrieving channel.xml from remote server'); 613 $dl = &$this->getDownloader(array()); 614 // if force is specified, use a timestamp of "1" to force retrieval 615 $lastmodified = isset($options['force']) ? false : $c->lastModified(); 616 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 617 $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml', 618 $this->ui, $tmpdir, null, $lastmodified); 619 PEAR::staticPopErrorHandling(); 620 if (PEAR::isError($contents)) { 621 return $this->raiseError('Cannot retrieve channel.xml for channel "' . 622 $c->getName() . '"'); 623 } 624 list($contents, $lastmodified) = $contents; 625 if (!$contents) { 626 $this->ui->outputData("Channel $params[0] channel.xml is up to date"); 627 return; 628 } 629 $contents = implode('', file($contents)); 630 if (!class_exists('PEAR_ChannelFile')) { 631 require_once 'PEAR/ChannelFile.php'; 632 } 633 $channel = new PEAR_ChannelFile; 634 $channel->fromXmlString($contents); 635 if (!$channel->getErrors()) { 636 // security check: is the downloaded file for the channel we got it from? 637 if (strtolower($channel->getName()) != strtolower($c->getName())) { 638 if (isset($options['force'])) { 639 $this->ui->log(0, 'WARNING: downloaded channel definition file' . 640 ' for channel "' . $channel->getName() . '" from channel "' . 641 strtolower($c->getName()) . '"'); 642 } else { 643 return $this->raiseError('ERROR: downloaded channel definition file' . 644 ' for channel "' . $channel->getName() . '" from channel "' . 645 strtolower($c->getName()) . '"'); 646 } 647 } 648 } 649 } else { 650 if (strpos($params[0], '://')) { 651 $dl = &$this->getDownloader(); 652 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 653 $loc = $dl->downloadHttp($params[0], 654 $this->ui, $tmpdir, null, $lastmodified); 655 PEAR::staticPopErrorHandling(); 656 if (PEAR::isError($loc)) { 657 return $this->raiseError("Cannot open " . $params[0]); 658 } else { 659 list($loc, $lastmodified) = $loc; 660 $contents = implode('', file($loc)); 661 } 662 } else { 663 $fp = @fopen($params[0], 'r'); 664 if (!$fp) { 665 return $this->raiseError("Cannot open " . $params[0]); 666 } 667 $contents = ''; 668 while (!feof($fp)) { 669 $contents .= fread($fp, 1024); 670 } 671 fclose($fp); 672 } 673 if (!class_exists('PEAR_ChannelFile')) { 674 require_once 'PEAR/ChannelFile.php'; 675 } 676 $channel = new PEAR_ChannelFile; 677 $channel->fromXmlString($contents); 678 } 679 $exit = false; 680 if (count($errors = $channel->getErrors(true))) { 681 foreach ($errors as $error) { 682 $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message'])); 683 if (!$exit) { 684 $exit = $error['level'] == 'error' ? true : false; 685 } 686 } 687 if ($exit) { 688 return $this->raiseError('Invalid channel.xml file'); 689 } 690 } 691 if (!$reg->channelExists($channel->getName())) { 692 return $this->raiseError('Error: Channel "' . $channel->getName() . 693 '" does not exist, use channel-add to add an entry'); 694 } 695 $ret = $reg->updateChannel($channel, $lastmodified); 696 if (PEAR::isError($ret)) { 697 return $ret; 698 } 699 if (!$ret) { 700 return $this->raiseError('Updating Channel "' . $channel->getName() . 701 '" in registry failed'); 702 } 703 $this->config->setChannels($reg->listChannels()); 704 $this->config->writeConfigFile(); 705 $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded'); 706 } 707 708 function &getDownloader() 709 { 710 if (!class_exists('PEAR_Downloader')) { 711 require_once 'PEAR/Downloader.php'; 712 } 713 $a = new PEAR_Downloader($this->ui, array(), $this->config); 714 return $a; 715 } 716 717 function doAlias($command, $options, $params) 718 { 719 $reg = &$this->config->getRegistry(); 720 if (sizeof($params) == 1) { 721 return $this->raiseError('No channel alias specified'); 722 } 723 if (sizeof($params) != 2) { 724 return $this->raiseError( 725 'Invalid format, correct is: channel-alias channel alias'); 726 } 727 if (!$reg->channelExists($params[0], true)) { 728 if ($reg->isAlias($params[0])) { 729 $extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' . 730 strtolower($params[1]) . '")'; 731 } else { 732 $extra = ''; 733 } 734 return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra); 735 } 736 if ($reg->isAlias($params[1])) { 737 return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' . 738 'already aliased to "' . strtolower($params[1]) . '", cannot re-alias'); 739 } 740 $chan = &$reg->getChannel($params[0]); 741 if (PEAR::isError($chan)) { 742 return $this->raiseError('Corrupt registry? Error retrieving channel "' . $params[0] . 743 '" information (' . $chan->getMessage() . ')'); 744 } 745 // make it a local alias 746 if (!$chan->setAlias(strtolower($params[1]), true)) { 747 return $this->raiseError('Alias "' . strtolower($params[1]) . 748 '" is not a valid channel alias'); 749 } 750 $reg->updateChannel($chan); 751 $this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' . 752 strtolower($params[1]) . '"'); 753 } 754 755 function doDiscover($command, $options, $params) 756 { 757 $reg = &$this->config->getRegistry(); 758 if (sizeof($params) != 1) { 759 return $this->raiseError("No channel server specified"); 760 } 761 if ($reg->channelExists($params[0])) { 762 if ($reg->isAlias($params[0])) { 763 return $this->raiseError("A channel alias named \"$params[0]\" " . 764 'already exists, aliasing channel "' . $reg->channelName($params[0]) 765 . '"'); 766 } else { 767 return $this->raiseError("Channel \"$params[0]\" is already initialized"); 768 } 769 } 770 $this->pushErrorHandling(PEAR_ERROR_RETURN); 771 $err = $this->doAdd($command, $options, array('http://' . $params[0] . '/channel.xml')); 772 $this->popErrorHandling(); 773 if (PEAR::isError($err)) { 774 return $this->raiseError("Discovery of channel \"$params[0]\" failed (" . 775 $err->getMessage() . ')'); 776 } 777 $this->ui->outputData("Discovery of channel \"$params[0]\" succeeded", $command); 778 } 779 } 780 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
|