Skip to content

Commit eb071f5

Browse files
committed
fixbug: document log add space id
1 parent 06a2033 commit eb071f5

10 files changed

Lines changed: 48 additions & 42 deletions

File tree

app/controllers/attachment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (this *AttachmentController) Upload() {
156156
"path": fmt.Sprintf("attachment/%s/%s/%s", spaceId, documentId, h.Filename),
157157
"source": models.Attachment_Source_Default,
158158
}
159-
_, err = models.AttachmentModel.Insert(attachment)
159+
_, err = models.AttachmentModel.Insert(attachment, spaceId)
160160
if err != nil {
161161
_ = os.Remove(attachmentFile)
162162
this.ErrorLog("上传附件错误: " + err.Error())
@@ -221,9 +221,9 @@ func (this *AttachmentController) Delete() {
221221
}
222222

223223
// update document log
224-
go func() {
225-
_, _ = models.LogDocumentModel.UpdateAction(this.UserId, documentId, "删除了附件 "+attachmentName)
226-
}()
224+
go func(userId string, documentId string, attachmentName string, spaceId string) {
225+
_, _ = models.LogDocumentModel.UpdateAction(userId, documentId, "删除了附件 "+attachmentName, spaceId)
226+
}(this.UserId, documentId, attachmentName, spaceId)
227227

228228
redirect := fmt.Sprintf("/attachment/page?document_id=%s", documentId)
229229
if attachmentSource == fmt.Sprintf("%d", models.Attachment_Source_Image) {

app/controllers/document.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ func (this *DocumentController) Move() {
334334
}
335335
}
336336

337-
space, err := models.SpaceModel.GetSpaceBySpaceId(document["space_id"])
337+
spaceId := document["space_id"]
338+
space, err := models.SpaceModel.GetSpaceBySpaceId(spaceId)
338339
if err != nil {
339340
this.ErrorLog("移动文档失败:" + err.Error())
340341
this.jsonError("移动文档失败!")
@@ -378,7 +379,8 @@ func (this *DocumentController) Move() {
378379
"path": targetDocument["path"] + "," + targetId,
379380
"edit_user_id": this.UserId,
380381
}
381-
_, err = models.DocumentModel.MoveDBAndFile(documentId, updateValue, oldPageFile, newPageFile, document["type"], "移动文档到 "+targetDocument["name"])
382+
_, err = models.DocumentModel.MoveDBAndFile(documentId, spaceId, updateValue,
383+
oldPageFile, newPageFile, document["type"], "移动文档到 "+targetDocument["name"])
382384
if err != nil {
383385
this.ErrorLog("移动文档 " + documentId + " 失败:" + err.Error())
384386
this.jsonError("移动文档失败!")
@@ -413,7 +415,7 @@ func (this *DocumentController) updateDocSequence(moveType string, document map[
413415
"sequence": updateSequence,
414416
"edit_user_id": this.UserId,
415417
}
416-
_, err = models.DocumentModel.Update(movedDocumentId, updateValue, fmt.Sprintf("移动文档"))
418+
_, err = models.DocumentModel.Update(movedDocumentId, updateValue, fmt.Sprintf("移动文档"), spaceId)
417419
if err != nil {
418420
this.ErrorLog("移动文档 " + movedDocumentId + "到目标文档 " + targetDocumentId + " " + moveType + " 失败:" + err.Error())
419421
this.jsonError("移动文档失败!")
@@ -447,7 +449,7 @@ func (this *DocumentController) Delete() {
447449
this.jsonError("请先删除或移动目录下所有文档!")
448450
}
449451
}
450-
452+
spaceId := document["space_id"]
451453
space, err := models.SpaceModel.GetSpaceBySpaceId(document["space_id"])
452454
if err != nil {
453455
this.ErrorLog("删除文档失败:" + err.Error())
@@ -468,7 +470,7 @@ func (this *DocumentController) Delete() {
468470
this.jsonError("删除文档失败!")
469471
}
470472

471-
err = models.DocumentModel.DeleteDBAndFile(documentId, this.UserId, pageFile, document["type"])
473+
err = models.DocumentModel.DeleteDBAndFile(documentId, spaceId, this.UserId, pageFile, document["type"])
472474
if err != nil {
473475
this.ErrorLog("删除文档 " + documentId + " 失败:" + err.Error())
474476
this.jsonError("删除文档失败!")

app/controllers/image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (this *ImageController) Upload() {
101101
"path": fmt.Sprintf("images/%s/%s/%s", spaceId, documentId, h.Filename),
102102
"source": models.Attachment_Source_Image,
103103
}
104-
_, err = models.AttachmentModel.Insert(attachment)
104+
_, err = models.AttachmentModel.Insert(attachment, spaceId)
105105
if err != nil {
106106
_ = os.Remove(imageFile)
107107
this.ErrorLog("上传图片保存信息错误: " + err.Error())

app/controllers/page.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (this *PageController) Modify() {
249249
"name": newName,
250250
"edit_user_id": this.UserId,
251251
}
252-
_, err = models.DocumentModel.UpdateDBAndFile(documentId, document, documentContent, updateValue, comment)
252+
_, err = models.DocumentModel.UpdateDBAndFile(documentId, spaceId, document, documentContent, updateValue, comment)
253253
if err != nil {
254254
this.ErrorLog("修改文档 " + documentId + " 失败:" + err.Error())
255255
this.jsonError("修改文档失败!")
@@ -271,9 +271,9 @@ func (this *PageController) Modify() {
271271
}
272272
// follow doc
273273
if isFollowDoc == "1" {
274-
go func() {
275-
_, _ = models.FollowModel.FollowDocument(this.UserId, documentId)
276-
}()
274+
go func(userId string, documentId string) {
275+
_, _ = models.FollowModel.FollowDocument(userId, documentId)
276+
}(this.UserId, documentId)
277277
}
278278
// 更新文档索引
279279
go func(documentId string) {

app/models/attachment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (a *Attachment) Delete(attachmentId string) (err error) {
151151
}
152152

153153
// insert attachment
154-
func (a *Attachment) Insert(attachmentValue map[string]interface{}) (id int64, err error) {
154+
func (a *Attachment) Insert(attachmentValue map[string]interface{}, spaceId string) (id int64, err error) {
155155

156156
attachmentValue["create_time"] = time.Now().Unix()
157157
attachmentValue["update_time"] = time.Now().Unix()
@@ -164,14 +164,14 @@ func (a *Attachment) Insert(attachmentValue map[string]interface{}) (id int64, e
164164
id = rs.LastInsertId
165165

166166
// create document log
167-
go func() {
167+
go func(attachmentValue map[string]interface{}, spaceId string) {
168168
comment := fmt.Sprintf("上传了附件 %s", attachmentValue["name"].(string))
169169
if attachmentValue["source"].(int) == Attachment_Source_Image {
170170
comment = fmt.Sprintf("上传了图片 %s", attachmentValue["name"].(string))
171171
}
172172
_, _ = LogDocumentModel.UpdateAction(attachmentValue["user_id"].(string),
173-
attachmentValue["document_id"].(string), comment)
174-
}()
173+
attachmentValue["document_id"].(string), comment, spaceId)
174+
}(attachmentValue, spaceId)
175175

176176
return
177177
}

app/models/document.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (d *Document) GetDocumentMaxSequence(parentId string, spaceId string) (sequ
157157
}
158158

159159
// delete document by document_id
160-
func (d *Document) DeleteDBAndFile(documentId string, userId string, pageFile string, docType string) (err error) {
160+
func (d *Document) DeleteDBAndFile(documentId string, spaceId string, userId string, pageFile string, docType string) (err error) {
161161
db := G.DB()
162162
tx, err := db.Begin(db.Config)
163163
if err != nil {
@@ -188,12 +188,12 @@ func (d *Document) DeleteDBAndFile(documentId string, userId string, pageFile st
188188
}
189189

190190
// create document log
191-
go func(userId, documentId string) {
192-
_, err := LogDocumentModel.DeleteAction(userId, documentId)
191+
go func(userId, documentId string, spaceId string) {
192+
_, err := LogDocumentModel.DeleteAction(userId, documentId, spaceId)
193193
if err != nil {
194194
logs.Error("delete document add log err=%s", err.Error())
195195
}
196-
}(userId, documentId)
196+
}(userId, documentId, spaceId)
197197

198198
// delete follow doc
199199
go func(documentId string) {
@@ -285,7 +285,7 @@ func (d *Document) Insert(documentValue map[string]interface{}) (id int64, err e
285285
}
286286

287287
// update document by document_id
288-
func (d *Document) Update(documentId string, documentValue map[string]interface{}, comment string) (id int64, err error) {
288+
func (d *Document) Update(documentId string, documentValue map[string]interface{}, comment string, spaceId string) (id int64, err error) {
289289
db := G.DB()
290290
var rs *mysql.ResultSet
291291
documentValue["update_time"] = time.Now().Unix()
@@ -299,12 +299,12 @@ func (d *Document) Update(documentId string, documentValue map[string]interface{
299299
id = rs.LastInsertId
300300

301301
// update document log
302-
go func(editUserId string, documentId string, comment string) {
303-
_, err := LogDocumentModel.UpdateAction(editUserId, documentId, comment)
302+
go func(editUserId string, documentId string, comment string, spaceId string) {
303+
_, err := LogDocumentModel.UpdateAction(editUserId, documentId, comment, spaceId)
304304
if err != nil {
305305
logs.Error("update document add log err=%s", err.Error())
306306
}
307-
}(documentValue["edit_user_id"].(string), documentId, comment)
307+
}(documentValue["edit_user_id"].(string), documentId, comment, spaceId)
308308

309309
// follow document
310310
go func(editUserId string, documentId string) {
@@ -340,7 +340,8 @@ func (d *Document) MoveSequenceBySpaceIdAndGtSequence(spaceId string, startSeque
340340
}
341341

342342
// move document
343-
func (d *Document) MoveDBAndFile(documentId string, updateValue map[string]interface{}, oldPageFile string, newPageFile string, docType string, comment string) (id int64, err error) {
343+
func (d *Document) MoveDBAndFile(documentId string, spaceId string, updateValue map[string]interface{},
344+
oldPageFile string, newPageFile string, docType string, comment string) (id int64, err error) {
344345

345346
db := G.DB()
346347
tx, err := db.Begin(db.Config)
@@ -370,18 +371,18 @@ func (d *Document) MoveDBAndFile(documentId string, updateValue map[string]inter
370371
}
371372

372373
// create document log
373-
go func(userId, documentId, comment string) {
374-
_, err := LogDocumentModel.UpdateAction(updateValue["edit_user_id"].(string), documentId, comment)
374+
go func(userId, documentId, comment string, spaceId string) {
375+
_, err := LogDocumentModel.UpdateAction(updateValue["edit_user_id"].(string), documentId, comment, spaceId)
375376
if err != nil {
376377
logs.Error("update document add log err=%s", err.Error())
377378
}
378-
}(updateValue["edit_user_id"].(string), documentId, comment)
379+
}(updateValue["edit_user_id"].(string), documentId, comment, spaceId)
379380

380381
return
381382
}
382383

383384
// update document by document_id
384-
func (d *Document) UpdateDBAndFile(documentId string, document map[string]string, documentContent string, updateValue map[string]interface{}, comment string) (id int64, err error) {
385+
func (d *Document) UpdateDBAndFile(documentId string, spaceId string, document map[string]string, documentContent string, updateValue map[string]interface{}, comment string) (id int64, err error) {
385386

386387
// get document page file
387388
_, oldPageFile, err := DocumentModel.GetParentDocumentsByDocument(document)
@@ -425,14 +426,14 @@ func (d *Document) UpdateDBAndFile(documentId string, document map[string]string
425426
}
426427

427428
// create document log
428-
go func() {
429-
LogDocumentModel.UpdateAction(updateValue["edit_user_id"].(string), documentId, comment)
430-
}()
429+
go func(documentId string, comment string, spaceId string) {
430+
_, _ = LogDocumentModel.UpdateAction(updateValue["edit_user_id"].(string), documentId, comment, spaceId)
431+
}(documentId, comment, spaceId)
431432

432433
// create follow doc
433-
go func() {
434-
FollowModel.CreateAutoFollowDocument(updateValue["edit_user_id"].(string), documentId)
435-
}()
434+
go func(documentId string) {
435+
_, _ = FollowModel.CreateAutoFollowDocument(updateValue["edit_user_id"].(string), documentId)
436+
}(documentId)
436437

437438
return
438439
}

app/models/log_document.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,23 @@ func (ld *LogDocument) CreateAction(userId string, documentId string, spaceId st
5555
return ld.Insert(logDocument)
5656
}
5757

58-
func (ld *LogDocument) UpdateAction(userId string, documentId string, comment string) (id int64, err error) {
58+
func (ld *LogDocument) UpdateAction(userId string, documentId string, comment string, spaceId string) (id int64, err error) {
5959
logDocument := map[string]interface{}{
6060
"user_id": userId,
6161
"document_id": documentId,
62+
"space_id": spaceId,
6263
"comment": comment,
6364
"action": LogDocument_Action_Update,
6465
"create_time": time.Now().Unix(),
6566
}
6667
return ld.Insert(logDocument)
6768
}
6869

69-
func (ld *LogDocument) DeleteAction(userId string, documentId string) (id int64, err error) {
70+
func (ld *LogDocument) DeleteAction(userId string, documentId string, spaceId string) (id int64, err error) {
7071
logDocument := map[string]interface{}{
7172
"user_id": userId,
7273
"document_id": documentId,
74+
"space_id": spaceId,
7375
"comment": "删除了该文档",
7476
"action": LogDocument_Action_Delete,
7577
"create_time": time.Now().Unix(),

app/modules/system/controllers/contact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ func (this *ContactController) Import() {
196196
this.Data["username"] = username
197197
this.SetPaginator(number, count)
198198
this.viewLayout("contact/import", "contact")
199-
}
199+
}

app/modules/system/controllers/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ func (this *PluginController) ConfigModify() {
9595
this.jsonError("修改插件配置失败")
9696
}
9797
this.jsonSuccess("修改插件配置成功", nil, "/system/plugin/list")
98-
}
98+
}

app/modules/system/controllers/space.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ func (this *SpaceController) Delete() {
303303
this.ErrorLog("删除空间 " + spaceId + " 获取空间文件失败: " + err.Error())
304304
this.jsonError("删除空间失败")
305305
}
306-
err = models.DocumentModel.DeleteDBAndFile(documents[0]["document_id"], this.UserId, pageFile, fmt.Sprintf("%d", models.Document_Type_Dir))
306+
err = models.DocumentModel.DeleteDBAndFile(documents[0]["document_id"], spaceId, this.UserId,
307+
pageFile, fmt.Sprintf("%d", models.Document_Type_Dir))
307308
// delete space document attachments
308309
_ = models.AttachmentModel.DeleteAttachmentsDBFileByDocumentId(documents[0]["document_id"])
309310
}

0 commit comments

Comments
 (0)