[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/pear/PEAR/Command/ -> Install.php (source)

   1  <?php
   2  /**
   3   * PEAR_Command_Install (install, upgrade, upgrade-all, uninstall, bundle, run-scripts commands)
   4   *
   5   * PHP versions 4 and 5
   6   *
   7   * LICENSE: This source file is subject to version 3.0 of the PHP license
   8   * that is available through the world-wide-web at the following URI:
   9   * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10   * the PHP License and are unable to obtain it through the web, please
  11   * send a note to license@php.net so we can mail you a copy immediately.
  12   *
  13   * @category   pear
  14   * @package    PEAR
  15   * @author     Stig Bakken <ssb@php.net>
  16   * @author     Greg Beaver <cellog@php.net>
  17   * @copyright  1997-2006 The PHP Group
  18   * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19   * @version    CVS: $Id: Install.php,v 1.115 2006/03/02 18:14:13 cellog Exp $
  20   * @link       http://pear.php.net/package/PEAR
  21   * @since      File available since Release 0.1
  22   */
  23  
  24  /**
  25   * base class
  26   */
  27  require_once 'PEAR/Command/Common.php';
  28  
  29  /**
  30   * PEAR commands for installation or deinstallation/upgrading of
  31   * packages.
  32   *
  33   * @category   pear
  34   * @package    PEAR
  35   * @author     Stig Bakken <ssb@php.net>
  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 0.1
  42   */
  43  class PEAR_Command_Install extends PEAR_Command_Common
  44  {
  45      // {{{ properties
  46  
  47      var $commands = array(
  48          'install' => array(
  49              'summary' => 'Install Package',
  50              'function' => 'doInstall',
  51              'shortcut' => 'i',
  52              'options' => array(
  53                  'force' => array(
  54                      'shortopt' => 'f',
  55                      'doc' => 'will overwrite newer installed packages',
  56                      ),
  57                  'loose' => array(
  58                      'shortopt' => 'l',
  59                      'doc' => 'do not check for recommended dependency version',
  60                      ),
  61                  'nodeps' => array(
  62                      'shortopt' => 'n',
  63                      'doc' => 'ignore dependencies, install anyway',
  64                      ),
  65                  'register-only' => array(
  66                      'shortopt' => 'r',
  67                      'doc' => 'do not install files, only register the package as installed',
  68                      ),
  69                  'soft' => array(
  70                      'shortopt' => 's',
  71                      'doc' => 'soft install, fail silently, or upgrade if already installed',
  72                      ),
  73                  'nobuild' => array(
  74                      'shortopt' => 'B',
  75                      'doc' => 'don\'t build C extensions',
  76                      ),
  77                  'nocompress' => array(
  78                      'shortopt' => 'Z',
  79                      'doc' => 'request uncompressed files when downloading',
  80                      ),
  81                  'installroot' => array(
  82                      'shortopt' => 'R',
  83                      'arg' => 'DIR',
  84                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
  85                      ),
  86                  'packagingroot' => array(
  87                      'shortopt' => 'P',
  88                      'arg' => 'DIR',
  89                      'doc' => 'root directory used when packaging files, like RPM packaging',
  90                      ),
  91                  'ignore-errors' => array(
  92                      'doc' => 'force install even if there were errors',
  93                      ),
  94                  'alldeps' => array(
  95                      'shortopt' => 'a',
  96                      'doc' => 'install all required and optional dependencies',
  97                      ),
  98                  'onlyreqdeps' => array(
  99                      'shortopt' => 'o',
 100                      'doc' => 'install all required dependencies',
 101                      ),
 102                  'offline' => array(
 103                      'shortopt' => 'O',
 104                      'doc' => 'do not attempt to download any urls or contact channels',
 105                      ),
 106                  'pretend' => array(
 107                      'shortopt' => 'p',
 108                      'doc' => 'Only list the packages that would be downloaded',
 109                      ),
 110                  ),
 111              'doc' => '[channel/]<package> ...
 112  Installs one or more PEAR packages.  You can specify a package to
 113  install in four ways:
 114  
 115  "Package-1.0.tgz" : installs from a local file
 116  
 117  "http://example.com/Package-1.0.tgz" : installs from
 118  anywhere on the net.
 119  
 120  "package.xml" : installs the package described in
 121  package.xml.  Useful for testing, or for wrapping a PEAR package in
 122  another package manager such as RPM.
 123  
 124  "Package[-version/state][.tar]" : queries your default channel\'s server
 125  ({config master_server}) and downloads the newest package with
 126  the preferred quality/state ({config preferred_state}).
 127  
 128  To retrieve Package version 1.1, use "Package-1.1," to retrieve
 129  Package state beta, use "Package-beta."  To retrieve an uncompressed
 130  file, append .tar (make sure there is no file by the same name first)
 131  
 132  To download a package from another channel, prefix with the channel name like
 133  "channel/Package"
 134  
 135  More than one package may be specified at once.  It is ok to mix these
 136  four ways of specifying packages.
 137  '),
 138          'upgrade' => array(
 139              'summary' => 'Upgrade Package',
 140              'function' => 'doInstall',
 141              'shortcut' => 'up',
 142              'options' => array(
 143                  'force' => array(
 144                      'shortopt' => 'f',
 145                      'doc' => 'overwrite newer installed packages',
 146                      ),
 147                  'loose' => array(
 148                      'shortopt' => 'l',
 149                      'doc' => 'do not check for recommended dependency version',
 150                      ),
 151                  'nodeps' => array(
 152                      'shortopt' => 'n',
 153                      'doc' => 'ignore dependencies, upgrade anyway',
 154                      ),
 155                  'register-only' => array(
 156                      'shortopt' => 'r',
 157                      'doc' => 'do not install files, only register the package as upgraded',
 158                      ),
 159                  'nobuild' => array(
 160                      'shortopt' => 'B',
 161                      'doc' => 'don\'t build C extensions',
 162                      ),
 163                  'nocompress' => array(
 164                      'shortopt' => 'Z',
 165                      'doc' => 'request uncompressed files when downloading',
 166                      ),
 167                  'installroot' => array(
 168                      'shortopt' => 'R',
 169                      'arg' => 'DIR',
 170                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
 171                      ),
 172                  'packagingroot' => array(
 173                      'shortopt' => 'P',
 174                      'arg' => 'DIR',
 175                      'doc' => 'root directory used when packaging files, like RPM packaging',
 176                      ),
 177                  'ignore-errors' => array(
 178                      'doc' => 'force install even if there were errors',
 179                      ),
 180                  'alldeps' => array(
 181                      'shortopt' => 'a',
 182                      'doc' => 'install all required and optional dependencies',
 183                      ),
 184                  'onlyreqdeps' => array(
 185                      'shortopt' => 'o',
 186                      'doc' => 'install all required dependencies',
 187                      ),
 188                  'offline' => array(
 189                      'shortopt' => 'O',
 190                      'doc' => 'do not attempt to download any urls or contact channels',
 191                      ),
 192                  'pretend' => array(
 193                      'shortopt' => 'p',
 194                      'doc' => 'Only list the packages that would be downloaded',
 195                      ),
 196                  ),
 197              'doc' => '<package> ...
 198  Upgrades one or more PEAR packages.  See documentation for the
 199  "install" command for ways to specify a package.
 200  
 201  When upgrading, your package will be updated if the provided new
 202  package has a higher version number (use the -f option if you need to
 203  upgrade anyway).
 204  
 205  More than one package may be specified at once.
 206  '),
 207          'upgrade-all' => array(
 208              'summary' => 'Upgrade All Packages',
 209              'function' => 'doInstall',
 210              'shortcut' => 'ua',
 211              'options' => array(
 212                  'nodeps' => array(
 213                      'shortopt' => 'n',
 214                      'doc' => 'ignore dependencies, upgrade anyway',
 215                      ),
 216                  'register-only' => array(
 217                      'shortopt' => 'r',
 218                      'doc' => 'do not install files, only register the package as upgraded',
 219                      ),
 220                  'nobuild' => array(
 221                      'shortopt' => 'B',
 222                      'doc' => 'don\'t build C extensions',
 223                      ),
 224                  'nocompress' => array(
 225                      'shortopt' => 'Z',
 226                      'doc' => 'request uncompressed files when downloading',
 227                      ),
 228                  'installroot' => array(
 229                      'shortopt' => 'R',
 230                      'arg' => 'DIR',
 231                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
 232                      ),
 233                  'ignore-errors' => array(
 234                      'doc' => 'force install even if there were errors',
 235                      ),
 236                  'loose' => array(
 237                      'doc' => 'do not check for recommended dependency version',
 238                      ),
 239                  ),
 240              'doc' => '
 241  Upgrades all packages that have a newer release available.  Upgrades are
 242  done only if there is a release available of the state specified in
 243  "preferred_state" (currently {config preferred_state}), or a state considered
 244  more stable.
 245  '),
 246          'uninstall' => array(
 247              'summary' => 'Un-install Package',
 248              'function' => 'doUninstall',
 249              'shortcut' => 'un',
 250              'options' => array(
 251                  'nodeps' => array(
 252                      'shortopt' => 'n',
 253                      'doc' => 'ignore dependencies, uninstall anyway',
 254                      ),
 255                  'register-only' => array(
 256                      'shortopt' => 'r',
 257                      'doc' => 'do not remove files, only register the packages as not installed',
 258                      ),
 259                  'installroot' => array(
 260                      'shortopt' => 'R',
 261                      'arg' => 'DIR',
 262                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
 263                      ),
 264                  'ignore-errors' => array(
 265                      'doc' => 'force install even if there were errors',
 266                      ),
 267                  'offline' => array(
 268                      'shortopt' => 'O',
 269                      'doc' => 'do not attempt to uninstall remotely',
 270                      ),
 271                  ),
 272              'doc' => '[channel/]<package> ...
 273  Uninstalls one or more PEAR packages.  More than one package may be
 274  specified at once.  Prefix with channel name to uninstall from a
 275  channel not in your default channel ({config default_channel})
 276  '),
 277          'bundle' => array(
 278              'summary' => 'Unpacks a Pecl Package',
 279              'function' => 'doBundle',
 280              'shortcut' => 'bun',
 281              'options' => array(
 282                  'destination' => array(
 283                     'shortopt' => 'd',
 284                      'arg' => 'DIR',
 285                      'doc' => 'Optional destination directory for unpacking (defaults to current path or "ext" if exists)',
 286                      ),
 287                  'force' => array(
 288                      'shortopt' => 'f',
 289                      'doc' => 'Force the unpacking even if there were errors in the package',
 290                  ),
 291              ),
 292              'doc' => '<package>
 293  Unpacks a Pecl Package into the selected location. It will download the
 294  package if needed.
 295  '),
 296          'run-scripts' => array(
 297              'summary' => 'Run Post-Install Scripts bundled with a package',
 298              'function' => 'doRunScripts',
 299              'shortcut' => 'rs',
 300              'options' => array(
 301              ),
 302              'doc' => '<package>
 303  Run post-installation scripts in package <package>, if any exist.
 304  '),
 305      );
 306  
 307      // }}}
 308      // {{{ constructor
 309  
 310      /**
 311       * PEAR_Command_Install constructor.
 312       *
 313       * @access public
 314       */
 315      function PEAR_Command_Install(&$ui, &$config)
 316      {
 317          parent::PEAR_Command_Common($ui, $config);
 318      }
 319  
 320      // }}}
 321  
 322      /**
 323       * For unit testing purposes
 324       */
 325      function &getDownloader(&$ui, $options, &$config)
 326      {
 327          if (!class_exists('PEAR_Downloader')) {
 328              require_once 'PEAR/Downloader.php';
 329          }
 330          $a = &new PEAR_Downloader($ui, $options, $config);
 331          return $a;
 332      }
 333  
 334      /**
 335       * For unit testing purposes
 336       */
 337      function &getInstaller(&$ui)
 338      {
 339          if (!class_exists('PEAR_Installer')) {
 340              require_once 'PEAR/Installer.php';
 341          }
 342          $a = &new PEAR_Installer($ui);
 343          return $a;
 344      }
 345  
 346      // {{{ doInstall()
 347  
 348      function doInstall($command, $options, $params)
 349      {
 350          if (empty($this->installer)) {
 351              $this->installer = &$this->getInstaller($this->ui);
 352          }
 353          if ($command == 'upgrade') {
 354              $options['upgrade'] = true;
 355          }
 356          if (isset($options['installroot']) && isset($options['packagingroot'])) {
 357              return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
 358          }
 359          if (isset($options['packagingroot']) && $this->config->get('verbose') > 2) {
 360              $this->ui->outputData('using package root: ' . $options['packagingroot']);
 361          }
 362          $reg = &$this->config->getRegistry();
 363          if ($command == 'upgrade-all') {
 364              $options['upgrade'] = true;
 365              $reg = &$this->config->getRegistry();
 366              $savechannel = $this->config->get('default_channel');
 367              $params = array();
 368              foreach ($reg->listChannels() as $channel) {
 369                  if ($channel == '__uri') {
 370                      continue;
 371                  }
 372                  $this->config->set('default_channel', $channel);
 373                  $chan = &$reg->getChannel($channel);
 374                  if (PEAR::isError($chan)) {
 375                      return $this->raiseError($chan);
 376                  }
 377                  if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
 378                        $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
 379                      $dorest = true;
 380                      unset($remote);
 381                  } else {
 382                      $dorest = false;
 383                      $remote = &$this->config->getRemote($this->config);
 384                  }
 385                  $state = $this->config->get('preferred_state');
 386                  $installed = array_flip($reg->listPackages($channel));
 387                  PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 388                  if ($dorest) {
 389                      $rest = &$this->config->getREST('1.0', array());
 390                      $latest = $rest->listLatestUpgrades($base, $state, $installed, $channel, $reg);
 391                  } else {
 392                      if (empty($state) || $state == 'any') {
 393                          $latest = $remote->call("package.listLatestReleases");
 394                      } else {
 395                          $latest = $remote->call("package.listLatestReleases", $state);
 396                      }
 397                  }
 398                  PEAR::staticPopErrorHandling();
 399                  if (PEAR::isError($latest) || !is_array($latest)) {
 400                      continue;
 401                  }
 402                  foreach ($latest as $package => $info) {
 403                      $package = strtolower($package);
 404                      if (!isset($installed[$package])) {
 405                          // skip packages we don't have installed
 406                          continue;
 407                      }
 408                      $inst_version = $reg->packageInfo($package, 'version', $channel);
 409                      if (version_compare("$info[version]", "$inst_version", "le")) {
 410                          // installed version is up-to-date
 411                          continue;
 412                      }
 413                      $params[] = $reg->parsedPackageNameToString(array('package' => $package,
 414                          'channel' => $channel));
 415                      $this->ui->outputData(array('data' => "Will upgrade $package"), $command);
 416                  }
 417              }
 418              $this->config->set('default_channel', $savechannel);
 419          }
 420          $this->downloader = &$this->getDownloader($this->ui, $options, $this->config);
 421          $errors = array();
 422          $downloaded = array();
 423          $downloaded = &$this->downloader->download($params);
 424          $errors = $this->downloader->getErrorMsgs();
 425          if (count($errors)) {
 426              foreach ($errors as $error) {
 427                  $err['data'][] = array($error);
 428              }
 429              $err['headline'] = 'Install Errors';
 430              $this->ui->outputData($err);
 431              if (!count($downloaded)) {
 432                  return $this->raiseError("$command failed");
 433              }
 434          }
 435          $data = array(
 436              'headline' => 'Packages that would be Installed'
 437          );
 438          if (isset($options['pretend'])) {
 439              foreach ($downloaded as $package) {
 440                  $data['data'][] = array($reg->parsedPackageNameToString($package->getParsedPackage()));
 441              }
 442              $this->ui->outputData($data, 'pretend');
 443              return true;
 444          }
 445          $this->installer->setOptions($options);
 446          $this->installer->sortPackagesForInstall($downloaded);
 447          if (PEAR::isError($err = $this->installer->setDownloadedPackages($downloaded))) {
 448              $this->raiseError($err->getMessage());
 449              return true;
 450          }
 451          $extrainfo = array();
 452          foreach ($downloaded as $param) {
 453              PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 454              $info = $this->installer->install($param, $options);
 455              PEAR::staticPopErrorHandling();
 456              if (PEAR::isError($info)) {
 457                  $oldinfo = $info;
 458                  $pkg = &$param->getPackageFile();
 459                  if ($info->getCode() != PEAR_INSTALLER_NOBINARY) {
 460                      if (!($info = $pkg->installBinary($this->installer))) {
 461                          $this->ui->outputData('ERROR: ' .$oldinfo->getMessage());
 462                          continue;
 463                      }
 464                      // we just installed a different package than requested,
 465                      // let's change the param and info so that the rest of this works
 466                      $param = $info[0];
 467                      $info = $info[1];
 468                  }
 469              }
 470              if (is_array($info)) {
 471                  if ($param->getPackageType() == 'extsrc' ||
 472                        $param->getPackageType() == 'extbin') {
 473                      $pkg = &$param->getPackageFile();
 474                      if ($instbin = $pkg->getInstalledBinary()) {
 475                          $instpkg = &$reg->getPackage($instbin, $pkg->getChannel());
 476                      } else {
 477                          $instpkg = &$reg->getPackage($pkg->getPackage(), $pkg->getChannel());
 478                      }
 479                      foreach ($instpkg->getFilelist() as $name => $atts) {
 480                          $pinfo = pathinfo($atts['installed_as']);
 481                          if (!isset($pinfo['extension']) ||
 482                                in_array($pinfo['extension'], array('c', 'h'))) {
 483                              continue; // make sure we don't match php_blah.h
 484                          }
 485                          if ((strpos($pinfo['basename'], 'php_') === 0 &&
 486                                $pinfo['extension'] == 'dll') ||
 487                                // most unices
 488                                $pinfo['extension'] == 'so' ||
 489                                // hp-ux
 490                                $pinfo['extension'] == 'sl') {
 491                              $extrainfo[] = 'You should add "extension=' . $pinfo['basename']
 492                                  . '" to php.ini';
 493                              break;
 494                          }
 495                      }
 496                  }
 497                  if ($this->config->get('verbose') > 0) {
 498                      $channel = $param->getChannel();
 499                      $label = $reg->parsedPackageNameToString(
 500                          array(
 501                              'channel' => $channel,
 502                              'package' => $param->getPackage(),
 503                              'version' => $param->getVersion(),
 504                          ));
 505                      $out = array('data' => "$command ok: $label");
 506                      if (isset($info['release_warnings'])) {
 507                          $out['release_warnings'] = $info['release_warnings'];
 508                      }
 509                      $this->ui->outputData($out, $command);
 510                      if (!isset($options['register-only']) && !isset($options['offline'])) {
 511                          if ($this->config->isDefinedLayer('ftp')) {
 512                              PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 513                              $info = $this->installer->ftpInstall($param);
 514                              PEAR::staticPopErrorHandling();
 515                              if (PEAR::isError($info)) {
 516                                  $this->ui->outputData($info->getMessage());
 517                                  $this->ui->outputData("remote install failed: $label");
 518                              } else {
 519                                  $this->ui->outputData("remote install ok: $label");
 520                              }
 521                          }
 522                      }
 523                  }
 524                  $deps = $param->getDeps();
 525                  if ($deps) {
 526                      if (isset($deps['group'])) {
 527                          $groups = $deps['group'];
 528                          if (!isset($groups[0])) {
 529                              $groups = array($groups);
 530                          }
 531                          foreach ($groups as $group) {
 532                              if ($group['attribs']['name'] == 'default') {
 533                                  // default group is always installed, unless the user
 534                                  // explicitly chooses to install another group
 535                                  continue;
 536                              }
 537                              $this->ui->outputData($param->getPackage() . ': Optional feature ' .
 538                                  $group['attribs']['name'] . ' available (' .
 539                                  $group['attribs']['hint'] . ')');
 540                          }
 541                          $extrainfo[] = 'To install use "pear install ' .
 542                              $reg->parsedPackageNameToString(
 543                                  array('package' => $param->getPackage(),
 544                                        'channel' => $param->getChannel()), true) .
 545                                    '#featurename"';
 546                      }
 547                  }
 548                  if (isset($options['installroot'])) {
 549                      $reg = &$this->config->getRegistry();
 550                  }
 551                  $pkg = &$reg->getPackage($param->getPackage(), $param->getChannel());
 552                  // $pkg may be NULL if install is a 'fake' install via --packagingroot
 553                  if (is_object($pkg)) {
 554                      $pkg->setConfig($this->config);
 555                      if ($list = $pkg->listPostinstallScripts()) {
 556                          $pn = $reg->parsedPackageNameToString(array('channel' =>
 557                             $param->getChannel(), 'package' => $param->getPackage()), true);
 558                          $extrainfo[] = $pn . ' has post-install scripts:';
 559                          foreach ($list as $file) {
 560                              $extrainfo[] = $file;
 561                          }
 562                          $extrainfo[] = 'Use "pear run-scripts ' . $pn . '" to run';
 563                          $extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES';
 564                      }
 565                  }
 566              } else {
 567                  return $this->raiseError("$command failed");
 568              }
 569          }
 570          if (count($extrainfo)) {
 571              foreach ($extrainfo as $info) {
 572                  $this->ui->outputData($info);
 573              }
 574          }
 575          return true;
 576      }
 577  
 578      // }}}
 579      // {{{ doUninstall()
 580  
 581      function doUninstall($command, $options, $params)
 582      {
 583          if (empty($this->installer)) {
 584              $this->installer = &$this->getInstaller($this->ui);
 585          }
 586          if (isset($options['remoteconfig'])) {
 587              $e = $this->config->readFTPConfigFile($options['remoteconfig']);
 588              if (!PEAR::isError($e)) {
 589                  $this->installer->setConfig($this->config);
 590              }
 591          }
 592          if (sizeof($params) < 1) {
 593              return $this->raiseError("Please supply the package(s) you want to uninstall");
 594          }
 595          $reg = &$this->config->getRegistry();
 596          $newparams = array();
 597          $badparams = array();
 598          foreach ($params as $pkg) {
 599              $channel = $this->config->get('default_channel');
 600              PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 601              $parsed = $reg->parsePackageName($pkg, $channel);
 602              PEAR::staticPopErrorHandling();
 603              if (!$parsed || PEAR::isError($parsed)) {
 604                  $badparams[] = $pkg;
 605                  continue;
 606              }
 607              $package = $parsed['package'];
 608              $channel = $parsed['channel'];
 609              $info = &$reg->getPackage($package, $channel);
 610              if ($info === null &&
 611                   ($channel == 'pear.php.net' || $channel == 'pecl.php.net')) {
 612                  // make sure this isn't a package that has flipped from pear to pecl but
 613                  // used a package.xml 1.0
 614                  $testc = ($channel == 'pear.php.net') ? 'pecl.php.net' : 'pear.php.net';
 615                  $info = &$reg->getPackage($package, $testc);
 616                  if ($info !== null) {
 617                      $channel = $testc;
 618                  }
 619              }
 620              if ($info === null) {
 621                  $badparams[] = $pkg;
 622              } else {
 623                  $newparams[] = &$info;
 624                  // check for binary packages (this is an alias for those packages if so)
 625                  if ($installedbinary = $info->getInstalledBinary()) {
 626                      $this->ui->log('adding binary package ' .
 627                          $reg->parsedPackageNameToString(array('channel' => $channel,
 628                              'package' => $installedbinary), true));
 629                      $newparams[] = &$reg->getPackage($installedbinary, $channel);
 630                  }
 631                  // add the contents of a dependency group to the list of installed packages
 632                  if (isset($parsed['group'])) {
 633                      $group = $info->getDependencyGroup($parsed['group']);
 634                      if ($group) {
 635                          $installed = &$reg->getInstalledGroup($group);
 636                          if ($installed) {
 637                              foreach ($installed as $i => $p) {
 638                                  $newparams[] = &$installed[$i];
 639                              }
 640                          }
 641                      }
 642                  }
 643              }
 644          }
 645          $err = $this->installer->sortPackagesForUninstall($newparams);
 646          if (PEAR::isError($err)) {
 647              $this->ui->outputData($err->getMessage(), $command);
 648              return true;
 649          }
 650          $params = $newparams;
 651          // twist this to use it to check on whether dependent packages are also being uninstalled
 652          // for circular dependencies like subpackages
 653          $this->installer->setUninstallPackages($newparams);
 654          $params = array_merge($params, $badparams);
 655          foreach ($params as $pkg) {
 656              $this->installer->pushErrorHandling(PEAR_ERROR_RETURN);
 657              if ($err = $this->installer->uninstall($pkg, $options)) {
 658                  $this->installer->popErrorHandling();
 659                  if (PEAR::isError($err)) {
 660                      $this->ui->outputData($err->getMessage(), $command);
 661                      continue;
 662                  }
 663                  $savepkg = $pkg;
 664                  if ($this->config->get('verbose') > 0) {
 665                      if (is_object($pkg)) {
 666                          $pkg = $reg->parsedPackageNameToString($pkg);
 667                      }
 668                      $this->ui->outputData("uninstall ok: $pkg", $command);
 669                  }
 670                  if (!isset($options['offline']) && is_object($savepkg) &&
 671                        defined('PEAR_REMOTEINSTALL_OK')) {
 672                      if ($this->config->isDefinedLayer('ftp')) {
 673                          $this->installer->pushErrorHandling(PEAR_ERROR_RETURN);
 674                          $info = $this->installer->ftpUninstall($savepkg);
 675                          $this->installer->popErrorHandling();
 676                          if (PEAR::isError($info)) {
 677                              $this->ui->outputData($info->getMessage());
 678                              $this->ui->outputData("remote uninstall failed: $pkg");
 679                          } else {
 680                              $this->ui->outputData("remote uninstall ok: $pkg");
 681                          }
 682                      }
 683                  }
 684              } else {
 685                  $this->installer->popErrorHandling();
 686                  if (is_object($pkg)) {
 687                      $pkg = $reg->parsedPackageNameToString($pkg);
 688                  }
 689                  return $this->raiseError("uninstall failed: $pkg");
 690              }
 691          }
 692          return true;
 693      }
 694  
 695      // }}}
 696  
 697  
 698      // }}}
 699      // {{{ doBundle()
 700      /*
 701      (cox) It just downloads and untars the package, does not do
 702              any check that the PEAR_Installer::_installFile() does.
 703      */
 704  
 705      function doBundle($command, $options, $params)
 706      {
 707          $downloader = &$this->getDownloader($this->ui, array('force' => true, 'nodeps' => true,
 708              'soft' => true), $this->config);
 709          $reg = &$this->config->getRegistry();
 710          if (sizeof($params) < 1) {
 711              return $this->raiseError("Please supply the package you want to bundle");
 712          }
 713  
 714          if (isset($options['destination'])) {
 715              if (!is_dir($options['destination'])) {
 716                  System::mkdir('-p ' . $options['destination']);
 717              }
 718              $dest = realpath($options['destination']);
 719          } else {
 720              $pwd = getcwd();
 721              if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
 722                  $dest = $pwd . DIRECTORY_SEPARATOR . 'ext';
 723              } else {
 724                  $dest = $pwd;
 725              }
 726          }
 727          $downloader->setDownloadDir($dest);
 728          $result = &$downloader->download(array($params[0]));
 729          if (PEAR::isError($result)) {
 730              return $result;
 731          }
 732          $pkgfile = &$result[0]->getPackageFile();
 733          $pkgname = $pkgfile->getName();
 734          $pkgversion = $pkgfile->getVersion();
 735  
 736          // Unpacking -------------------------------------------------
 737          $dest .= DIRECTORY_SEPARATOR . $pkgname;
 738          $orig = $pkgname . '-' . $pkgversion;
 739  
 740          $tar = &new Archive_Tar($pkgfile->getArchiveFile());
 741          if (!@$tar->extractModify($dest, $orig)) {
 742              return $this->raiseError('unable to unpack ' . $pkgfile->getArchiveFile());
 743          }
 744          $this->ui->outputData("Package ready at '$dest'");
 745      // }}}
 746      }
 747  
 748      // }}}
 749  
 750      function doRunScripts($command, $options, $params)
 751      {
 752          if (!isset($params[0])) {
 753              return $this->raiseError('run-scripts expects 1 parameter: a package name');
 754          }
 755          $reg = &$this->config->getRegistry();
 756          PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 757          $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
 758          PEAR::staticPopErrorHandling();
 759          if (PEAR::isError($parsed)) {
 760              return $this->raiseError($parsed);
 761          }
 762          $package = &$reg->getPackage($parsed['package'], $parsed['channel']);
 763          if (is_object($package)) {
 764              $package->setConfig($this->config);
 765              $package->runPostinstallScripts();
 766          } else {
 767              return $this->raiseError('Could not retrieve package "' . $params[0] . '" from registry');
 768          }
 769          $this->ui->outputData('Install scripts complete', $command);
 770          return true;
 771      }
 772  }
 773  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics