svn: /pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/ Commands.php

[email protected] (Brett Bieber) Sat, 17 Jul 2010 13:35:02 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
saltybeagle                              Sat, 17 Jul 2010 13:35:02 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=301348

Log:
If an install command fails because of an undiscovered channel error, ask the user if they'd like to discover the channel and try the install again.

Changed paths:
    U   pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php

Modified: pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php
===================================================================
--- pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php	2010-07-17 09:09:26 UTC (rev 301347)
+++ pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php	2010-07-17 13:35:02 UTC (rev 301348)
@@ -497,6 +497,26 @@
                 echo $dep, ' depended on by ', implode(', ', array_keys($packages)), "\n";
             }
         } catch (\Exception $e) {
+
+            // If this is an undiscovered channel, handle it gracefully
+            if ($e instanceof \PEAR2\Pyrus\Package\Exception
+                && $e->getPrevious() instanceof \PEAR2\Pyrus\ChannelRegistry\Exception
+                && $e->getPrevious()->getPrevious() instanceof \PEAR2\Pyrus\ChannelRegistry\ParseException
+                && $e->getPrevious()->getPrevious()->why == 'channel'
+                && strpos($arg, '/') !== false) {
+
+                $channel = strstr($arg, '/', true);
+
+                echo "Sorry, the channel \"{$channel}\" is unknown.\n";
+
+                if ('yes' === $this->ask('Do you want to add this channel and continue the install?', array('yes', 'no'), 'yes')) {
+                    $this->channelDiscover(array('channel' => $channel));
+                    $this->install($args, $options);
+                    return;
+                }
+                echo "Ok. I understand.\n";
+            }
+
             $this->exceptionHandler($e);
             exit -1;
         }