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

Method Replace

models/book.go:646–664  ·  view source on GitHub ↗

内容替换

(bookId int, src, dst string)

Source from the content-addressed store, hash-verified

644
645// 内容替换
646func (m *Book) Replace(bookId int, src, dst string) {
647 var docs []Document
648 o := orm.NewOrm()
649 o.QueryTable(NewDocument()).Filter("book_id", bookId).Limit(10000).All(&docs, "document_id")
650 if len(docs) > 0 {
651 for _, doc := range docs {
652 ds := new(DocumentStore)
653 o.QueryTable(ds).Filter("document_id", doc.DocumentId).One(ds)
654 if ds.DocumentId > 0 {
655 if count := strings.Count(ds.Markdown, src); count > 0 { // 如果没找到内容,则不更新这篇文章
656 ds.Markdown = strings.Replace(ds.Markdown, src, dst, count)
657 ds.Content = ""
658 ds.UpdatedAt = time.Now()
659 o.Update(ds)
660 }
661 }
662 }
663 }
664}
665
666// 根据书籍id获取(公开的)书籍
667func (m *Book) GetBooksById(id []int, fields ...string) (books []Book, err error) {

Callers 15

JoinURIFunction · 0.45
GetPagerHtmlFunction · 0.45
CrawlHtml2MarkdownFunction · 0.45
DownImageFunction · 0.45
SplitMarkdownFunction · 0.45
depressFunction · 0.45
compressFunction · 0.45
handleLiFunction · 0.45
ReplaceIdentifyMethod · 0.45
ReleaseContentMethod · 0.45
BookStackCrawlMethod · 0.45
html2TextMethod · 0.45

Calls 4

NewDocumentFunction · 0.85
AllMethod · 0.45
CountMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected