mirror of
https://github.com/documize/community.git
synced 2025-07-23 15:19:42 +02:00
event logging
This commit is contained in:
parent
b6c676149a
commit
93ed361705
48 changed files with 861 additions and 853 deletions
58
core/api/request/event.go
Normal file
58
core/api/request/event.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package request
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/log"
|
||||
)
|
||||
|
||||
// RecordEvent adds event entry for specified user.
|
||||
func (p *Persister) RecordEvent(t entity.EventType) {
|
||||
e := entity.AppEvent{}
|
||||
e.OrgID = p.Context.OrgID
|
||||
e.UserID = p.Context.UserID
|
||||
e.Created = time.Now().UTC()
|
||||
e.Type = string(t)
|
||||
|
||||
if e.OrgID == "" || e.UserID == "" {
|
||||
log.Info("Missing OrgID/UserID for event record " + e.Type)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := Db.Beginx()
|
||||
if err != nil {
|
||||
log.Error("Unable to prepare insert RecordEvent", err)
|
||||
return
|
||||
}
|
||||
|
||||
stmt, err := tx.Preparex("INSERT INTO userevent (orgid, userid, eventtype, created) VALUES (?, ?, ?, ?)")
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
log.Error("Unable to prepare insert RecordEvent", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(e.OrgID, e.UserID, e.Type, e.Created)
|
||||
if err != nil {
|
||||
log.Error("Unable to execute insert RecordEvent", err)
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
stmt.Close()
|
||||
tx.Commit()
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue