Skip to content

Commit 04521e3

Browse files
authored
Merge pull request #137 from Ente/TT-212
TT-212: update check
2 parents da55dcc + 033123a commit 04521e3

File tree

6 files changed

+102
-11
lines changed

6 files changed

+102
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# CHANGELOG
22

3+
## v8.7
4+
5+
* Added automatic update check within the Settings page allowing to see the changelogs and a link to the new Release.
6+
* Updated `README.md`
7+
38
## v8.6
49

510
* Telemetry statistics page for environments using the Telemetry Server. Please check `README.md`
611

712
## v8.5.1
813

914
* Fixed undefined variable warning message <!-- [#133](https://github.com/Ente/timetrack/issues/133) -->
10-
* Changed app.json.sample default values
15+
* Changed `app.json.sample` default values
1116
* Updated README.md <!-- [#134](https://github.com/Ente/timetrack/issues/134) -->
1217
* Added `update.sh` script
1318
* Internal plugin views can now be hidden

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A demo is available here: [https://tt-demo.openducks.org](https://tt-demo.opendu
2828
You can quickly get started with TimeTrack using Docker. Follow these steps:
2929

3030
* Ensure you have Docker and Docker Compose installed on your system.
31-
* Clone the TimeTrack repository: `git clone https://github.com/Ente/timetrack.git` & `cd timetrack`
31+
* 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)**
3232
* Build the Docker image: `docker build -t openducks/timetrack .`
3333
* 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.
3434
* 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.
5656
Simply install the software by following these steps:
5757

5858
- 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.
59-
- Git clone timetrack to e.g. `/var/www`: `cd /var/www && git clone https://github.com/Ente/timetrack.git && cd timetrack`
59+
- 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)**
6060
- Install requirements for composer `composer install`
6161
- 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;`!
6262
- 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`

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.6
1+
8.7

api/v1/class/arbeitszeit.inc.php

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ public function renderUserWorktimeSelect(
229229
?int $selectedWorktime = null,
230230
string $placeholder = "",
231231
string $class = ""
232-
): void
233-
{
232+
): void {
234233
$userId = $this->benutzer()->get_user_from_id($userId)["username"];
235234
$sql = "SELECT * FROM arbeitszeiten WHERE username = ?";
236235
$stmt = $this->db->sendQuery($sql);
@@ -247,9 +246,9 @@ public function renderUserWorktimeSelect(
247246
echo '<option value="' . $wt["id"] . '"' . $sel . '>'
248247
. htmlspecialchars($label)
249248
. '</option>';
250-
}
249+
}
251250

252-
echo '</select>';
251+
echo '</select>';
253252
}
254253

255254

@@ -404,7 +403,7 @@ public function add_worktime($start, $end, $location, $date, $username, $type, $
404403

405404
public function update_worktime($id, $array)
406405
{
407-
if(!$this->check_if_for_review($id)){
406+
if (!$this->check_if_for_review($id)) {
408407
return false;
409408
}
410409
$allowed = [
@@ -839,6 +838,92 @@ public function blockIfNotAdmin()
839838
return false;
840839
}
841840

841+
public function checkForUpdate()
842+
{
843+
$currentVersion = $this->getTimeTrackVersion();
844+
$latestVersion = file_get_contents("https://raw.githubusercontent.com/Ente/timetrack/refs/heads/develop/VERSION");
845+
846+
$currentVersion = trim($currentVersion);
847+
$latestVersion = trim($latestVersion);
848+
849+
if (version_compare($currentVersion, $latestVersion, '<')) {
850+
return $latestVersion;
851+
} else {
852+
return false;
853+
}
854+
}
855+
856+
public function getChanges(string $version_tag = "latest")
857+
{
858+
if ($version_tag !== "latest") {
859+
$url = "https://api.github.com/repos/ente/timetrack/releases/tags/v{$version_tag}";
860+
} else {
861+
$url = "https://api.github.com/repos/ente/timetrack/releases/latest";
862+
}
863+
864+
$context = stream_context_create([
865+
"http" => [
866+
"method" => "GET",
867+
"header" => [
868+
"User-Agent: TimeTrack-Updater",
869+
"Accept: application/vnd.github+json"
870+
],
871+
"timeout" => 10
872+
]
873+
]);
874+
875+
$json = @file_get_contents($url, false, $context);
876+
877+
if ($json === false) {
878+
return null;
879+
#throw new \RuntimeException("GitHub API request failed");
880+
}
881+
882+
return json_decode($json, true);
883+
}
884+
885+
886+
public function renderGUIUpdateCheck()
887+
{
888+
889+
$text = "";
890+
$current = $this->getTimeTrackVersion();
891+
$latest = $this->checkForUpdate();
892+
893+
894+
if ($this->checkForUpdate() != false) {
895+
$latestChanges = $this->getChanges($latest) ?? "NULL";
896+
$fullChangelogUrl = "https://github.com/ente/timetrack/compare/v{$current}...v{$latest}";
897+
$latestVersionLink = "https://github.com/ente/timetrack/releases/tag/v{$latest}";
898+
$text .= "<div class='card v8-bordered log-box'>";
899+
$text .= "<h2>Update available!</h2><br>";
900+
$text .= "You are currently using TimeTrack version <strong>{$current}</strong>, the latest version is <strong><a href='{$latestVersionLink}' target='_blank'>{$latest}</a></strong>.<br>";
901+
$text .= "Please check the <a href='{$fullChangelogUrl}' target='_blank'>changelog</a> for more information about the changes.<br>";
902+
$text .= "It is recommended to update as soon as possible to benefit from the latest features and security improvements.";
903+
## changelog + parsedown
904+
$text .= "<hr>";
905+
$text .= "<strong>Changelog for version {$latest}:</strong><br>";
906+
$parsedown = new \Parsedown();
907+
$text .= $parsedown->text($latestChanges["body"]);
908+
$text .= "</div>";
909+
return $text;
910+
} else {
911+
$text .= "<div class='card v8-bordered log-box'>";
912+
$text .= "You are using the latest version of TimeTrack (<strong>{$current}</strong>). No update is required.";
913+
## current changelog
914+
$text .= "<hr>";
915+
$text .= "<strong>Changelog for version {$current}:</strong><br>";
916+
$parsedown = new \Parsedown();
917+
$currentChanges = $this->getChanges($current);
918+
if($currentChanges == null) {
919+
$currentChanges["body"] = "**No changelogs found. Either you are using a custom build or something went wrong while fetching the changelogs.**";
920+
}
921+
$text .= $parsedown->text($currentChanges["body"]);
922+
$text .= "</div>";
923+
return $text;
924+
}
925+
}
926+
842927
public function global_dispatcher(): \Symfony\Component\EventDispatcher\EventDispatcher
843928
{
844929
return \Arbeitszeit\Events\EventDispatcherService::get();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "TimeTrack is a PHP-written time recording tool for small businesses",
44
"type": "software",
55
"license": "GNU GPL",
6-
"version": "8.6",
6+
"version": "8.7",
77
"authors": [
88
{
99
"name": "Bryan Boehnke-Avan",

suite/admin/users/settings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
2525
DAT;
2626

27-
?>
27+
?><br><br>
28+
<?= $arbeit->renderGUIUpdateCheck(); ?><br><br>
2829
<div class="card v8-bordered log-box">
2930
<h2>Telemetry</h2>
3031
<p>Here you can send anonymous telemetry data to help improve the application.

0 commit comments

Comments
 (0)