From 3d0a03783d9fe4eabbbec70fde3da735c1401d54 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Thu, 29 Jan 2026 12:51:07 -0500 Subject: [PATCH 1/4] remove SQL trigger --- resources/init.php | 1 + resources/lib/UnitySQL.php | 12 ++++++++++++ tools/docker-dev/sql/bootstrap.sql | 13 ------------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/init.php b/resources/init.php index 4ec354b8d..5f8b81e76 100644 --- a/resources/init.php +++ b/resources/init.php @@ -84,6 +84,7 @@ $days_idle = $SQL->convertLastLoginToDaysIdle($SQL->getUserLastLogin($USER->uid)); $SQL->addLog("user_login", $OPERATOR->uid); + $SQL->updateUserLastLogin($OPERATOR->uid); $USER->updateIsQualified(); // in case manual changes have been made to PI groups diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index 19f9eab8b..ec4240990 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -155,6 +155,18 @@ public function addLog(string $action_type, string $recipient): void $stmt->execute(); } + public function updateUserLastLogin(string $uid): void + { + $stmt = $this->conn->prepare( + sprintf( + "UPDATE %s SET last_login=CURRENT_TIMESTAMP WHERE uid=:uid", + self::TABLE_USER_LAST_LOGINS, + ), + ); + $stmt->bindParam(":uid", $uid); + $stmt->execute(); + } + /** @return user_last_login[] */ public function getAllUserLastLogins(): array { diff --git a/tools/docker-dev/sql/bootstrap.sql b/tools/docker-dev/sql/bootstrap.sql index 602ab5386..68de987db 100644 --- a/tools/docker-dev/sql/bootstrap.sql +++ b/tools/docker-dev/sql/bootstrap.sql @@ -48,19 +48,6 @@ CREATE TABLE user_last_logins ( last_login TIMESTAMP ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; -DELIMITER // -CREATE TRIGGER update_last_login -AFTER INSERT ON audit_log -FOR EACH ROW -BEGIN - IF NEW.action_type = 'user_login' THEN - INSERT INTO user_last_logins (operator, last_login) - VALUES (NEW.operator, NEW.timestamp) - ON DUPLICATE KEY UPDATE last_login = NEW.timestamp; - END IF; -END;// -DELIMITER ; - -- -------------------------------------------------------- -- From 90129fe81d9a9a3aae195e5181c812d240a65853 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Thu, 29 Jan 2026 12:53:40 -0500 Subject: [PATCH 2/4] fix column name --- resources/lib/UnitySQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index ec4240990..07fc29323 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -159,7 +159,7 @@ public function updateUserLastLogin(string $uid): void { $stmt = $this->conn->prepare( sprintf( - "UPDATE %s SET last_login=CURRENT_TIMESTAMP WHERE uid=:uid", + "UPDATE %s SET last_login=CURRENT_TIMESTAMP WHERE operator=:uid", self::TABLE_USER_LAST_LOGINS, ), ); From e0d2b9d7a4a54f8941db497ddb8ab313dc70cff3 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 30 Jan 2026 12:44:25 -0500 Subject: [PATCH 3/4] fix bug when operator not already in table --- resources/lib/UnitySQL.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index 07fc29323..6ce453be1 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -157,12 +157,14 @@ public function addLog(string $action_type, string $recipient): void public function updateUserLastLogin(string $uid): void { - $stmt = $this->conn->prepare( - sprintf( - "UPDATE %s SET last_login=CURRENT_TIMESTAMP WHERE operator=:uid", - self::TABLE_USER_LAST_LOGINS, - ), - ); + $table = self::TABLE_USER_LAST_LOGINS; + $stmt = $this->conn->prepare(" + INSERT INTO $table + (operator, last_login) + VALUES(:uid, CURRENT_TIMESTAMP) + ON DUPLICATE KEY UPDATE + last_login=CURRENT_TIMESTAMP + "); $stmt->bindParam(":uid", $uid); $stmt->execute(); } From 6bd57fcf3e02352c1b3d9ad6874d22ed4202e1b4 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Thu, 5 Mar 2026 15:20:00 -0500 Subject: [PATCH 4/4] add to changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e90456023..b1d963a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,10 @@ For details on the changes in each release, see [the Releases page](https://gith - the `[ldap]user_flag_groups[immortal]` open must also be defined - the `[site]account_policy_url` option has been renamed to `[site]pi_qualification_docs_url` - the `[site]account_expiration_policy_url` option must be defined +- the SQL trigger for `audit_log` to update `user_last_logins` should be removed: + ```sql + drop trigger update_last_logins; + ``` ### 1.5 -> 1.6