Subversion Repositories Applications.gtt

Rev

Rev 187 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
187 mathias 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
 * @link       http://pear.php.net/package/PEAR
13
 * @since      File available since Release 1.7.0
14
 */
15
 
16
/**
17
 * @category   pear
18
 * @package    PEAR
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
25
 */
26
class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
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, $old, false));
99
                $this->installer->addFileOperation('delete', array($temp_file));
100
            }
101
        }
102
 
103
        return $test;
104
    }
105
}