home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / tmp / PEAR-1.7.1 / PEAR / Installer / Role / Cfg.php next >
Encoding:
PHP Script  |  2008-02-15  |  3.6 KB  |  90 lines

  1. <?php
  2. /**
  3.  * PEAR_Installer_Role_Cfg
  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     Greg Beaver <cellog@php.net>
  16.  * @copyright  2007-2008 The PHP Group
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: Cfg.php,v 1.4 2008/01/03 20:26:36 cellog Exp $
  19.  * @link       http://pear.php.net/package/PEAR
  20.  * @since      File available since Release 1.7.0
  21.  */
  22.  
  23. /**
  24.  * @category   pear
  25.  * @package    PEAR
  26.  * @author     Greg Beaver <cellog@php.net>
  27.  * @copyright  2007-2008 The PHP Group
  28.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  29.  * @version    Release: 1.7.1
  30.  * @link       http://pear.php.net/package/PEAR
  31.  * @since      Class available since Release 1.7.0
  32.  */
  33. class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
  34. {
  35.     var $installer;
  36.     /**
  37.      * Do any unusual setup here
  38.      * @param PEAR_Installer
  39.      * @param PEAR_PackageFile_v2
  40.      * @param array file attributes
  41.      * @param string file name
  42.      */
  43.     function setup(&$installer, $pkg, $atts, $file)
  44.     {
  45.         $this->installer = &$installer;
  46.     }
  47.  
  48.     function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
  49.     {
  50.         $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
  51.         if (@file_exists($test[2])) {
  52.             // configuration has already been installed, check for mods
  53.             if (md5_file($test[2]) !== md5_file($test[3])) {
  54.                 // configuration has been modified, so save our version as
  55.                 // configfile-version
  56.                 $old = $test[2];
  57.                 $test[2] .= '.new-' . $pkg->getVersion();
  58.                 // backup original and re-install it
  59.                 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  60.                 $tmpcfg = $this->config->get('temp_dir');
  61.                 $newloc = System::mkdir(array('-p', $tmpcfg));
  62.                 if (!$newloc) {
  63.                     // try temp_dir 
  64.                     $newloc = System::mktemp(array('-d'));
  65.                     if (!$newloc || PEAR::isError($newloc)) {
  66.                         PEAR::popErrorHandling();
  67.                         return PEAR::raiseError('Could not save existing configuration file '.
  68.                             $old . ', unable to install.  Please set temp_dir ' .
  69.                             'configuration variable to a writeable location and try again');
  70.                     }
  71.                 } else {
  72.                     $newloc = $tmpcfg;
  73.                 }
  74.                 if (!@copy($old, $newloc . DIRECTORY_SEPARATOR . 'savefile')) {
  75.                     PEAR::popErrorHandling();
  76.                     return PEAR::raiseError('Could not save existing configuration file '.
  77.                         $old . ', unable to install.  Please set temp_dir ' .
  78.                         'configuration variable to a writeable location and try again');
  79.                 }
  80.                 PEAR::popErrorHandling();
  81.                 $this->installer->addFileOperation('rename',
  82.                     array($newloc . DIRECTORY_SEPARATOR . 'savefile', $old, false
  83.                 ));
  84.                 $this->installer->addFileOperation('delete', array($newloc . DIRECTORY_SEPARATOR . 'savefile'));
  85.             }
  86.         }
  87.         return $test;
  88.     }
  89. }
  90. ?>