Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP version 5                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 2004-2007, Clay Loveless                               |
7
// | All rights reserved.                                                 |
8
// +----------------------------------------------------------------------+
9
// | This LICENSE is in the BSD license style.                            |
10
// | http://www.opensource.org/licenses/bsd-license.php                   |
11
// |                                                                      |
12
// | Redistribution and use in source and binary forms, with or without   |
13
// | modification, are permitted provided that the following conditions   |
14
// | are met:                                                             |
15
// |                                                                      |
16
// |  * Redistributions of source code must retain the above copyright    |
17
// |    notice, this list of conditions and the following disclaimer.     |
18
// |                                                                      |
19
// |  * Redistributions in binary form must reproduce the above           |
20
// |    copyright notice, this list of conditions and the following       |
21
// |    disclaimer in the documentation and/or other materials provided   |
22
// |    with the distribution.                                            |
23
// |                                                                      |
24
// |  * Neither the name of Clay Loveless nor the names of contributors   |
25
// |    may be used to endorse or promote products derived from this      |
26
// |    software without specific prior written permission.               |
27
// |                                                                      |
28
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
32
// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35
// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36
// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38
// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39
// | POSSIBILITY OF SUCH DAMAGE.                                          |
40
// +----------------------------------------------------------------------+
41
// | Author: Clay Loveless <clay@killersoft.com>                          |
42
// +----------------------------------------------------------------------+
43
//
44
// $Id: Delete.php 287962 2009-09-02 07:53:12Z mrook $
45
//
46
 
47
/**
48
 * @package     VersionControl_SVN
49
 * @category    VersionControl
50
 * @author      Clay Loveless <clay@killersoft.com>
51
 */
52
 
53
/**
54
 * Subversion Delete command manager class
55
 *
56
 * Remove files and directories from version control.
57
 *
58
 *  1. Each item specified by a PATH is scheduled for deletion upon
59
 *     the next commit.  Files, and directories that have not been
60
 *     committed, are immediately removed from the working copy.
61
 *     PATHs that are, or contain, unversioned or modified items will
62
 *     not be removed unless the 'force' option is given.
63
 *
64
 *  2. Each item specified by a URL is deleted from the repository
65
 *     via an immediate commit.
66
 *
67
 * $switches is an array containing one or more command line options
68
 * defined by the following associative keys:
69
 *
70
 * <code>
71
 *
72
 * $switches = array(
73
 *  'm [message]'   =>  'Specified commit message',
74
 *                      // either 'm' or 'message' may be used (optional)
75
 *  'F [file]'      =>  'Read commit message data from specified file',
76
 *                      // either 'F' or 'file' may be used (optional)
77
 *  'q [quiet]'     =>  true|false,
78
 *                      // prints as little as possible
79
 *  'targets'       =>  'ARG',
80
 *                      // pass contents of file ARG as additional args
81
 *  'force'         =>  true|false,
82
 *                      // force operation to run
83
 *  'force-log'     =>  true|false,
84
 *                      // force validity of log message source
85
 *  'username'      =>  'Subversion repository login',
86
 *  'password'      =>  'Subversion repository password',
87
 *  'no-auth-cache' =>  true|false,
88
 *                      // Do not cache authentication tokens
89
 *  'encoding'      =>  'ARG',
90
 *                      // treat value as being in charset encoding ARG
91
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
92
 * );
93
 *
94
 * </code>
95
 *
96
 * Note: Subversion does not offer an XML output option for this subcommand
97
 *
98
 * The non-interactive option available on the command-line
99
 * svn client may also be set (true|false), but it is set to true by default.
100
 *
101
 * The editor-cmd option available on the command-line svn client is not available
102
 * since this class does not operate as an interactive shell session.
103
 *
104
 * Usage example:
105
 * <code>
106
 * <?php
107
 * require_once 'VersionControl/SVN.php';
108
 *
109
 * // Setup error handling -- always a good idea!
110
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
111
 *
112
 * // Set up runtime options. Will be passed to all
113
 * // subclasses.
114
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
115
 *
116
 * // Pass array of subcommands we need to factory
117
 * $svn = VersionControl_SVN::factory(array('delete'), $options);
118
 *
119
 * // Define any switches and aguments we may need
120
 * $switches = array('m' => 'Whoops! Better get rid of this file',
121
 *                   'username' => 'user', 'password' => 'pass');
122
 * $args = array('svn://svn.example.com/repos/TestProj/trunk/template1/bad_index.tpl');
123
 *
124
 * // Run command
125
 * if ($output = $svn->delete->run($args, $switches)) {
126
 *     print_r($output);
127
 * } else {
128
 *     if (count($errs = $svnstack->getErrors())) {
129
 *         foreach ($errs as $err) {
130
 *             echo '<br />'.$err['message']."<br />\n";
131
 *             echo "Command used: " . $err['params']['cmd'];
132
 *         }
133
 *     }
134
 * }
135
 * ?>
136
 * </code>
137
 *
138
 * @package  VersionControl_SVN
139
 * @version  0.3.4
140
 * @category SCM
141
 * @author   Clay Loveless <clay@killersoft.com>
142
 */
143
class VersionControl_SVN_Delete extends VersionControl_SVN
144
{
145
    /**
146
     * Valid switches for svn delete
147
     *
148
     * @var     array
149
     * @access  public
150
     */
151
    var $valid_switches = array('m',
152
                                'message',
153
                                'q',
154
                                'quiet',
155
                                'targets',
156
                                'username',
157
                                'password',
158
                                'no-auth-cache',
159
                                'no_auth_cache',
160
                                'non-interactive',
161
                                'non_interactive',
162
                                'config-dir',
163
                                'config_dir',
164
                                'file',
165
                                'F',
166
                                'encoding',
167
                                'force',
168
                                'force-log',
169
                                'force_log',
170
                                );
171
 
172
    /**
173
     * Command-line arguments that should be passed
174
     * <b>outside</b> of those specified in {@link switches}.
175
     *
176
     * @var     array
177
     * @access  public
178
     */
179
    var $args = array();
180
 
181
    /**
182
     * Minimum number of args required by this subcommand.
183
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
184
     * Subversion Complete Reference for details on arguments for this subcommand.
185
     * @var     int
186
     * @access  public
187
     */
188
    var $min_args = 1;
189
 
190
    /**
191
     * Switches required by this subcommand.
192
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
193
     * Subversion Complete Reference for details on arguments for this subcommand.
194
     * @var     array
195
     * @access  public
196
     */
197
    var $required_switches = array();
198
 
199
    /**
200
     * Use exec or passthru to get results from command.
201
     * @var     bool
202
     * @access  public
203
     */
204
    var $passthru = false;
205
 
206
    /**
207
     * Prepare the svn subcommand switches.
208
     *
209
     * Defaults to non-interactive mode, and will auto-set the
210
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
211
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
212
     *
213
     * @param   void
214
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
215
     *                 for error details, if any.
216
     */
217
    function prepare()
218
    {
219
        $meets_requirements = $this->checkCommandRequirements();
220
        if (!$meets_requirements) {
221
            return false;
222
        }
223
 
224
        $valid_switches     = $this->valid_switches;
225
        $switches           = $this->switches;
226
        $args               = $this->args;
227
        $fetchmode          = $this->fetchmode;
228
        $invalid_switches   = array();
229
        $_switches          = '';
230
 
231
        foreach ($switches as $switch => $val) {
232
            if (in_array($switch, $valid_switches)) {
233
                $switch = str_replace('_', '-', $switch);
234
                switch ($switch) {
235
                    case 'username':
236
                    case 'password':
237
                    case 'encoding':
238
                    case 'config-dir':
239
                        $_switches .= "--$switch $val ";
240
                        break;
241
                    case 'F':
242
                    case 'm':
243
                        $_switches .= "-$switch \"$val\" ";
244
                        break;
245
                    case 'file':
246
                    case 'message':
247
                        $_switches .= "--$switch \"$val\" ";
248
                        break;
249
                    case 'quiet':
250
                    case 'force':
251
                    case 'force-log':
252
                    case 'no-auth-cache':
253
                        if ($val === true) {
254
                            $_switches .= "--$switch ";
255
                        }
256
                        break;
257
                    case 'q':
258
                        if ($val === true) {
259
                            $_switches .= "-$switch ";
260
                        }
261
                        break;
262
                    default:
263
                        // that's all, folks!
264
                        break;
265
                }
266
            } else {
267
                $invalid_switches[] = $switch;
268
            }
269
        }
270
 
271
        $_switches = trim($_switches);
272
        $this->_switches = $_switches;
273
 
274
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
275
        if (!empty($args)) {
276
            $cmd .= ' '. join(' ', $args);
277
        }
278
 
279
        $this->_prepped_cmd = $cmd;
280
        $this->prepared = true;
281
 
282
        $invalid = count($invalid_switches);
283
        if ($invalid > 0) {
284
            $params['was'] = 'was';
285
            $params['is_invalid_switch'] = 'is an invalid switch';
286
            if ($invalid > 1) {
287
                $params['was'] = 'were';
288
                $params['is_invalid_switch'] = 'are invalid switches';
289
            }
290
            $params['list'] = $invalid_switches;
291
            $params['switches'] = $switches;
292
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
293
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
294
        }
295
        return true;
296
    }
297
 
298
    // }}}
299
    // {{{ parseOutput()
300
 
301
    /**
302
     * Handles output parsing of standard and verbose output of command.
303
     *
304
     * @param   array   $out    Array of output captured by exec command in {@link run}.
305
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
306
     *                  if desired fetchmode is not available.
307
     * @access  public
308
     */
309
    function parseOutput($out)
310
    {
311
        $fetchmode = $this->fetchmode;
312
        switch($fetchmode) {
313
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
314
                return join("\n", $out);
315
                break;
316
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
317
                // Temporary, see parseOutputArray below
318
                return join("\n", $out);
319
                break;
320
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
321
                // Temporary, will return object-ified array from
322
                // parseOutputArray
323
                return join("\n", $out);
324
                break;
325
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
326
                // Temporary, will eventually build an XML string
327
                // with XML_Util or XML_Tree
328
                return join("\n", $out);
329
                break;
330
            default:
331
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
332
                return join("\n", $out);
333
                break;
334
        }
335
    }
336
 
337
    /**
338
     * Helper method for parseOutput that parses output into an associative array
339
     *
340
     * @todo Finish this method! : )
341
     */
342
    function parseOutputArray($out)
343
    {
344
        $parsed = array();
345
    }
346
}
347
 
348
// }}}
349
?>