mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Change audit store to use own TX
This commit is contained in:
parent
7c70274f5e
commit
28424e7e4b
1 changed files with 7 additions and 6 deletions
|
@ -14,6 +14,7 @@ package audit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
"github.com/documize/community/domain"
|
"github.com/documize/community/domain"
|
||||||
"github.com/documize/community/domain/store"
|
"github.com/documize/community/domain/store"
|
||||||
|
@ -35,21 +36,21 @@ func (s Store) Record(ctx domain.RequestContext, t audit.EventType) {
|
||||||
e.IP = ctx.ClientIP
|
e.IP = ctx.ClientIP
|
||||||
e.Type = string(t)
|
e.Type = string(t)
|
||||||
|
|
||||||
tx, err := s.Runtime.Db.Beginx()
|
tx, ok := s.Runtime.StartTx(sql.LevelReadUncommitted)
|
||||||
if err != nil {
|
if !ok {
|
||||||
s.Runtime.Log.Error("transaction", err)
|
s.Runtime.Log.Info("unable to start transaction")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(s.Bind("INSERT INTO dmz_audit_log (c_orgid, c_userid, c_eventtype, c_ip, c_created) VALUES (?, ?, ?, ?, ?)"),
|
_, err := tx.Exec(s.Bind("INSERT INTO dmz_audit_log (c_orgid, c_userid, c_eventtype, c_ip, c_created) VALUES (?, ?, ?, ?, ?)"),
|
||||||
e.OrgID, e.UserID, e.Type, e.IP, e.Created)
|
e.OrgID, e.UserID, e.Type, e.IP, e.Created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
s.Runtime.Rollback(tx)
|
||||||
s.Runtime.Log.Error("prepare audit insert", err)
|
s.Runtime.Log.Error("prepare audit insert", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.Commit()
|
s.Runtime.Commit(tx)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue