Source for file Ethna_Plugin_Handle_UninstallPlugin.php

Documentation is available at Ethna_Plugin_Handle_UninstallPlugin.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Handle_UninstallPlugin.php
  5.  *
  6.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id$
  10.  */
  11.  
  12. require_once ETHNA_BASE . '/class/Ethna_PearWrapper.php';
  13.  
  14. // {{{ Ethna_Plugin_Handle_UninstallPlugin
  15. /**
  16.  *  install-plugin handler
  17.  *
  18.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  19.  *  @access     public
  20.  *  @package    Ethna
  21.  */
  22. {
  23.     // {{{ _parseArgList()
  24.     /**
  25.      * @access private
  26.      */
  27.     function &_parseArgList()
  28.     {
  29.         $r =& $this->_getopt(array('local', 'master', 'basedir=',
  30.                                    'channel=', 'pearopt='));
  31.         if (Ethna::isError($r)) {
  32.             return $r;
  33.         }
  34.         list($opt_list, $arg_list) = $r;
  35.         $ret = array();
  36.  
  37.         // options
  38.         $ret['target'] = isset($opt_list['master']) ? 'master' : 'local';
  39.         if (isset($opt_list['basedir'])) {
  40.             $ret['basedir'] = end($opt_list['basedir']);
  41.         }
  42.         if (isset($opt_list['channel'])) {
  43.             $ret['channel'] = end($opt_list['channel']);
  44.         }
  45.  
  46.         // arguments
  47.         if (count($arg_list) == 2) {
  48.             $ret['type'] = $arg_list[0];
  49.             $ret['name'] = $arg_list[1];
  50.         }
  51.  
  52.         return $ret;
  53.     }
  54.     // }}}
  55.  
  56.     // {{{ perform()
  57.     /**
  58.      *  @access public
  59.      *  @todo   deal with the package including some plugins.
  60.      */
  61.     function perform()
  62.     {
  63.         $args =& $this->_parseArgList();
  64.         if (Ethna::isError($args)) {
  65.             return $args;
  66.         }
  67.  
  68.         $pear =& new Ethna_PearWrapper();
  69.         if (isset($args['pearopt'])) {
  70.             $pear->setPearOpt($args['pearopt']);
  71.         }
  72.  
  73.         if (isset($args['type']) && isset($args['name'])) {
  74.             // install from repository.
  75.             $target = isset($args['target']) ? $args['target'] : null;
  76.             $channel = isset($args['channel']) ? $args['channel'] : null;
  77.             $basedir = isset($args['basedir']) ? realpath($args['basedir']) : getcwd();
  78.             if ($target == 'master') {
  79.                 $pkg_name = sprintf('Ethna_Plugin_%s_%s', $args['type'], $args['name']);
  80.             } else {
  81.                 $pkg_name = sprintf('App_Plugin_%s_%s', $args['type'], $args['name']);
  82.             }
  83.  
  84.             $r =& $pear->init($target, $basedir, $channel);
  85.             if (Ethna::isError($r)) {
  86.                 return $r;
  87.             }
  88.             $pkg_name = $pear->getCanonicalPackageName($pkg_name);
  89.             if (Ethna::isError($pkg_name)) {
  90.                 return $pkg_name;
  91.             }
  92.             $r =& $pear->doUninstall($pkg_name);
  93.             if (Ethna::isError($r)) {
  94.                 return $r;
  95.             }
  96.  
  97.         } else {
  98.             return Ethna::raiseError('invalid number of arguments', 'usage');
  99.         }
  100.  
  101.         if ($target != 'master') {
  102.             list(,, $ctype, $cname) = explode('_', $pkg_name, 4);
  103.             $r = Ethna_Generator::remove('Plugin', $basedir, $ctype, $cname);
  104.             if (Ethna::isError($r)) {
  105.                 return $r;
  106.             }
  107.         }
  108.  
  109.         return true;
  110.     }
  111.     // }}}
  112.  
  113.     // {{{ getDescription()
  114.     /**
  115.      *  @access public
  116.      */
  117.     function getDescription()
  118.     {
  119.         return <<<EOS
  120. uninstall plugin:
  121.     {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [type name]
  122.  
  123. EOS;
  124.     }
  125.     // }}}
  126.  
  127.     // {{{
  128.     /**
  129.      *  @access public
  130.      */
  131.     function getUsage()
  132.     {
  133.         return <<<EOS
  134. ethna {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [type name]
  135. EOS;
  136.     }
  137.     // }}}
  138. }
  139. // }}}
  140. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:33 +0900 by phpDocumentor 1.4.3