1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Drush Cerbere command line tools. |
5
|
|
|
* Copyright (C) 2015 - Sebastien Malot <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along |
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Cerbere\Versioning; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Svn |
26
|
|
|
* @package Cerbere\Versioning |
27
|
|
|
*/ |
28
|
|
|
class Svn implements VersioningInterface |
29
|
|
|
{ |
30
|
|
|
const SVN_BINARY_PATH = '/usr/bin/svn'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $workDirectory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
public function __construct() |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getCode() |
49
|
|
|
{ |
50
|
|
|
return 'svn'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getWorkingDirectory() |
57
|
|
|
{ |
58
|
|
|
return $this->workDirectory; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $source |
63
|
|
|
* |
64
|
|
|
* @return mixed |
65
|
|
|
*/ |
66
|
|
|
public function prepare($source) |
67
|
|
|
{ |
68
|
|
|
$this->workDirectory = drush_tempdir(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $source |
73
|
|
|
* @param string $destination |
74
|
|
|
* @param array $options |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function process($source, $destination, $options = array()) |
79
|
|
|
{ |
80
|
|
|
$command = $this->buildCommandLine($source, $destination, $options); |
81
|
|
|
|
82
|
|
|
if (!empty($options['debug'])) { |
83
|
|
|
drush_print('$> ' . $command); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
passthru($command); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $source |
91
|
|
|
* @param string $destination |
92
|
|
|
* @param array $options |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function buildCommandLine($source, $destination, $options = array()) |
97
|
|
|
{ |
98
|
|
|
$options += array('svn' => self::SVN_BINARY_PATH, 'arguments' => array()); |
99
|
|
|
|
100
|
|
|
$command = escapeshellarg($options['svn']) . ' ' . |
101
|
|
|
'checkout ' . escapeshellarg($source) . ' ' . |
102
|
|
|
escapeshellarg($destination) . ' '; |
103
|
|
|
|
104
|
|
|
foreach ($options['arguments'] as $param => $value) { |
105
|
|
|
if (is_numeric($param)) { |
106
|
|
|
$command .= escapeshellarg('-' . $value) . ' '; |
107
|
|
|
} else { |
108
|
|
|
$command .= '--' . $param . '=' . escapeshellarg($value) . ' '; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $command; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|