28
28
*/
29
29
class DeployApplication
30
30
{
31
+ /** @var bool */
32
+ public $ breakOnExecError = true ;
33
+
31
34
/**
32
35
* Private key for protection
33
36
* @var string
@@ -49,6 +52,9 @@ class DeployApplication
49
52
/** @var boolean */
50
53
private $ logError = false ;
51
54
55
+ /** @var bool */
56
+ private $ hasExecError = false ;
57
+
52
58
/**
53
59
* DeployApplication constructor.
54
60
* @param string $securityKey string key for protect application
@@ -66,12 +72,14 @@ public function __construct($securityKey, $workPath = '.', $logFileName = 'git-d
66
72
/**
67
73
* Fastest executing for typical cases
68
74
* @param array $customCommands
75
+ * @return bool
69
76
*/
70
77
public function run (array $ customCommands = [])
71
78
{
72
79
$ this ->begin ();
73
- $ this ->execute ($ customCommands );
80
+ $ res = $ this ->execute ($ customCommands );
74
81
$ this ->end ();
82
+ return $ res ;
75
83
}
76
84
77
85
/**
@@ -87,17 +95,20 @@ public function begin()
87
95
/**
88
96
* Executing command like a command lines
89
97
* @param array $customCommands you can execute custom commands
98
+ * @return bool
90
99
*/
91
100
public function execute (array $ customCommands = [])
92
101
{
93
102
if (!$ this ->checkSecurity ()) {
94
- return ;
103
+ return false ;
95
104
}
105
+ $ this ->hasExecError = false ;
96
106
if (empty ($ customCommands )) {
97
107
$ this ->exec (['git branch ' , 'git pull ' ]); // git pull && git log -1
98
108
} else {
99
109
$ this ->exec ($ customCommands );
100
110
}
111
+ return $ this ->hasExecError ;
101
112
}
102
113
103
114
/**
@@ -173,10 +184,14 @@ private function exec(array $commands)
173
184
exec ($ command . ' 2>&1 ' , $ response , $ error_code );
174
185
if ($ error_code > 0 && empty ($ response )) {
175
186
$ response = array ('Error: ' . $ error_code );
187
+ $ this ->hasExecError = true ;
176
188
}
177
189
$ response = implode ("\n" , $ response );
178
190
$ this ->log ($ response . "\n" . ($ response ? "\n" : '' ));
179
191
}
192
+ if ($ this ->hasExecError && $ this ->breakOnExecError ) {
193
+ return ;
194
+ }
180
195
}
181
196
}
182
197
0 commit comments