From 13a45c81a08c340cb1c8324e6cc323a0d53b5aae Mon Sep 17 00:00:00 2001 From: Hugo Sampaio Date: Mon, 13 May 2024 11:12:52 -0300 Subject: [PATCH 1/2] Display notification when update is available --- admin_update.php | 15 ++++----------- cron.php | 13 +++++++++++++ functions.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/admin_update.php b/admin_update.php index 21229d82f..b97a0adcb 100644 --- a/admin_update.php +++ b/admin_update.php @@ -3,19 +3,12 @@ require_once "database_version.php"; -require_once "config.php"; +$updates = fetchUpdates(); -// Fetch the latest code changes but don't apply them -exec("git fetch", $output, $result); -$latest_version = exec("git rev-parse origin/$repo_branch"); -$current_version = exec("git rev-parse HEAD"); - -if ($current_version == $latest_version) { - $update_message = "No Updates available"; -} else { - $update_message = "New Updates are Available [$latest_version]"; -} +$latest_version = $updates->latest_version; +$current_version = $updates->current_version; +$result = $updates->result; $git_log = shell_exec("git log $repo_branch..origin/$repo_branch --pretty=format:'%h%ar%s'"); diff --git a/cron.php b/cron.php index 8ea474b99..093af55b8 100644 --- a/cron.php +++ b/cron.php @@ -979,6 +979,19 @@ mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Telemetry', log_description = 'Cron sent telemetry results to ITFlow Developers'"); } + +// Fetch Updates +$updates = fetchUpdates(); + +$update_message = $updates->update_message; + +if ($updates->current_version !== $updates->latest_version) { + // Send Alert to inform Updates Available + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Updates', notification = '$update_message', notification_action = 'admin_update.php'"); +} + + + /* * ############################################################################################################### * FINISH UP diff --git a/functions.php b/functions.php index 7bfb1debc..ccae03520 100644 --- a/functions.php +++ b/functions.php @@ -1186,3 +1186,34 @@ function getTicketStatusName($ticket_status) { return "Unknown"; } + + +function fetchUpdates() { + + global $mysqli, $repo_branch; + + // Fetch the latest code changes but don't apply them + exec("git fetch", $output, $result); + $latest_version = exec("git rev-parse origin/$repo_branch"); + $current_version = exec("git rev-parse HEAD"); + + if ($current_version == $latest_version) { + $update_message = "No Updates available"; + } else { + $update_message = "New Updates are Available [$latest_version]"; + } + + + + $updates = new stdClass(); + $updates->output = $output; + $updates->result = $result; + $updates->current_version = $current_version; + $updates->latest_version = $latest_version; + $updates->update_message = $update_message; + + + + return $updates; + +} \ No newline at end of file From 352fbd852e3544199c87eb32a14397c4a0f7356e Mon Sep 17 00:00:00 2001 From: Hugo Sampaio Date: Mon, 13 May 2024 11:22:57 -0300 Subject: [PATCH 2/2] typos --- cron.php | 2 +- functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cron.php b/cron.php index 093af55b8..3b6f685b0 100644 --- a/cron.php +++ b/cron.php @@ -987,7 +987,7 @@ if ($updates->current_version !== $updates->latest_version) { // Send Alert to inform Updates Available - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Updates', notification = '$update_message', notification_action = 'admin_update.php'"); + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Update', notification = '$update_message', notification_action = 'admin_update.php'"); } diff --git a/functions.php b/functions.php index ccae03520..389d018f9 100644 --- a/functions.php +++ b/functions.php @@ -1190,7 +1190,7 @@ function getTicketStatusName($ticket_status) { function fetchUpdates() { - global $mysqli, $repo_branch; + global $repo_branch; // Fetch the latest code changes but don't apply them exec("git fetch", $output, $result);