Skip to content

Commit 85e7745

Browse files
authored
remove SQL trigger (#593)
1 parent a1ae9f5 commit 85e7745

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ For details on the changes in each release, see [the Releases page](https://gith
3838
- the `[ldap]user_flag_groups[immortal]` open must also be defined
3939
- the `[site]account_policy_url` option has been renamed to `[site]pi_qualification_docs_url`
4040
- the `[site]account_expiration_policy_url` option must be defined
41+
- the SQL trigger for `audit_log` to update `user_last_logins` should be removed:
42+
```sql
43+
drop trigger update_last_logins;
44+
```
4145

4246
### 1.5 -> 1.6
4347

resources/init.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484

8585
$days_idle = $SQL->convertLastLoginToDaysIdle($SQL->getUserLastLogin($USER->uid));
8686
$SQL->addLog("user_login", $OPERATOR->uid);
87+
$SQL->updateUserLastLogin($OPERATOR->uid);
8788

8889
$USER->updateIsQualified(); // in case manual changes have been made to PI groups
8990

resources/lib/UnitySQL.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ public function addLog(string $action_type, string $recipient): void
155155
$stmt->execute();
156156
}
157157

158+
public function updateUserLastLogin(string $uid): void
159+
{
160+
$table = self::TABLE_USER_LAST_LOGINS;
161+
$stmt = $this->conn->prepare("
162+
INSERT INTO $table
163+
(operator, last_login)
164+
VALUES(:uid, CURRENT_TIMESTAMP)
165+
ON DUPLICATE KEY UPDATE
166+
last_login=CURRENT_TIMESTAMP
167+
");
168+
$stmt->bindParam(":uid", $uid);
169+
$stmt->execute();
170+
}
171+
158172
/** @return user_last_login[] */
159173
public function getAllUserLastLogins(): array
160174
{

tools/docker-dev/sql/bootstrap.sql

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ CREATE TABLE user_last_logins (
4848
last_login TIMESTAMP
4949
) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
5050

51-
DELIMITER //
52-
CREATE TRIGGER update_last_login
53-
AFTER INSERT ON audit_log
54-
FOR EACH ROW
55-
BEGIN
56-
IF NEW.action_type = 'user_login' THEN
57-
INSERT INTO user_last_logins (operator, last_login)
58-
VALUES (NEW.operator, NEW.timestamp)
59-
ON DUPLICATE KEY UPDATE last_login = NEW.timestamp;
60-
END IF;
61-
END;//
62-
DELIMITER ;
63-
6451
-- --------------------------------------------------------
6552

6653
--

0 commit comments

Comments
 (0)