MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Restore

Method Restore

models/document_history.go:118–165  ·  view source on GitHub ↗

恢复指定历史的文档.

(historyId, docId, uid int)

Source from the content-addressed store, hash-verified

116
117//恢复指定历史的文档.
118func (history *DocumentHistory) Restore(historyId, docId, uid int) (err error) {
119 o := orm.NewOrm()
120
121 o.Begin()
122 defer func() {
123 if err != nil {
124 o.Rollback()
125 } else {
126 o.Commit()
127 }
128 }()
129
130 err = o.QueryTable(history.TableNameWithPrefix()).Filter("history_id", historyId).Filter("document_id", docId).One(history)
131 if err != nil {
132 return err
133 }
134
135 var doc *Document
136
137 doc, err = NewDocument().Find(history.DocumentId)
138 if err != nil {
139 return err
140 }
141
142 ds := DocumentStore{DocumentId: docId}
143 if err = o.Read(&ds); err != nil {
144 return err
145 }
146
147 vc := NewVersionControl(docId, history.Version)
148
149 html := vc.GetVersionContent(true)
150 md := vc.GetVersionContent(false)
151
152 ds.Markdown = md //markdown内容
153 ds.Content = html //HTML内容
154 doc.Release = html //HTML内容
155 doc.DocumentName = history.DocumentName //文件名
156 doc.Version = time.Now().Unix() //版本
157
158 _, err = o.Update(doc)
159 if err != nil {
160 return
161 }
162 _, err = o.Update(&ds)
163
164 return err
165}
166
167// 根据文档id删除记录
168func (history *DocumentHistory) DeleteByDocumentId(docId int) (err error) {

Callers 1

RestoreHistoryMethod · 0.80

Calls 7

TableNameWithPrefixMethod · 0.95
NewDocumentFunction · 0.85
NewVersionControlFunction · 0.85
GetVersionContentMethod · 0.80
FindMethod · 0.45
ReadMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected