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 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..6ce453be1 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -155,6 +155,20 @@ public function addLog(string $action_type, string $recipient): void $stmt->execute(); } + public function updateUserLastLogin(string $uid): void + { + $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(); + } + /** @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 ; - -- -------------------------------------------------------- --