Source for file Ethna_Plugin_Handle_UpgradePlugin.php

Documentation is available at Ethna_Plugin_Handle_UpgradePlugin.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Handle_UpgradePlugin.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_UpgradePlugin
  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''state=',
  30.                                    'basedir=''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.         if (isset($opt_list['state'])) {
  46.             $ret['state'end($opt_list['state']);
  47.         }
  48.  
  49.         // arguments
  50.         if (count($arg_list== 2{
  51.             $ret['type'$arg_list[0];
  52.             $ret['name'$arg_list[1];
  53.         else if (count($arg_list== 1{
  54.             $ret['pkg_file_or_url'$arg_list[0];
  55.         }
  56.  
  57.         return $ret;
  58.     }
  59.     // }}}
  60.  
  61.     // {{{ perform()
  62.     /**
  63.      *  @access public
  64.      *  @todo   deal with the package including some plugins.
  65.      */
  66.     function perform()
  67.     {
  68.         $args =$this->_parseArgList();
  69.         if (Ethna::isError($args)) {
  70.             return $args;
  71.         }
  72.  
  73.         $pear =new Ethna_PearWrapper();
  74.         if (isset($args['pearopt'])) {
  75.             $pear->setPearOpt($args['pearopt']);
  76.         }
  77.  
  78.         if (isset($args['pkg_file_or_url'])) {
  79.             // install from local tgz.
  80.             $pkg_file_or_url $args['pkg_file_or_url'];
  81.             $pkg_name =Ethna_PearWrapper::getPackageNameFromTgz($pkg_file_or_url);
  82.             if (Ethna::isError($pkg_name)) {
  83.                 return $pkg_name;
  84.             }
  85.             list($appid,, $ctype$cnameexplode('_'$pkg_name4);
  86.             $target $appid == 'Ethna' 'master' 'local';
  87.             $channel = isset($args['channel']$args['channel'null;
  88.             $basedir = isset($args['basedir']realpath($args['basedir']getcwd();
  89.  
  90.             $r =$pear->init($target$basedir$channel);
  91.             if (Ethna::isError($r)) {
  92.                 return $r;
  93.             }
  94.             $r =$pear->doUpgradeFromTgz($pkg_file_or_url$pkg_name);
  95.             if (Ethna::isError($r)) {
  96.                 return $r;
  97.             }
  98.  
  99.         else if (isset($args['type']&& isset($args['name'])) {
  100.             // install from repository.
  101.             $target = isset($args['target']$args['target'null;
  102.             $channel = isset($args['channel']$args['channel'null;
  103.             $basedir = isset($args['basedir']realpath($args['basedir']getcwd();
  104.             $state = isset($args['state']$args['state'null;
  105.             if ($target == 'master'{
  106.                 $pkg_name sprintf('Ethna_Plugin_%s_%s'$args['type']$args['name']);
  107.             else {
  108.                 $pkg_name sprintf('App_Plugin_%s_%s'$args['type']$args['name']);
  109.             }
  110.  
  111.             $r =$pear->init($target$basedir$channel);
  112.             if (Ethna::isError($r)) {
  113.                 return $r;
  114.             }
  115.             $r =$pear->doUpgrade($pkg_name$state);
  116.             if (Ethna::isError($r)) {
  117.                 return $r;
  118.             }
  119.  
  120.             $pkg_name $pear->getCanonicalPackageName($pkg_name);
  121.             if (Ethna::isError($pkg_name)) {
  122.                 return $pkg_name;
  123.             }
  124.  
  125.         else {
  126.             return Ethna::raiseError('invalid number of arguments''usage');
  127.         }
  128.  
  129.         if ($target != 'master'{
  130.             list(,, $ctype$cnameexplode('_'$pkg_name4);
  131.             $r Ethna_Generator::generate('Plugin'$basedir$ctype$cnametrue);
  132.             if (Ethna::isError($r)) {
  133.                 return $r;
  134.             }
  135.         }
  136.  
  137.         return true;
  138.     }
  139.     // }}}
  140.  
  141.     // {{{ getDescription()
  142.     /**
  143.      *  @access public
  144.      */
  145.     function getDescription()
  146.     {
  147.         return <<<EOS
  148. upgrade plugin:
  149.     {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [type name|packagefile|packageurl]
  150.  
  151. EOS;
  152.     }
  153.     // }}}
  154.  
  155.     // {{{
  156.     /**
  157.      *  @access public
  158.      */
  159.     function getUsage()
  160.     {
  161.         return <<<EOS
  162. ethna {$this->id} [-c|--channel=channel] [-b|--basedir=dir] [-l|--local] [-m|--master] [type name|packagefile|packageurl]
  163. EOS;
  164.     }
  165.     // }}}
  166. }
  167. // }}}
  168. ?>

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