From e995b3b42ef4069915d7516818c10900144d38e2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Nov 2018 07:14:31 +0100 Subject: [PATCH] Included die() in endScript() Since after every single endScript() there was an exit or die, it can be included inside the function, to be terminated with an optional message --- deploy.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/deploy.php b/deploy.php index 85f5bdc..2840d3f 100644 --- a/deploy.php +++ b/deploy.php @@ -29,7 +29,7 @@ function errorPage($msg) { } // Command to execute at the end of the script -function endScript() { +function endScript($errorMessage = "") { // Remove lock file unlink(__DIR__ . '/deploy.lock'); // Flush buffer and prepare output for log and email @@ -51,6 +51,7 @@ function endScript() { if(defined('LOG_FILE') && LOG_FILE !== '') error_log($output, 3, LOG_FILE); // Send email notification if(defined('EMAIL_NOTIFICATIONS') && EMAIL_NOTIFICATIONS !== '') error_log($output, 1, EMAIL_NOTIFICATIONS); + die($errorMessage); } /* Begin Script Execution */ @@ -70,7 +71,6 @@ function endScript() { } else { errorPage('

File deploy-config.php does not exist

'); endScript(); - die(); } // Check configuration errors @@ -88,14 +88,12 @@ function endScript() { if (count($err)) { errorPage("

Configuration Error

\n
\n" . implode("\n", $err) . "\n
"); endScript(); - die(); } // Check if lock file exists if (file_exists(__DIR__ . '/deploy.lock')) { errorPage('

File deploy.lock detected, another process already running

'); endScript(); - die(); } // Create lock file @@ -133,7 +131,6 @@ function endScript() { if(!$allow) { errorPage('

Access Denied

'); endScript(); - die(); } } @@ -141,7 +138,6 @@ function endScript() { if (!isset($_GET['t']) || $_GET['t'] !== ACCESS_TOKEN || DISABLED === true) { errorPage('

Access Denied

'); endScript(); - die(); } ?> @@ -193,7 +189,6 @@ function getallheaders() { } else { echo "\nOnly push and merged pull request events are processed\n\nDone.\n"; endScript(); - exit; } } else if(isset($headers['X-GitHub-Event'])) { // Github webhook @@ -211,7 +206,6 @@ function getallheaders() { } else { echo "\nOnly push and merged pull request events are processed\n\nDone.\n"; endScript(); - exit; } } @@ -221,7 +215,6 @@ function getallheaders() { if($branch != unserialize(BRANCH)[0]) { echo "\nBranch $branch not allowed, stopping execution.\n"; endScript(); - exit; } } else { @@ -232,7 +225,6 @@ function getallheaders() { if(!in_array($branch, unserialize(BRANCH))) { echo "\nBranch $branch not allowed, stopping execution.\n"; endScript(); - exit; } } else { $branch = unserialize(BRANCH)[0]; @@ -249,8 +241,7 @@ function getallheaders() { $path = trim(shell_exec('which '.$command)); if ($path == '') { header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); - endScript(); - die(sprintf('
%s not available. It needs to be installed on the server for this script to work.
', $command)); + endScript(sprintf('
%s not available. It needs to be installed on the server for this script to work.
', $command)); } else { $version = explode("\n", shell_exec($command.' --version')); printf('%s : %s'."\n" @@ -293,7 +284,6 @@ function cmd($command, $print = true, $dir = GIT_DIR) { ' ); endScript(); - exit; } return $tmp; @@ -484,5 +474,4 @@ function cmd($command, $print = true, $dir = GIT_DIR) {