Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * <tasks:postinstallscript>
3
 * <tasks:postinstallscript>
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
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
7
 * @category  pear
14
 * @package    PEAR
8
 * @package   PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author    Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright 1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license   http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: Postinstallscript.php,v 1.18 2006/02/08 01:21:47 cellog Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link      http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since     File available since Release 1.4.0a1
21
 */
14
 */
22
/**
15
/**
23
 * Base class
16
 * Base class
24
 */
17
 */
25
require_once 'PEAR/Task/Common.php';
18
require_once 'PEAR/Task/Common.php';
26
/**
19
/**
27
 * Implements the postinstallscript file task.
20
 * Implements the postinstallscript file task.
28
 *
21
 *
29
 * Note that post-install scripts are handled separately from installation, by the
22
 * Note that post-install scripts are handled separately from installation, by the
30
 * "pear run-scripts" command
23
 * "pear run-scripts" command
-
 
24
 *
31
 * @category   pear
25
 * @category  pear
32
 * @package    PEAR
26
 * @package   PEAR
33
 * @author     Greg Beaver <cellog@php.net>
27
 * @author    Greg Beaver <cellog@php.net>
34
 * @copyright  1997-2006 The PHP Group
28
 * @copyright 1997-2009 The Authors
35
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
29
 * @license   http://opensource.org/licenses/bsd-license.php New BSD License
36
 * @version    Release: 1.5.1
30
 * @version   Release: 1.10.1
37
 * @link       http://pear.php.net/package/PEAR
31
 * @link      http://pear.php.net/package/PEAR
38
 * @since      Class available since Release 1.4.0a1
32
 * @since     Class available since Release 1.4.0a1
39
 */
33
 */
40
class PEAR_Task_Postinstallscript extends PEAR_Task_Common
34
class PEAR_Task_Postinstallscript extends PEAR_Task_Common
41
{
35
{
42
    var $type = 'script';
36
    public $type = 'script';
43
    var $_class;
37
    public $_class;
44
    var $_params;
38
    public $_params;
45
    var $_obj;
39
    public $_obj;
46
    /**
40
    /**
47
     *
41
     *
48
     * @var PEAR_PackageFile_v2
42
     * @var PEAR_PackageFile_v2
49
     */
43
     */
50
    var $_pkg;
44
    public $_pkg;
51
    var $_contents;
45
    public $_contents;
52
    var $phase = PEAR_TASK_INSTALL;
46
    public $phase = PEAR_TASK_INSTALL;
Line 53... Line 47...
53
 
47
 
54
    /**
48
    /**
55
     * Validate the raw xml at parsing-time.
49
     * Validate the raw xml at parsing-time.
56
     *
50
     *
57
     * This also attempts to validate the script to make sure it meets the criteria
51
     * This also attempts to validate the script to make sure it meets the criteria
-
 
52
     * for a post-install script
58
     * for a post-install script
53
     *
59
     * @param PEAR_PackageFile_v2
54
     * @param  PEAR_PackageFile_v2
60
     * @param array The XML contents of the <postinstallscript> tag
55
     * @param  array The XML contents of the <postinstallscript> tag
61
     * @param PEAR_Config
56
     * @param  PEAR_Config
62
     * @param array the entire parsed <file> tag
-
 
63
     * @static
57
     * @param  array the entire parsed <file> tag
64
     */
58
     */
65
    function validateXml($pkg, $xml, &$config, $fileXml)
59
    public static function validateXml($pkg, $xml, $config, $fileXml)
66
    {
60
    {
67
        if ($fileXml['role'] != 'php') {
61
        if ($fileXml['role'] != 'php') {
68
            return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
62
            return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
69
            $fileXml['name'] . '" must be role="php"');
63
            $fileXml['name'].'" must be role="php"', );
70
        }
64
        }
71
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
65
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
72
        $file = $pkg->getFileContents($fileXml['name']);
66
        $file = $pkg->getFileContents($fileXml['name']);
73
        if (PEAR::isError($file)) {
67
        if (PEAR::isError($file)) {
-
 
68
            PEAR::popErrorHandling();
74
            PEAR::popErrorHandling();
69
 
75
            return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
70
            return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
76
                $fileXml['name'] . '" is not valid: ' .
71
                $fileXml['name'].'" is not valid: '.
77
                $file->getMessage());
72
                $file->getMessage(), );
78
        } elseif ($file === null) {
73
        } elseif ($file === null) {
79
            return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
74
            return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
80
                $fileXml['name'] . '" could not be retrieved for processing!');
75
                $fileXml['name'].'" could not be retrieved for processing!', );
81
        } else {
76
        } else {
82
            $analysis = $pkg->analyzeSourceCode($file, true);
77
            $analysis = $pkg->analyzeSourceCode($file, true);
83
            if (!$analysis) {
78
            if (!$analysis) {
84
                PEAR::popErrorHandling();
79
                PEAR::popErrorHandling();
85
                $warnings = '';
80
                $warnings = '';
86
                foreach ($pkg->getValidationWarnings() as $warn) {
81
                foreach ($pkg->getValidationWarnings() as $warn) {
87
                    $warnings .= $warn['message'] . "\n";
82
                    $warnings .= $warn['message']."\n";
-
 
83
                }
88
                }
84
 
89
                return array(PEAR_TASK_ERROR_INVALID, 'Analysis of post-install script "' .
85
                return array(PEAR_TASK_ERROR_INVALID, 'Analysis of post-install script "'.
90
                    $fileXml['name'] . '" failed: ' . $warnings);
86
                    $fileXml['name'].'" failed: '.$warnings, );
91
            }
87
            }
92
            if (count($analysis['declared_classes']) != 1) {
88
            if (count($analysis['declared_classes']) != 1) {
-
 
89
                PEAR::popErrorHandling();
93
                PEAR::popErrorHandling();
90
 
94
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
91
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
95
                    $fileXml['name'] . '" must declare exactly 1 class');
92
                    $fileXml['name'].'" must declare exactly 1 class', );
96
            }
93
            }
-
 
94
            $class = $analysis['declared_classes'][0];
97
            $class = $analysis['declared_classes'][0];
95
            if ($class != str_replace(
98
            if ($class != str_replace(array('/', '.php'), array('_', ''),
96
                array('/', '.php'), array('_', ''),
-
 
97
                $fileXml['name']
99
                  $fileXml['name']) . '_postinstall') {
98
            ).'_postinstall') {
-
 
99
                PEAR::popErrorHandling();
100
                PEAR::popErrorHandling();
100
 
101
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
101
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
-
 
102
                    $fileXml['name'].'" class "'.$class.'" must be named "'.
102
                    $fileXml['name'] . '" class "' . $class . '" must be named "' .
103
                    str_replace(
-
 
104
                        array('/', '.php'), array('_', ''),
103
                    str_replace(array('/', '.php'), array('_', ''),
105
                        $fileXml['name']
104
                    $fileXml['name']) . '_postinstall"');
106
                    ).'_postinstall"', );
105
            }
107
            }
106
            if (!isset($analysis['declared_methods'][$class])) {
108
            if (!isset($analysis['declared_methods'][$class])) {
-
 
109
                PEAR::popErrorHandling();
107
                PEAR::popErrorHandling();
110
 
108
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
111
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
109
                    $fileXml['name'] . '" must declare methods init() and run()');
112
                    $fileXml['name'].'" must declare methods init() and run()', );
110
            }
113
            }
111
            $methods = array('init' => 0, 'run' => 1);
114
            $methods = array('init' => 0, 'run' => 1);
112
            foreach ($analysis['declared_methods'][$class] as $method) {
115
            foreach ($analysis['declared_methods'][$class] as $method) {
113
                if (isset($methods[$method])) {
116
                if (isset($methods[$method])) {
114
                    unset($methods[$method]);
117
                    unset($methods[$method]);
115
                }
118
                }
116
            }
119
            }
117
            if (count($methods)) {
120
            if (count($methods)) {
-
 
121
                PEAR::popErrorHandling();
118
                PEAR::popErrorHandling();
122
 
119
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
123
                return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
120
                    $fileXml['name'] . '" must declare methods init() and run()');
124
                    $fileXml['name'].'" must declare methods init() and run()', );
121
            }
125
            }
122
        }
126
        }
123
        PEAR::popErrorHandling();
127
        PEAR::popErrorHandling();
124
        $definedparams = array();
128
        $definedparams = array();
125
        $tasksNamespace = $pkg->getTasksNs() . ':';
129
        $tasksNamespace = $pkg->getTasksNs().':';
126
        if (!isset($xml[$tasksNamespace . 'paramgroup']) && isset($xml['paramgroup'])) {
130
        if (!isset($xml[$tasksNamespace.'paramgroup']) && isset($xml['paramgroup'])) {
127
            // in order to support the older betas, which did not expect internal tags
131
            // in order to support the older betas, which did not expect internal tags
128
            // to also use the namespace
132
            // to also use the namespace
129
            $tasksNamespace = '';
133
            $tasksNamespace = '';
130
        }
134
        }
131
        if (isset($xml[$tasksNamespace . 'paramgroup'])) {
135
        if (isset($xml[$tasksNamespace.'paramgroup'])) {
132
            $params = $xml[$tasksNamespace . 'paramgroup'];
136
            $params = $xml[$tasksNamespace.'paramgroup'];
133
            if (!is_array($params) || !isset($params[0])) {
137
            if (!is_array($params) || !isset($params[0])) {
134
                $params = array($params);
138
                $params = array($params);
135
            }
139
            }
136
            foreach ($params as $param) {
140
            foreach ($params as $param) {
137
                if (!isset($param[$tasksNamespace . 'id'])) {
141
                if (!isset($param[$tasksNamespace.'id'])) {
138
                    return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
142
                    return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
139
                        $fileXml['name'] . '" <paramgroup> must have ' .
143
                        $fileXml['name'].'" <paramgroup> must have '.
140
                        'an ' . $tasksNamespace . 'id> tag');
144
                        'an '.$tasksNamespace.'id> tag', );
141
                }
145
                }
142
                if (isset($param[$tasksNamespace . 'name'])) {
146
                if (isset($param[$tasksNamespace.'name'])) {
143
                    if (!in_array($param[$tasksNamespace . 'name'], $definedparams)) {
147
                    if (!in_array($param[$tasksNamespace.'name'], $definedparams)) {
144
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
148
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
145
                            $fileXml['name'] . '" ' . $tasksNamespace .
149
                            $fileXml['name'].'" '.$tasksNamespace.
146
                            'paramgroup> id "' . $param[$tasksNamespace . 'id'] .
150
                            'paramgroup> id "'.$param[$tasksNamespace.'id'].
147
                            '" parameter "' . $param[$tasksNamespace . 'name'] .
151
                            '" parameter "'.$param[$tasksNamespace.'name'].
148
                            '" has not been previously defined');
152
                            '" has not been previously defined', );
149
                    }
153
                    }
150
                    if (!isset($param[$tasksNamespace . 'conditiontype'])) {
154
                    if (!isset($param[$tasksNamespace.'conditiontype'])) {
151
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
155
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
152
                            $fileXml['name'] . '" ' . $tasksNamespace .
156
                            $fileXml['name'].'" '.$tasksNamespace.
153
                            'paramgroup> id "' . $param[$tasksNamespace . 'id'] .
157
                            'paramgroup> id "'.$param[$tasksNamespace.'id'].
154
                            '" must have a ' . $tasksNamespace . 
158
                            '" must have a '.$tasksNamespace.
155
                            'conditiontype> tag containing either "=", ' .
159
                            'conditiontype> tag containing either "=", '.
156
                            '"!=", or "preg_match"');
160
                            '"!=", or "preg_match"', );
-
 
161
                    }
157
                    }
162
                    if (!in_array(
158
                    if (!in_array($param[$tasksNamespace . 'conditiontype'],
163
                        $param[$tasksNamespace.'conditiontype'],
-
 
164
                        array('=', '!=', 'preg_match')
159
                          array('=', '!=', 'preg_match'))) {
165
                    )) {
160
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
166
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
161
                            $fileXml['name'] . '" ' . $tasksNamespace .
167
                            $fileXml['name'].'" '.$tasksNamespace.
162
                            'paramgroup> id "' . $param[$tasksNamespace . 'id'] .
168
                            'paramgroup> id "'.$param[$tasksNamespace.'id'].
163
                            '" must have a ' . $tasksNamespace .
169
                            '" must have a '.$tasksNamespace.
164
                            'conditiontype> tag containing either "=", ' .
170
                            'conditiontype> tag containing either "=", '.
165
                            '"!=", or "preg_match"');
171
                            '"!=", or "preg_match"', );
166
                    }
172
                    }
167
                    if (!isset($param[$tasksNamespace . 'value'])) {
173
                    if (!isset($param[$tasksNamespace.'value'])) {
168
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
174
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
169
                            $fileXml['name'] . '" ' . $tasksNamespace .
175
                            $fileXml['name'].'" '.$tasksNamespace.
170
                            'paramgroup> id "' . $param[$tasksNamespace . 'id'] .
176
                            'paramgroup> id "'.$param[$tasksNamespace.'id'].
171
                            '" must have a ' . $tasksNamespace .
177
                            '" must have a '.$tasksNamespace.
172
                            'value> tag containing expected parameter value');
178
                            'value> tag containing expected parameter value', );
173
                    }
179
                    }
174
                }
180
                }
175
                if (isset($param[$tasksNamespace . 'instructions'])) {
181
                if (isset($param[$tasksNamespace.'instructions'])) {
176
                    if (!is_string($param[$tasksNamespace . 'instructions'])) {
182
                    if (!is_string($param[$tasksNamespace.'instructions'])) {
177
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
183
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
178
                            $fileXml['name'] . '" ' . $tasksNamespace .
184
                            $fileXml['name'].'" '.$tasksNamespace.
179
                            'paramgroup> id "' . $param[$tasksNamespace . 'id'] .
185
                            'paramgroup> id "'.$param[$tasksNamespace.'id'].
180
                            '" ' . $tasksNamespace . 'instructions> must be simple text');
186
                            '" '.$tasksNamespace.'instructions> must be simple text', );
181
                    }
187
                    }
182
                }
188
                }
183
                if (!isset($param[$tasksNamespace . 'param'])) {
189
                if (!isset($param[$tasksNamespace.'param'])) {
184
                    continue; // <param> is no longer required
190
                    continue; // <param> is no longer required
185
                }
191
                }
186
                $subparams = $param[$tasksNamespace . 'param'];
192
                $subparams = $param[$tasksNamespace.'param'];
187
                if (!is_array($subparams) || !isset($subparams[0])) {
193
                if (!is_array($subparams) || !isset($subparams[0])) {
188
                    $subparams = array($subparams);
194
                    $subparams = array($subparams);
189
                }
195
                }
190
                foreach ($subparams as $subparam) {
196
                foreach ($subparams as $subparam) {
191
                    if (!isset($subparam[$tasksNamespace . 'name'])) {
197
                    if (!isset($subparam[$tasksNamespace.'name'])) {
192
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
198
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
193
                            $fileXml['name'] . '" parameter for ' .
199
                            $fileXml['name'].'" parameter for '.
194
                            $tasksNamespace . 'paramgroup> id "' .
200
                            $tasksNamespace.'paramgroup> id "'.
195
                            $param[$tasksNamespace . 'id'] . '" must have ' .
201
                            $param[$tasksNamespace.'id'].'" must have '.
196
                            'a ' . $tasksNamespace . 'name> tag');
202
                            'a '.$tasksNamespace.'name> tag', );
-
 
203
                    }
197
                    }
204
                    if (!preg_match(
198
                    if (!preg_match('/[a-zA-Z0-9]+/',
205
                        '/[a-zA-Z0-9]+/',
-
 
206
                        $subparam[$tasksNamespace.'name']
199
                          $subparam[$tasksNamespace . 'name'])) {
207
                    )) {
200
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
208
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
201
                            $fileXml['name'] . '" parameter "' .
209
                            $fileXml['name'].'" parameter "'.
202
                            $subparam[$tasksNamespace . 'name'] .
210
                            $subparam[$tasksNamespace.'name'].
203
                            '" for ' . $tasksNamespace . 'paramgroup> id "' .
211
                            '" for '.$tasksNamespace.'paramgroup> id "'.
204
                            $param[$tasksNamespace . 'id'] .
212
                            $param[$tasksNamespace.'id'].
205
                            '" is not a valid name.  Must contain only alphanumeric characters');
213
                            '" is not a valid name.  Must contain only alphanumeric characters', );
206
                    }
214
                    }
207
                    if (!isset($subparam[$tasksNamespace . 'prompt'])) {
215
                    if (!isset($subparam[$tasksNamespace.'prompt'])) {
208
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
216
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
209
                            $fileXml['name'] . '" parameter "' .
217
                            $fileXml['name'].'" parameter "'.
210
                            $subparam[$tasksNamespace . 'name'] .
218
                            $subparam[$tasksNamespace.'name'].
211
                            '" for ' . $tasksNamespace . 'paramgroup> id "' .
219
                            '" for '.$tasksNamespace.'paramgroup> id "'.
212
                            $param[$tasksNamespace . 'id'] .
220
                            $param[$tasksNamespace.'id'].
213
                            '" must have a ' . $tasksNamespace . 'prompt> tag');
221
                            '" must have a '.$tasksNamespace.'prompt> tag', );
214
                    }
222
                    }
215
                    if (!isset($subparam[$tasksNamespace . 'type'])) {
223
                    if (!isset($subparam[$tasksNamespace.'type'])) {
216
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
224
                        return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "'.
217
                            $fileXml['name'] . '" parameter "' .
225
                            $fileXml['name'].'" parameter "'.
218
                            $subparam[$tasksNamespace . 'name'] .
226
                            $subparam[$tasksNamespace.'name'].
219
                            '" for ' . $tasksNamespace . 'paramgroup> id "' .
227
                            '" for '.$tasksNamespace.'paramgroup> id "'.
220
                            $param[$tasksNamespace . 'id'] .
228
                            $param[$tasksNamespace.'id'].
221
                            '" must have a ' . $tasksNamespace . 'type> tag');
229
                            '" must have a '.$tasksNamespace.'type> tag', );
222
                    }
230
                    }
223
                    $definedparams[] = $param[$tasksNamespace . 'id'] . '::' .
231
                    $definedparams[] = $param[$tasksNamespace.'id'].'::'.
224
                    $subparam[$tasksNamespace . 'name'];
232
                    $subparam[$tasksNamespace.'name'];
225
                }
233
                }
226
            }
234
            }
-
 
235
        }
227
        }
236
 
228
        return true;
237
        return true;
Line 229... Line 238...
229
    }
238
    }
230
 
239
 
231
    /**
240
    /**
232
     * Initialize a task instance with the parameters
241
     * Initialize a task instance with the parameters
-
 
242
     * @param array       $xml         raw, parsed xml
233
     * @param array raw, parsed xml
243
     * @param array       $fileattribs attributes from the <file> tag containing
-
 
244
     *                                 this task
234
     * @param array attributes from the <file> tag containing this task
245
     * @param string|null $lastversion last installed version of this package,
235
     * @param string|null last installed version of this package, if any (useful for upgrades)
246
     *                                 if any (useful for upgrades)
236
     */
247
     */
237
    function init($xml, $fileattribs, $lastversion)
248
    public function init($xml, $fileattribs, $lastversion)
238
    {
249
    {
239
        $this->_class = str_replace('/', '_', $fileattribs['name']);
250
        $this->_class = str_replace('/', '_', $fileattribs['name']);
240
        $this->_filename = $fileattribs['name'];
251
        $this->_filename = $fileattribs['name'];
241
        $this->_class = str_replace ('.php', '', $this->_class) . '_postinstall';
252
        $this->_class = str_replace('.php', '', $this->_class).'_postinstall';
242
        $this->_params = $xml;
253
        $this->_params = $xml;
Line 243... Line 254...
243
        $this->_lastversion = $lastversion;
254
        $this->_lastversion = $lastversion;
244
    }
255
    }
245
 
256
 
246
    /**
257
    /**
247
     * Strip the tasks: namespace from internal params
258
     * Strip the tasks: namespace from internal params
248
     *
259
     *
249
     * @access private
260
     * @access private
250
     */
261
     */
251
    function _stripNamespace($params = null)
262
    public function _stripNamespace($params = null)
252
    {
263
    {
253
        if ($params === null) {
264
        if ($params === null) {
254
            $params = array();
265
            $params = array();
255
            if (!is_array($this->_params)) {
266
            if (!is_array($this->_params)) {
256
                return;
267
                return;
257
            }
268
            }
258
            foreach ($this->_params as $i => $param) {
269
            foreach ($this->_params as $i => $param) {
259
                if (is_array($param)) {
270
                if (is_array($param)) {
260
                    $param = $this->_stripNamespace($param);
271
                    $param = $this->_stripNamespace($param);
261
                }
272
                }
262
                $params[str_replace($this->_pkg->getTasksNs() . ':', '', $i)] = $param;
273
                $params[str_replace($this->_pkg->getTasksNs().':', '', $i)] = $param;
263
            }
274
            }
264
            $this->_params = $params;
275
            $this->_params = $params;
265
        } else {
276
        } else {
266
            $newparams = array();
277
            $newparams = array();
267
            foreach ($params as $i => $param) {
278
            foreach ($params as $i => $param) {
268
                if (is_array($param)) {
279
                if (is_array($param)) {
269
                    $param = $this->_stripNamespace($param);
280
                    $param = $this->_stripNamespace($param);
-
 
281
                }
270
                }
282
                $newparams[str_replace($this->_pkg->getTasksNs().':', '', $i)] = $param;
271
                $newparams[str_replace($this->_pkg->getTasksNs() . ':', '', $i)] = $param;
283
            }
272
            }
284
 
Line 273... Line 285...
273
            return $newparams;
285
            return $newparams;
274
        }
286
        }
275
    }
287
    }
-
 
288
 
276
 
289
    /**
277
    /**
290
     * Unlike other tasks, the installed file name is passed in instead of the
-
 
291
     * file contents, because this task is handled post-installation
278
     * Unlike other tasks, the installed file name is passed in instead of the file contents,
292
     *
279
     * because this task is handled post-installation
293
     * @param mixed  $pkg      PEAR_PackageFile_v1|PEAR_PackageFile_v2
280
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
294
     * @param string $contents file name
281
     * @param string file name
295
     *
282
     * @return bool|PEAR_Error false to skip this file, PEAR_Error to fail
296
     * @return bool|PEAR_Error false to skip this file, PEAR_Error to fail
283
     *         (use $this->throwError)
297
     *                         (use $this->throwError)
284
     */
298
     */
285
    function startSession($pkg, $contents)
299
    public function startSession($pkg, $contents)
286
    {
300
    {
287
        if ($this->installphase != PEAR_TASK_INSTALL) {
301
        if ($this->installphase != PEAR_TASK_INSTALL) {
288
            return false;
302
            return false;
-
 
303
        }
289
        }
304
        // remove the tasks: namespace if present
290
        // remove the tasks: namespace if present
305
        $this->_pkg = $pkg;
-
 
306
        $this->_stripNamespace();
291
        $this->_pkg = $pkg;
307
        $this->logger->log(
292
        $this->_stripNamespace();
308
            0, 'Including external post-installation script "'.
293
        $this->logger->log(0, 'Including external post-installation script "' .
309
            $contents.'" - any errors are in this script'
294
            $contents . '" - any errors are in this script');
310
        );
-
 
311
        include_once $contents;
295
        include_once $contents;
312
        if (class_exists($this->_class)) {
296
        if (class_exists($this->_class)) {
313
            $this->logger->log(0, 'Inclusion succeeded');
-
 
314
        } else {
297
            $this->logger->log(0, 'Inclusion succeeded');
315
            return $this->throwError(
298
        } else {
316
                'init of post-install script class "'.$this->_class
299
            return $this->throwError('init of post-install script class "' . $this->_class
317
                .'" failed'
300
                . '" failed');
318
            );
301
        }
319
        }
302
        $this->_obj = new $this->_class;
320
        $this->_obj = new $this->_class();
303
        $this->logger->log(1, 'running post-install script "' . $this->_class . '->init()"');
321
        $this->logger->log(1, 'running post-install script "'.$this->_class.'->init()"');
304
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
322
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
305
        $res = $this->_obj->init($this->config, $pkg, $this->_lastversion);
323
        $res = $this->_obj->init($this->config, $pkg, $this->_lastversion);
-
 
324
        PEAR::popErrorHandling();
306
        PEAR::popErrorHandling();
325
        if ($res) {
307
        if ($res) {
326
            $this->logger->log(0, 'init succeeded');
-
 
327
        } else {
308
            $this->logger->log(0, 'init succeeded');
328
            return $this->throwError(
309
        } else {
329
                'init of post-install script "'.$this->_class.
-
 
330
                '->init()" failed'
310
            return $this->throwError('init of post-install script "' . $this->_class .
331
            );
311
                '->init()" failed');
332
        }
Line 312... Line 333...
312
        }
333
        $this->_contents = $contents;
313
        $this->_contents = $contents;
334
 
-
 
335
        return true;
314
        return true;
336
    }
315
    }
337
 
316
 
338
    /**
317
    /**
339
     * No longer used
318
     * No longer used
-
 
319
     * @see PEAR_PackageFile_v2::runPostinstallScripts()
340
     *
320
     * @param array an array of tasks
341
     * @see    PEAR_PackageFile_v2::runPostinstallScripts()
321
     * @param string install or upgrade
342
     * @param  array an array of tasks
322
     * @access protected
343
     * @param  string install or upgrade
323
     * @static
344
     * @access protected
324
     */
-
 
325
    function run()
345
     */