Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 54eedd4

Browse files
Merge pull request #7 from 7twin/endScript-cleanup
endScript() cleanup
2 parents 484bc2e + e995b3b commit 54eedd4

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

‎deploy.php‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function errorPage($msg) {
2929
}
3030

3131
// Command to execute at the end of the script
32-
function endScript() {
32+
function endScript($errorMessage = "") {
3333
// Remove lock file
3434
unlink(__DIR__ . '/deploy.lock');
3535
// Flush buffer and prepare output for log and email
@@ -51,6 +51,7 @@ function endScript() {
5151
if(defined('LOG_FILE') && LOG_FILE !== '') error_log($output, 3, LOG_FILE);
5252
// Send email notification
5353
if(defined('EMAIL_NOTIFICATIONS') && EMAIL_NOTIFICATIONS !== '') error_log($output, 1, EMAIL_NOTIFICATIONS);
54+
die($errorMessage);
5455
}
5556

5657
/* Begin Script Execution */
@@ -70,7 +71,6 @@ function endScript() {
7071
} else {
7172
errorPage('<h2>File deploy-config.php does not exist</h2>');
7273
endScript();
73-
die();
7474
}
7575

7676
// Check configuration errors
@@ -88,14 +88,12 @@ function endScript() {
8888
if (count($err)) {
8989
errorPage("<h2>Configuration Error</h2>\n<pre>\n" . implode("\n", $err) . "\n</pre>");
9090
endScript();
91-
die();
9291
}
9392

9493
// Check if lock file exists
9594
if (file_exists(__DIR__ . '/deploy.lock')) {
9695
errorPage('<h2>File deploy.lock detected, another process already running</h2>');
9796
endScript();
98-
die();
9997
}
10098

10199
// Create lock file
@@ -133,15 +131,13 @@ function endScript() {
133131
if(!$allow) {
134132
errorPage('<h2>Access Denied</h2>');
135133
endScript();
136-
die();
137134
}
138135
}
139136

140137
// If there's authorization error
141138
if (!isset($_GET['t']) || $_GET['t'] !== ACCESS_TOKEN || DISABLED === true) {
142139
errorPage('<h2>Access Denied</h2>');
143140
endScript();
144-
die();
145141
}
146142
?>
147143
<!DOCTYPE html>
@@ -193,7 +189,6 @@ function getallheaders() {
193189
} else {
194190
echo "\nOnly push and merged pull request events are processed\n\nDone.\n</pre></body></html>";
195191
endScript();
196-
exit;
197192
}
198193
} else if(isset($headers['X-GitHub-Event'])) {
199194
// Github webhook
@@ -211,7 +206,6 @@ function getallheaders() {
211206
} else {
212207
echo "\nOnly push and merged pull request events are processed\n\nDone.\n</pre></body></html>";
213208
endScript();
214-
exit;
215209
}
216210
}
217211

@@ -221,7 +215,6 @@ function getallheaders() {
221215
if($branch != unserialize(BRANCH)[0]) {
222216
echo "\nBranch $branch not allowed, stopping execution.\n</pre></body></html>";
223217
endScript();
224-
exit;
225218
}
226219

227220
} else {
@@ -232,7 +225,6 @@ function getallheaders() {
232225
if(!in_array($branch, unserialize(BRANCH))) {
233226
echo "\nBranch $branch not allowed, stopping execution.\n</pre></body></html>";
234227
endScript();
235-
exit;
236228
}
237229
} else {
238230
$branch = unserialize(BRANCH)[0];
@@ -249,8 +241,7 @@ function getallheaders() {
249241
$path = trim(shell_exec('which '.$command));
250242
if ($path == '') {
251243
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
252-
endScript();
253-
die(sprintf('<div class="error"><b>%s</b> not available. It needs to be installed on the server for this script to work.</div>', $command));
244+
endScript(sprintf('<div class="error"><b>%s</b> not available. It needs to be installed on the server for this script to work.</div>', $command));
254245
} else {
255246
$version = explode("\n", shell_exec($command.' --version'));
256247
printf('<b>%s</b> : %s'."\n"
@@ -293,7 +284,6 @@ function cmd($command, $print = true, $dir = GIT_DIR) {
293284
'
294285
);
295286
endScript();
296-
exit;
297287
}
298288

299289
return $tmp;
@@ -484,5 +474,4 @@ function cmd($command, $print = true, $dir = GIT_DIR) {
484474
</body>
485475
</html>
486476
<?php
487-
endScript();
488-
exit;
477+
endScript();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /