From 033123a868a371b6af7956f0572fbc99074a54d9 Mon Sep 17 00:00:00 2001 From: Ente Date: Sat, 27 Dec 2025 23:51:20 +0100 Subject: [PATCH] TT-212: update check --- CHANGELOG.md | 7 ++- README.md | 4 +- VERSION | 2 +- api/v1/class/arbeitszeit.inc.php | 95 ++++++++++++++++++++++++++++++-- composer.json | 2 +- suite/admin/users/settings.php | 3 +- 6 files changed, 102 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc9f48..3158740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## v8.7 + +* Added automatic update check within the Settings page allowing to see the changelogs and a link to the new Release. +* Updated `README.md` + ## v8.6 * Telemetry statistics page for environments using the Telemetry Server. Please check `README.md` @@ -7,7 +12,7 @@ ## v8.5.1 * Fixed undefined variable warning message -* Changed app.json.sample default values +* Changed `app.json.sample` default values * Updated README.md * Added `update.sh` script * Internal plugin views can now be hidden diff --git a/README.md b/README.md index 3dea56c..6852fea 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ A demo is available here: [https://tt-demo.openducks.org](https://tt-demo.opendu You can quickly get started with TimeTrack using Docker. Follow these steps: * Ensure you have Docker and Docker Compose installed on your system. -* Clone the TimeTrack repository: `git clone https://github.com/Ente/timetrack.git` & `cd timetrack` +* Clone the TimeTrack repository: `git clone https://github.com/Ente/timetrack.git` & `cd timetrack` - **The develop branch should not be used unless you know what you are doing. Download the latest release [https://github.com/ente/timetrack/releases/latest](here)** * Build the Docker image: `docker build -t openducks/timetrack .` * Create a `app.json` configuration file based on the provided sample below: `cp api/v1/inc/app.json.sample api/v1/inc/app.json` and edit it to fit your needs. * Adjust the database settings if needed (at least `db_password`) @@ -56,7 +56,7 @@ This software has been tested on Debian 11/12, XAMPP, PHP internal server (e.g. Simply install the software by following these steps: - Install php and requirements: `sudo apt update && sudo apt install php8.2 php8.2-curl php8.2-gd php8.2-gmp php8.2-intl php8.2-mbstring php8.2-mysqli php8.2-pgsql php8.2-xsl php8.2-gettext php8.2-dom php8.2-ldap composer git mariadb-server apache2 -y` and enable the apache rewrite mod `a2enmod rewrite && service apache2 restart`. If you do not want to use apache2 you can skip this step. -- Git clone timetrack to e.g. `/var/www`: `cd /var/www && git clone https://github.com/Ente/timetrack.git && cd timetrack` +- Git clone timetrack to e.g. `/var/www`: `cd /var/www && git clone https://github.com/Ente/timetrack.git && cd timetrack` - **The develop branch should not be used unless you know what you are doing. Download the latest release [https://github.com/ente/timetrack/releases/latest](here)** - Install requirements for composer `composer install` - Create a new database, e.g. with the name `ab` and create a dedicated user, login (`mysql -u root -p`) then e.g. `timetool`: `CREATE DATABASE ab;` and `CREATE USER 'timetool'@'localhost' IDENTIFIED BY 'yourpassword';` and `GRANT ALL PRIVILEGES ON ab.* TO 'timetool'@'localhost';` don't forget to `FLUSH PRIVILEGES;`! - Configure `app.json` (see below - required changes: `base_url`, `db_user`, `db_password`, `smtp` section and any other if your installation is different) then `mv api/v1/inc/app.json.sample app.json && cd /var/www/timetrack` diff --git a/VERSION b/VERSION index 48c26da..12b73c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.6 +8.7 diff --git a/api/v1/class/arbeitszeit.inc.php b/api/v1/class/arbeitszeit.inc.php index ee17df3..201cd2e 100644 --- a/api/v1/class/arbeitszeit.inc.php +++ b/api/v1/class/arbeitszeit.inc.php @@ -229,8 +229,7 @@ public function renderUserWorktimeSelect( ?int $selectedWorktime = null, string $placeholder = "—", string $class = "" - ): void - { + ): void { $userId = $this->benutzer()->get_user_from_id($userId)["username"]; $sql = "SELECT * FROM arbeitszeiten WHERE username = ?"; $stmt = $this->db->sendQuery($sql); @@ -247,9 +246,9 @@ public function renderUserWorktimeSelect( echo ''; - } + } - echo ''; + echo ''; } @@ -404,7 +403,7 @@ public function add_worktime($start, $end, $location, $date, $username, $type, $ public function update_worktime($id, $array) { - if(!$this->check_if_for_review($id)){ + if (!$this->check_if_for_review($id)) { return false; } $allowed = [ @@ -839,6 +838,92 @@ public function blockIfNotAdmin() return false; } + public function checkForUpdate() + { + $currentVersion = $this->getTimeTrackVersion(); + $latestVersion = file_get_contents("https://raw.githubusercontent.com/Ente/timetrack/refs/heads/develop/VERSION"); + + $currentVersion = trim($currentVersion); + $latestVersion = trim($latestVersion); + + if (version_compare($currentVersion, $latestVersion, '<')) { + return $latestVersion; + } else { + return false; + } + } + + public function getChanges(string $version_tag = "latest") + { + if ($version_tag !== "latest") { + $url = "https://api.github.com/repos/ente/timetrack/releases/tags/v{$version_tag}"; + } else { + $url = "https://api.github.com/repos/ente/timetrack/releases/latest"; + } + + $context = stream_context_create([ + "http" => [ + "method" => "GET", + "header" => [ + "User-Agent: TimeTrack-Updater", + "Accept: application/vnd.github+json" + ], + "timeout" => 10 + ] + ]); + + $json = @file_get_contents($url, false, $context); + + if ($json === false) { + return null; + #throw new \RuntimeException("GitHub API request failed"); + } + + return json_decode($json, true); + } + + + public function renderGUIUpdateCheck() + { + + $text = ""; + $current = $this->getTimeTrackVersion(); + $latest = $this->checkForUpdate(); + + + if ($this->checkForUpdate() != false) { + $latestChanges = $this->getChanges($latest) ?? "NULL"; + $fullChangelogUrl = "https://github.com/ente/timetrack/compare/v{$current}...v{$latest}"; + $latestVersionLink = "https://github.com/ente/timetrack/releases/tag/v{$latest}"; + $text .= "
"; + $text .= "

Update available!


"; + $text .= "You are currently using TimeTrack version {$current}, the latest version is {$latest}.
"; + $text .= "Please check the changelog for more information about the changes.
"; + $text .= "It is recommended to update as soon as possible to benefit from the latest features and security improvements."; + ## changelog + parsedown + $text .= "
"; + $text .= "Changelog for version {$latest}:
"; + $parsedown = new \Parsedown(); + $text .= $parsedown->text($latestChanges["body"]); + $text .= "
"; + return $text; + } else { + $text .= "
"; + $text .= "You are using the latest version of TimeTrack ({$current}). No update is required."; + ## current changelog + $text .= "
"; + $text .= "Changelog for version {$current}:
"; + $parsedown = new \Parsedown(); + $currentChanges = $this->getChanges($current); + if($currentChanges == null) { + $currentChanges["body"] = "**No changelogs found. Either you are using a custom build or something went wrong while fetching the changelogs.**"; + } + $text .= $parsedown->text($currentChanges["body"]); + $text .= "
"; + return $text; + } + } + public function global_dispatcher(): \Symfony\Component\EventDispatcher\EventDispatcher { return \Arbeitszeit\Events\EventDispatcherService::get(); diff --git a/composer.json b/composer.json index 9f2a6b6..41bccd5 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "TimeTrack is a PHP-written time recording tool for small businesses", "type": "software", "license": "GNU GPL", - "version": "8.6", + "version": "8.7", "authors": [ { "name": "Bryan Boehnke-Avan", diff --git a/suite/admin/users/settings.php b/suite/admin/users/settings.php index a9b039b..a44fa47 100644 --- a/suite/admin/users/settings.php +++ b/suite/admin/users/settings.php @@ -24,7 +24,8 @@ DAT; -?> +?>

+renderGUIUpdateCheck(); ?>

Telemetry

Here you can send anonymous telemetry data to help improve the application.