3 * PEAR_Installer_Role_Cfg
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
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
27 class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
35 * the md5 of the original file
42 * Do any unusual setup here
43 * @param PEAR_Installer
44 * @param PEAR_PackageFile_v2
45 * @param array file attributes
46 * @param string file name
48 function setup(&$installer, $pkg, $atts, $file)
50 $this->installer = &$installer;
51 $reg = &$this->installer->config->getRegistry();
52 $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
54 $filelist = $package->getFilelist();
55 if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
56 $this->md5 = $filelist[$file]['md5sum'];
61 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
63 $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
64 if (@file_exists($test[2]) && @file_exists($test[3])) {
65 $md5 = md5_file($test[2]);
66 // configuration has already been installed, check for mods
67 if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) {
68 // configuration has been modified, so save our version as
71 $test[2] .= '.new-' . $pkg->getVersion();
72 // backup original and re-install it
73 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
74 $tmpcfg = $this->config->get('temp_dir');
75 $newloc = System::mkdir(array('-p', $tmpcfg));
78 $newloc = System::mktemp(array('-d'));
79 if (!$newloc || PEAR::isError($newloc)) {
80 PEAR::popErrorHandling();
81 return PEAR::raiseError('Could not save existing configuration file '.
82 $old . ', unable to install. Please set temp_dir ' .
83 'configuration variable to a writeable location and try again');
89 $temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile');
90 if (!@copy($old, $temp_file)) {
91 PEAR::popErrorHandling();
92 return PEAR::raiseError('Could not save existing configuration file '.
93 $old . ', unable to install. Please set temp_dir ' .
94 'configuration variable to a writeable location and try again');
97 PEAR::popErrorHandling();
98 $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");
99 $this->installer->addFileOperation('rename', array($temp_file, $old, false));
100 $this->installer->addFileOperation('delete', array($temp_file));