181 $reg = &$this->config->getRegistry();
182 $registered = $reg->getChannels();
183 usort($registered, array(&$this,
'_sortchannels'));
186 'caption' =>
'Registered Channels:',
188 'headline' => array(
'Channel',
'Alias',
'Summary')
190 foreach ($registered as $channel) {
191 $data[
'data'][] = array($channel->getName(),
192 $channel->getAlias(),
193 $channel->getSummary());
196 if (count($registered) === 0) {
197 $data =
'(no registered channels)';
199 $this->ui->outputData($data,
$command);
228 if (count($params) !== 1) {
229 return $this->raiseError(
"No channel specified");
232 $reg = &$this->config->getRegistry();
233 $channel = strtolower($params[0]);
234 if ($reg->channelExists($channel)) {
235 $chan = $reg->getChannel($channel);
237 return $this->raiseError($chan);
240 if (strpos($channel,
'://')) {
242 $tmpdir = $this->config->get(
'temp_dir');
244 $loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir);
247 return $this->raiseError(
'Cannot open "' . $channel .
248 '" (' . $loc->getMessage() .
')');
250 $contents = implode(
'', file($loc));
253 if (!file_exists($params[0])) {
254 return $this->raiseError(
'Unknown channel "' . $channel .
'"');
257 $fp = fopen($params[0],
'r');
259 return $this->raiseError(
'Cannot open "' . $params[0] .
'"');
264 $contents .= fread($fp, 1024);
269 if (!class_exists(
'PEAR_ChannelFile')) {
270 require_once
'PEAR/ChannelFile.php';
276 if ($errs = $chan->getErrors(
true)) {
277 foreach ($errs as $err) {
278 $this->ui->outputData($err[
'level'] .
': ' . $err[
'message']);
280 return $this->raiseError(
'Channel file "' . $params[0] .
'" is not valid');
285 return $this->raiseError(
'Serious error: Channel "' . $params[0] .
286 '" has a corrupted registry entry');
289 $channel = $chan->getName();
290 $caption =
'Channel ' . $channel .
' Information:';
292 'caption' => $caption,
294 $data1[
'data'][
'server'] = array(
'Name and Server', $chan->getName());
295 if ($chan->getAlias() != $chan->getName()) {
296 $data1[
'data'][
'alias'] = array(
'Alias', $chan->getAlias());
299 $data1[
'data'][
'summary'] = array(
'Summary', $chan->getSummary());
300 $validate = $chan->getValidationPackage();
301 $data1[
'data'][
'vpackage'] = array(
'Validation Package Name', $validate[
'_content']);
302 $data1[
'data'][
'vpackageversion'] =
303 array(
'Validation Package Version', $validate[
'attribs'][
'version']);
307 $data[
'data'] = array();
308 $data[
'caption'] =
'Server Capabilities';
309 $data[
'headline'] = array(
'Type',
'Version/REST type',
'Function Name/REST base');
310 if ($chan->supportsREST()) {
311 if ($chan->supportsREST()) {
312 $funcs = $chan->getFunctions(
'rest');
313 if (!isset($funcs[0])) {
314 $funcs = array($funcs);
316 foreach ($funcs as $protocol) {
317 $data[
'data'][] = array(
'rest', $protocol[
'attribs'][
'type'],
318 $protocol[
'_content']);
322 $data[
'data'][] = array(
'No supported protocols');
325 $d[
'protocols'] = $data;
326 $data[
'data'] = array();
327 $mirrors = $chan->getMirrors();
329 $data[
'caption'] =
'Channel ' . $channel .
' Mirrors:';
330 unset($data[
'headline']);
331 foreach ($mirrors as $mirror) {
332 $data[
'data'][] = array($mirror[
'attribs'][
'host']);
333 $d[
'mirrors'] = $data;
336 foreach ($mirrors as $i => $mirror) {
337 $data[
'data'] = array();
338 $data[
'caption'] =
'Mirror ' . $mirror[
'attribs'][
'host'] .
' Capabilities';
339 $data[
'headline'] = array(
'Type',
'Version/REST type',
'Function Name/REST base');
340 if ($chan->supportsREST($mirror[
'attribs'][
'host'])) {
341 if ($chan->supportsREST($mirror[
'attribs'][
'host'])) {
342 $funcs = $chan->getFunctions(
'rest', $mirror[
'attribs'][
'host']);
343 if (!isset($funcs[0])) {
344 $funcs = array($funcs);
347 foreach ($funcs as $protocol) {
348 $data[
'data'][] = array(
'rest', $protocol[
'attribs'][
'type'],
349 $protocol[
'_content']);
353 $data[
'data'][] = array(
'No supported protocols');
355 $d[
'mirrorprotocols' . $i] = $data;
358 $this->ui->outputData($d,
'channel-info');
365 if (count($params) !== 1) {
366 return $this->raiseError(
'channel-delete: no channel specified');
369 $reg = &$this->config->getRegistry();
370 if (!$reg->channelExists($params[0])) {
371 return $this->raiseError(
'channel-delete: channel "' . $params[0] .
'" does not exist');
374 $channel = $reg->channelName($params[0]);
375 if ($channel ==
'pear.php.net') {
376 return $this->raiseError(
'Cannot delete the pear.php.net channel');
379 if ($channel ==
'pecl.php.net') {
380 return $this->raiseError(
'Cannot delete the pecl.php.net channel');
383 if ($channel ==
'doc.php.net') {
384 return $this->raiseError(
'Cannot delete the doc.php.net channel');
387 if ($channel ==
'__uri') {
388 return $this->raiseError(
'Cannot delete the __uri pseudo-channel');
396 return $this->raiseError(
'Channel "' . $channel .
397 '" has installed packages, cannot delete');
400 if (!$reg->deleteChannel($channel)) {
401 return $this->raiseError(
'Channel "' . $channel .
'" deletion failed');
403 $this->config->deleteChannel($channel);
404 $this->ui->outputData(
'Channel "' . $channel .
'" deleted',
$command);
410 if (count($params) !== 1) {
411 return $this->raiseError(
'channel-add: no channel file specified');
414 if (strpos($params[0],
'://')) {
416 $tmpdir = $this->config->get(
'temp_dir');
417 if (!file_exists($tmpdir)) {
418 require_once
'System.php';
420 $err = System::mkdir(array(
'-p', $tmpdir));
423 return $this->raiseError(
'channel-add: temp_dir does not exist: "' .
425 '" - You can change this location with "pear config-set temp_dir"');
429 if (!is_writable($tmpdir)) {
430 return $this->raiseError(
'channel-add: temp_dir is not writable: "' .
432 '" - You can change this location with "pear config-set temp_dir"');
436 $loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir,
null,
false);
439 return $this->raiseError(
'channel-add: Cannot open "' . $params[0] .
440 '" (' . $loc->getMessage() .
')');
443 list($loc, $lastmodified) = $loc;
444 $contents = implode(
'', file($loc));
446 $lastmodified = $fp =
false;
447 if (file_exists($params[0])) {
448 $fp = fopen($params[0],
'r');
452 return $this->raiseError(
'channel-add: cannot open "' . $params[0] .
'"');
457 $contents .= fread($fp, 1024);
462 if (!class_exists(
'PEAR_ChannelFile')) {
463 require_once
'PEAR/ChannelFile.php';
468 $result = $channel->fromXmlString($contents);
472 if (count($errors = $channel->getErrors(
true))) {
473 foreach ($errors as $error) {
474 $this->ui->outputData(ucfirst($error[
'level'] .
': ' . $error[
'message']));
476 $exit = $error[
'level'] ==
'error' ? true :
false;
480 return $this->raiseError(
'channel-add: invalid channel.xml file');
485 $reg = &$this->config->getRegistry();
486 if ($reg->channelExists($channel->getName())) {
487 return $this->raiseError(
'channel-add: Channel "' . $channel->getName() .
491 $ret = $reg->addChannel($channel, $lastmodified);
497 return $this->raiseError(
'channel-add: adding Channel "' . $channel->getName() .
498 '" to registry failed');
501 $this->config->setChannels($reg->listChannels());
502 $this->config->writeConfigFile();
503 $this->ui->outputData(
'Adding Channel "' . $channel->getName() .
'" succeeded',
$command);
508 if (count($params) !== 1) {
509 return $this->raiseError(
"No channel file specified");
512 $tmpdir = $this->config->get(
'temp_dir');
513 if (!file_exists($tmpdir)) {
514 require_once
'System.php';
516 $err = System::mkdir(array(
'-p', $tmpdir));
519 return $this->raiseError(
'channel-add: temp_dir does not exist: "' .
521 '" - You can change this location with "pear config-set temp_dir"');
525 if (!is_writable($tmpdir)) {
526 return $this->raiseError(
'channel-add: temp_dir is not writable: "' .
528 '" - You can change this location with "pear config-set temp_dir"');
531 $reg = &$this->config->getRegistry();
532 $lastmodified =
false;
533 if ((!file_exists($params[0]) || is_dir($params[0]))
534 && $reg->channelExists(strtolower($params[0]))) {
535 $c = $reg->getChannel(strtolower($params[0]));
537 return $this->raiseError($c);
540 $this->ui->outputData(
"Updating channel \"$params[0]\"",
$command);
543 $lastmodified = isset(
$options[
'force']) ? false : $c->lastModified();
545 $contents = $dl->downloadHttp(
'https://' . $c->getName() .
'/channel.xml',
546 $this->ui, $tmpdir,
null, $lastmodified);
550 $this->ui->outputData(
"Channel \"$params[0]\" is not responding over https://, failed with message: " . $contents->getMessage());
551 $this->ui->outputData(
"Trying channel \"$params[0]\" over http:// instead");
553 $contents = $dl->downloadHttp(
'http://' . $c->getName() .
'/channel.xml',
554 $this->ui, $tmpdir,
null, $lastmodified);
557 return $this->raiseError(
'Cannot retrieve channel.xml for channel "' .
558 $c->getName() .
'" (' . $contents->getMessage() .
')');
561 if (is_array($contents)) {
562 list($contents, $lastmodified) = $contents;
565 $this->ui->outputData(
"Channel \"$params[0]\" is up to date");
569 $contents = implode(
'', file($contents));
570 if (!class_exists(
'PEAR_ChannelFile')) {
571 require_once
'PEAR/ChannelFile.php';
576 if (!$channel->getErrors()) {
578 if (strtolower($channel->getName()) != strtolower($c->getName())) {
580 return $this->raiseError(
'ERROR: downloaded channel definition file' .
581 ' for channel "' . $channel->getName() .
'" from channel "' .
582 strtolower($c->getName()) .
'"');
585 $this->ui->log(0,
'WARNING: downloaded channel definition file' .
586 ' for channel "' . $channel->getName() .
'" from channel "' .
587 strtolower($c->getName()) .
'"');
591 if (strpos($params[0],
'://')) {
594 $loc = $dl->downloadHttp($params[0],
595 $this->ui, $tmpdir,
null, $lastmodified);
598 return $this->raiseError(
"Cannot open " . $params[0] .
599 ' (' . $loc->getMessage() .
')');
602 list($loc, $lastmodified) = $loc;
603 $contents = implode(
'', file($loc));
606 if (file_exists($params[0])) {
607 $fp = fopen($params[0],
'r');
611 return $this->raiseError(
"Cannot open " . $params[0]);
616 $contents .= fread($fp, 1024);
621 if (!class_exists(
'PEAR_ChannelFile')) {
622 require_once
'PEAR/ChannelFile.php';
630 if (count($errors = $channel->getErrors(
true))) {
631 foreach ($errors as $error) {
632 $this->ui->outputData(ucfirst($error[
'level'] .
': ' . $error[
'message']));
634 $exit = $error[
'level'] ==
'error' ? true :
false;
638 return $this->raiseError(
'Invalid channel.xml file');
642 if (!$reg->channelExists($channel->getName())) {
643 return $this->raiseError(
'Error: Channel "' . $channel->getName() .
644 '" does not exist, use channel-add to add an entry');
647 $ret = $reg->updateChannel($channel, $lastmodified);
653 return $this->raiseError(
'Updating Channel "' . $channel->getName() .
654 '" in registry failed');
657 $this->config->setChannels($reg->listChannels());
658 $this->config->writeConfigFile();
659 $this->ui->outputData(
'Update of Channel "' . $channel->getName() .
'" succeeded');
673 if (count($params) === 1) {
674 return $this->raiseError(
'No channel alias specified');
677 if (count($params) !== 2 || (!empty($params[1]) && $params[1][0] ==
'-')) {
678 return $this->raiseError(
679 'Invalid format, correct is: channel-alias channel alias');
682 $reg = &$this->config->getRegistry();
683 if (!$reg->channelExists($params[0],
true)) {
685 if ($reg->isAlias($params[0])) {
686 $extra =
' (use "channel-alias ' . $reg->channelName($params[0]) .
' ' .
687 strtolower($params[1]) .
'")';
690 return $this->raiseError(
'"' . $params[0] .
'" is not a valid channel' . $extra);
693 if ($reg->isAlias($params[1])) {
694 return $this->raiseError(
'Channel "' . $reg->channelName($params[1]) .
'" is ' .
695 'already aliased to "' . strtolower($params[1]) .
'", cannot re-alias');
698 $chan = $reg->getChannel($params[0]);
700 return $this->raiseError(
'Corrupt registry? Error retrieving channel "' . $params[0] .
701 '" information (' . $chan->getMessage() .
')');
705 if (!$chan->setAlias(strtolower($params[1]),
true)) {
706 return $this->raiseError(
'Alias "' . strtolower($params[1]) .
707 '" is not a valid channel alias');
710 $reg->updateChannel($chan);
711 $this->ui->outputData(
'Channel "' . $chan->getName() .
'" aliased successfully to "' .
712 strtolower($params[1]) .
'"');
728 if (count($params) !== 1) {
729 return $this->raiseError(
"No channel server specified");
733 if (preg_match(
'/^(.+):(.+)@(.+)\\z/', $params[0], $matches)) {
734 $username = $matches[1];
735 $password = $matches[2];
736 $channel = $matches[3];
738 $channel = $params[0];
741 $reg = &$this->config->getRegistry();
742 if ($reg->channelExists($channel)) {
743 if (!$reg->isAlias($channel)) {
747 return $this->raiseError(
"A channel alias named \"$channel\" " .
748 'already exists, aliasing channel "' . $reg->channelName($channel)
754 $this->popErrorHandling();
757 return $this->raiseError(
"Discovery of channel \"$channel\" failed (" .
758 $err->getMessage() .
')');
761 $this->ui->outputData(
"Discovering channel $channel over http:// failed with message: " . $err->getMessage());
762 $this->ui->outputData(
"Trying to discover channel $channel over https:// instead");
765 $this->popErrorHandling();
767 return $this->raiseError(
"Discovery of channel \"$channel\" failed (" .
768 $err->getMessage() .
')');
776 if (isset($username)) {
777 $this->config->set(
'username', $username,
'user', $channel);
778 $this->config->set(
'password', $password,
'user', $channel);
779 $this->config->store();
780 $this->ui->outputData(
"Stored login for channel \"$channel\" using username \"$username\"",
$command);
783 $this->ui->outputData(
"Discovery of channel \"$channel\" succeeded",
$command);
800 $reg = &$this->config->getRegistry();
803 $channel = isset($params[0]) ? $params[0] : $this->config->get(
'default_channel');
805 $chan = $reg->getChannel($channel);
807 return $this->raiseError($chan);
810 $server = $this->config->get(
'preferred_mirror',
null, $channel);
811 $username = $this->config->get(
'username',
null, $channel);
812 if (empty($username)) {
813 $username = isset($_ENV[
'USER']) ? $_ENV[
'USER'] :
null;
815 $this->ui->outputData(
"Logging in to $server.",
$command);
817 list($username, $password) = $this->ui->userDialog(
819 array(
'Username',
'Password'),
820 array(
'text',
'password'),
823 $username = trim($username);
824 $password = trim($password);
826 $ourfile = $this->config->getConfFile(
'user');
828 $ourfile = $this->config->getConfFile(
'system');
831 $this->config->set(
'username', $username,
'user', $channel);
832 $this->config->set(
'password', $password,
'user', $channel);
834 if ($chan->supportsREST()) {
839 return $this->raiseError(
'Login failed!');
842 $this->ui->outputData(
"Logged in.",
$command);
844 $ourconfig =
new PEAR_Config($ourfile, $ourfile);
845 $ourconfig->set(
'username', $username,
'user', $channel);
846 $ourconfig->set(
'password', $password,
'user', $channel);
866 $reg = &$this->config->getRegistry();
869 $channel = isset($params[0]) ? $params[0] : $this->config->get(
'default_channel');
871 $chan = $reg->getChannel($channel);
873 return $this->raiseError($chan);
876 $server = $this->config->get(
'preferred_mirror',
null, $channel);
877 $this->ui->outputData(
"Logging out from $server.",
$command);
878 $this->config->remove(
'username',
'user', $channel);
879 $this->config->remove(
'password',
'user', $channel);
880 $this->config->store();