PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Cfg.php

Documentation is available at Cfg.php

  1. <?php
  2. /**
  3.  * PEAR_Installer_Role_Cfg
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * @category   pear
  8.  * @package    PEAR
  9.  * @author     Greg Beaver <cellog@php.net>
  10.  * @copyright  2007-2009 The Authors
  11.  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
  12.  * @version    CVS: $Id: Cfg.php 313023 2011-07-06 19:17:11Z dufuz $
  13.  * @link       http://pear.php.net/package/PEAR
  14.  * @since      File available since Release 1.7.0
  15.  */
  16.  
  17. /**
  18.  * @category   pear
  19.  * @package    PEAR
  20.  * @author     Greg Beaver <cellog@php.net>
  21.  * @copyright  2007-2009 The Authors
  22.  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
  23.  * @version    Release: 1.9.4
  24.  * @link       http://pear.php.net/package/PEAR
  25.  * @since      Class available since Release 1.7.0
  26.  */
  27. {
  28.     /**
  29.      * @var PEAR_Installer 
  30.      */
  31.     var $installer;
  32.  
  33.     /**
  34.      * the md5 of the original file
  35.      *
  36.      * @var unknown_type 
  37.      */
  38.     var $md5 = null;
  39.  
  40.     /**
  41.      * Do any unusual setup here
  42.      * @param PEAR_Installer 
  43.      * @param PEAR_PackageFile_v2 
  44.      * @param array file attributes
  45.      * @param string file name
  46.      */
  47.     function setup(&$installer$pkg$atts$file)
  48.     {
  49.         $this->installer = &$installer;
  50.         $reg &$this->installer->config->getRegistry();
  51.         $package $reg->getPackage($pkg->getPackage()$pkg->getChannel());
  52.         if ($package{
  53.             $filelist $package->getFilelist();
  54.             if (isset($filelist[$file]&& isset($filelist[$file]['md5sum'])) {
  55.                 $this->md5 = $filelist[$file]['md5sum'];
  56.             }
  57.         }
  58.     }
  59.  
  60.     function processInstallation($pkg$atts$file$tmp_path$layer = null)
  61.     {
  62.         $test = parent::processInstallation($pkg$atts$file$tmp_path$layer);
  63.         if (@file_exists($test[2]&& @file_exists($test[3])) {
  64.             $md5 md5_file($test[2]);
  65.             // configuration has already been installed, check for mods
  66.             if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) {
  67.                 // configuration has been modified, so save our version as
  68.                 // configfile-version
  69.                 $old $test[2];
  70.                 $test[2.= '.new-' $pkg->getVersion();
  71.                 // backup original and re-install it
  72.                 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  73.                 $tmpcfg $this->config->get('temp_dir');
  74.                 $newloc System::mkdir(array('-p'$tmpcfg));
  75.                 if (!$newloc{
  76.                     // try temp_dir
  77.                     $newloc System::mktemp(array('-d'));
  78.                     if (!$newloc || PEAR::isError($newloc)) {
  79.                         PEAR::popErrorHandling();
  80.                         return PEAR::raiseError('Could not save existing configuration file '.
  81.                             $old ', unable to install.  Please set temp_dir ' .
  82.                             'configuration variable to a writeable location and try again');
  83.                     }
  84.                 else {
  85.                     $newloc $tmpcfg;
  86.                 }
  87.  
  88.                 $temp_file $newloc . DIRECTORY_SEPARATOR . uniqid('savefile');
  89.                 if (!@copy($old$temp_file)) {
  90.                     PEAR::popErrorHandling();
  91.                     return PEAR::raiseError('Could not save existing configuration file '.
  92.                         $old ', unable to install.  Please set temp_dir ' .
  93.                         'configuration variable to a writeable location and try again');
  94.                 }
  95.  
  96.                 PEAR::popErrorHandling();
  97.                 $this->installer->log(0"WARNING: configuration file $old is being installed as $test[2], you should manually merge in changes to the existing configuration file");
  98.                 $this->installer->addFileOperation('rename'array($temp_file$oldfalse));
  99.                 $this->installer->addFileOperation('delete'array($temp_file));
  100.             }
  101.         }
  102.  
  103.         return $test;
  104.     }
  105. }

Documentation generated on Wed, 06 Jul 2011 23:30:27 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.