source: branches/version-2_13-dev/data/module/PEAR/Installer/Role/Cfg.php @ 23125

Revision 23125, 3.9 KB checked in by kimoto, 11 years ago (diff)

#2275 PEAR更新
不要なrequire_onceの削除
レガシーなPEARモジュールは使わない
SearchReplace?.phpのパスが間違っているので修正

Line 
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 */
27class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
28{
29    /**
30     * @var PEAR_Installer
31     */
32    var $installer;
33
34    /**
35     * the md5 of the original file
36     *
37     * @var unknown_type
38     */
39    var $md5 = null;
40
41    /**
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
47     */
48    function setup(&$installer, $pkg, $atts, $file)
49    {
50        $this->installer = &$installer;
51        $reg = &$this->installer->config->getRegistry();
52        $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
53        if ($package) {
54            $filelist = $package->getFilelist();
55            if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
56                $this->md5 = $filelist[$file]['md5sum'];
57            }
58        }
59    }
60
61    function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
62    {
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
69                // configfile-version
70                $old = $test[2];
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));
76                if (!$newloc) {
77                    // try temp_dir
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');
84                    }
85                } else {
86                    $newloc = $tmpcfg;
87                }
88
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');
95                }
96
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));
101            }
102        }
103
104        return $test;
105    }
106}
Note: See TracBrowser for help on using the repository browser.