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 * @link http://pear.php.net/package/PEAR
13 * @since File available since Release 1.7.0
19 * @author Greg Beaver <cellog@php.net>
20 * @copyright 2007-2009 The Authors
21 * @license http://opensource.org/licenses/bsd-license.php New BSD License
22 * @version Release: 1.10.1
23 * @link http://pear.php.net/package/PEAR
24 * @since Class available since Release 1.7.0
26 class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
34 * the md5 of the original file
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
47 function setup(&$installer, $pkg, $atts, $file)
49 $this->installer = &$installer;
50 $reg = &$this->installer->config->getRegistry();
51 $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
53 $filelist = $package->getFilelist();
54 if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
55 $this->md5 = $filelist[$file]['md5sum'];
60 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
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
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));
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');
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');
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, $old, false));
99 $this->installer->addFileOperation('delete', array($temp_file));