mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-19 01:58:00 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
)
|
||||
@@ -65,7 +65,7 @@ func (m *Attachment) Delete() error {
|
||||
|
||||
if err == nil {
|
||||
if err1 := os.Remove(m.FilePath); err1 != nil {
|
||||
beego.Error(err1)
|
||||
logs.Error(err1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func (m *Attachment) FindToPager(pageIndex, pageSize int) (attachList []*Attachm
|
||||
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
beego.Info("没有查到附件 ->", err)
|
||||
logs.Info("没有查到附件 ->", err)
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
|
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
)
|
||||
|
||||
|
@@ -7,8 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/mindoc-org/mindoc/cache"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
@@ -94,7 +95,7 @@ func (b *Blog) Find(blogId int) (*Blog, error) {
|
||||
|
||||
err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).One(b)
|
||||
if err != nil {
|
||||
beego.Error("查询文章时失败 -> ", err)
|
||||
logs.Error("查询文章时失败 -> ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -103,23 +104,23 @@ func (b *Blog) Find(blogId int) (*Blog, error) {
|
||||
|
||||
//从缓存中读取文章
|
||||
func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
|
||||
key := fmt.Sprintf("blog-id-%d", blogId);
|
||||
key := fmt.Sprintf("blog-id-%d", blogId)
|
||||
var temp Blog
|
||||
err = cache.Get(key, &temp);
|
||||
err = cache.Get(key, &temp)
|
||||
if err == nil {
|
||||
b = &temp
|
||||
b.Link()
|
||||
beego.Debug("从缓存读取文章成功 ->", key)
|
||||
logs.Debug("从缓存读取文章成功 ->", key)
|
||||
return b, nil
|
||||
} else {
|
||||
beego.Error("读取缓存失败 ->", err)
|
||||
logs.Error("读取缓存失败 ->", err)
|
||||
}
|
||||
|
||||
blog, err = b.Find(blogId)
|
||||
if err == nil {
|
||||
//默认一个小时
|
||||
if err := cache.Put(key, blog, time.Hour*1); err != nil {
|
||||
beego.Error("将文章存入缓存失败 ->", err)
|
||||
logs.Error("将文章存入缓存失败 ->", err)
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -131,7 +132,7 @@ func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
|
||||
|
||||
err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).Filter("member_id", memberId).One(b)
|
||||
if err != nil {
|
||||
beego.Error("查询文章时失败 -> ", err)
|
||||
logs.Error("查询文章时失败 -> ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
|
||||
|
||||
err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_identify", identify).One(b)
|
||||
if err != nil {
|
||||
beego.Error("查询文章时失败 -> ", err)
|
||||
logs.Error("查询文章时失败 -> ", err)
|
||||
return nil, err
|
||||
}
|
||||
return b, nil
|
||||
@@ -157,7 +158,7 @@ func (b *Blog) Link() (*Blog, error) {
|
||||
if b.BlogType == 1 && b.DocumentId > 0 {
|
||||
doc := NewDocument()
|
||||
if err := o.QueryTable(doc.TableNameWithPrefix()).Filter("document_id", b.DocumentId).One(doc, "release", "markdown", "identify", "book_id"); err != nil {
|
||||
beego.Error("查询文章链接对象时出错 -> ", err)
|
||||
logs.Error("查询文章链接对象时出错 -> ", err)
|
||||
} else {
|
||||
b.DocumentIdentify = doc.Identify
|
||||
b.BlogRelease = doc.Release
|
||||
@@ -166,7 +167,7 @@ func (b *Blog) Link() (*Blog, error) {
|
||||
b.BlogContent = doc.Markdown
|
||||
book := NewBook()
|
||||
if err := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id", doc.BookId).One(book, "identify"); err != nil {
|
||||
beego.Error("查询关联文档的项目时出错 ->", err)
|
||||
logs.Error("查询关联文档的项目时出错 ->", err)
|
||||
} else {
|
||||
b.BookIdentify = book.Identify
|
||||
b.BookId = doc.BookId
|
||||
@@ -174,13 +175,13 @@ func (b *Blog) Link() (*Blog, error) {
|
||||
//处理链接文档存在源文档修改时间的问题
|
||||
if content, err := goquery.NewDocumentFromReader(bytes.NewBufferString(b.BlogRelease)); err == nil {
|
||||
content.Find(".wiki-bottom").Remove()
|
||||
if html,err := content.Html();err == nil {
|
||||
if html, err := content.Html(); err == nil {
|
||||
b.BlogRelease = html
|
||||
} else {
|
||||
beego.Error("处理文章失败 ->",err)
|
||||
logs.Error("处理文章失败 ->", err)
|
||||
}
|
||||
}else {
|
||||
beego.Error("处理文章失败 ->",err)
|
||||
} else {
|
||||
logs.Error("处理文章失败 ->", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,7 +225,7 @@ func (b *Blog) Save(cols ...string) error {
|
||||
if b.OrderIndex <= 0 {
|
||||
blog := NewBlog()
|
||||
if err := o.QueryTable(blog.TableNameWithPrefix()).OrderBy("-blog_id").Limit(1).One(blog, "blog_id"); err == nil {
|
||||
b.OrderIndex = blog.BlogId + 1;
|
||||
b.OrderIndex = blog.BlogId + 1
|
||||
} else {
|
||||
c, _ := o.QueryTable(b.TableNameWithPrefix()).Count()
|
||||
b.OrderIndex = int(c) + 1
|
||||
@@ -260,7 +261,7 @@ func (b *Blog) Processor() *Blog {
|
||||
content.Find("a").Each(func(i int, contentSelection *goquery.Selection) {
|
||||
if src, ok := contentSelection.Attr("href"); ok {
|
||||
if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") {
|
||||
//beego.Info(src,conf.BaseUrl,strings.HasPrefix(src,conf.BaseUrl))
|
||||
//logs.Info(src,conf.BaseUrl,strings.HasPrefix(src,conf.BaseUrl))
|
||||
if conf.BaseUrl != "" && !strings.HasPrefix(src, conf.BaseUrl) {
|
||||
contentSelection.SetAttr("target", "_blank")
|
||||
if html, err := content.Html(); err == nil {
|
||||
@@ -272,7 +273,7 @@ func (b *Blog) Processor() *Blog {
|
||||
}
|
||||
})
|
||||
//设置图片为CDN地址
|
||||
if cdnimg := beego.AppConfig.String("cdnimg"); cdnimg != "" {
|
||||
if cdnimg, _ := web.AppConfig.String("cdnimg"); cdnimg != "" {
|
||||
content.Find("img").Each(func(i int, contentSelection *goquery.Selection) {
|
||||
if src, ok := contentSelection.Attr("src"); ok && strings.HasPrefix(src, "/uploads/") {
|
||||
contentSelection.SetAttr("src", utils.JoinURI(cdnimg, src))
|
||||
@@ -306,13 +307,13 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
|
||||
if err == orm.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
beego.Error("获取文章列表时出错 ->", err)
|
||||
logs.Error("获取文章列表时出错 ->", err)
|
||||
return
|
||||
}
|
||||
count, err := query.Count()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("获取文章数量时出错 ->", err)
|
||||
logs.Error("获取文章数量时出错 ->", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
totalCount = int(count)
|
||||
@@ -331,7 +332,7 @@ func (b *Blog) Delete(blogId int) error {
|
||||
|
||||
_, err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).Delete()
|
||||
if err != nil {
|
||||
beego.Error("删除文章失败 ->", err)
|
||||
logs.Error("删除文章失败 ->", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -342,14 +343,14 @@ func (b *Blog) QueryNext(blogId int) (*Blog, error) {
|
||||
blog := NewBlog()
|
||||
|
||||
if err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).One(blog, "order_index"); err != nil {
|
||||
beego.Error("查询文章时出错 ->", err)
|
||||
logs.Error("查询文章时出错 ->", err)
|
||||
return b, err
|
||||
}
|
||||
|
||||
err := o.QueryTable(b.TableNameWithPrefix()).Filter("order_index__gte", blog.OrderIndex).Filter("blog_id__gt", blogId).OrderBy("order_index", "blog_id").One(blog)
|
||||
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("查询文章时出错 ->", err)
|
||||
logs.Error("查询文章时出错 ->", err)
|
||||
}
|
||||
return blog, err
|
||||
}
|
||||
@@ -360,14 +361,14 @@ func (b *Blog) QueryPrevious(blogId int) (*Blog, error) {
|
||||
blog := NewBlog()
|
||||
|
||||
if err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).One(blog, "order_index"); err != nil {
|
||||
beego.Error("查询文章时出错 ->", err)
|
||||
logs.Error("查询文章时出错 ->", err)
|
||||
return b, err
|
||||
}
|
||||
|
||||
err := o.QueryTable(b.TableNameWithPrefix()).Filter("order_index__lte", blog.OrderIndex).Filter("blog_id__lt", blogId).OrderBy("-order_index", "-blog_id").One(blog)
|
||||
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("查询文章时出错 ->", err)
|
||||
logs.Error("查询文章时出错 ->", err)
|
||||
}
|
||||
return blog, err
|
||||
}
|
||||
@@ -382,13 +383,13 @@ func (b *Blog) LinkAttach() (err error) {
|
||||
if b.BlogType != 1 || b.DocumentId <= 0 {
|
||||
_, err = o.QueryTable(NewAttachment().TableNameWithPrefix()).Filter("document_id", b.BlogId).Filter("book_id", 0).All(&attachList)
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("查询文章附件时出错 ->", err)
|
||||
logs.Error("查询文章附件时出错 ->", err)
|
||||
}
|
||||
} else {
|
||||
_, err = o.QueryTable(NewAttachment().TableNameWithPrefix()).Filter("document_id", b.DocumentId).Filter("book_id", b.BookId).All(&attachList)
|
||||
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("查询文章附件时出错 ->", err)
|
||||
logs.Error("查询文章附件时出错 ->", err)
|
||||
}
|
||||
}
|
||||
b.AttachList = attachList
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -16,16 +17,15 @@ import (
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
"github.com/mindoc-org/mindoc/utils/requests"
|
||||
"github.com/mindoc-org/mindoc/utils/ziptil"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
var releaseQueue = make(chan int, 500)
|
||||
@@ -194,11 +194,11 @@ func (book *Book) Copy(identify string) error {
|
||||
err := o.QueryTable(book.TableNameWithPrefix()).Filter("identify", identify).One(book)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询项目时出错 -> ", err)
|
||||
logs.Error("查询项目时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
if err := o.Begin(); err != nil {
|
||||
beego.Error("开启事物时出错 -> ", err)
|
||||
if _, err := o.Begin(); err != nil {
|
||||
logs.Error("开启事物时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -210,49 +210,87 @@ func (book *Book) Copy(identify string) error {
|
||||
book.CommentCount = 0
|
||||
book.HistoryCount = 0
|
||||
|
||||
if _, err := o.Insert(book); err != nil {
|
||||
beego.Error("复制项目时出错 -> ", err)
|
||||
o.Rollback()
|
||||
/* v2 version of beego remove the o.Rollback api for transaction operation.
|
||||
* typically, in v1, you can write code like this:
|
||||
*
|
||||
* o := orm.NewOrm()
|
||||
* if err := o.Operateion(); err != nil {
|
||||
* o.Rollback()
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* however, in v2, this is not available. beego will handles the transaction in new way using
|
||||
* cluster. the new code is like below:
|
||||
*
|
||||
* o := orm.NewOrm()
|
||||
* if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error{
|
||||
* err := o.Operations()
|
||||
* if err != nil {
|
||||
* return err
|
||||
* }
|
||||
* ...
|
||||
* }); err != nil {
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* when operation failed, it will automatically calls o.Rollback() for TxOrmer.
|
||||
* more details see https://beego.me/docs/mvc/model/transaction.md
|
||||
*/
|
||||
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||
_, err := txo.Insert(book)
|
||||
return err
|
||||
|
||||
}); err != nil {
|
||||
logs.Error("复制项目时出错: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
var rels []*Relationship
|
||||
|
||||
if _, err := o.QueryTable(NewRelationship().TableNameWithPrefix()).Filter("book_id", bookId).All(&rels); err != nil {
|
||||
beego.Error("复制项目关系时出错 -> ", err)
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||
_, err := txo.QueryTable(NewRelationship().TableNameWithPrefix()).Filter("book_id", bookId).All(&rels)
|
||||
return err
|
||||
}); err != nil {
|
||||
logs.Error("复制项目关系时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range rels {
|
||||
rel.BookId = book.BookId
|
||||
rel.RelationshipId = 0
|
||||
if _, err := o.Insert(rel); err != nil {
|
||||
beego.Error("复制项目关系时出错 -> ", err)
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||
_, err := txo.Insert(rel)
|
||||
return err
|
||||
}); err != nil {
|
||||
logs.Error("复制项目关系时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var docs []*Document
|
||||
|
||||
if _, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", 0).All(&docs); err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("读取项目文档时出错 -> ", err)
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err := txOrm.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", 0).All(&docs)
|
||||
return err
|
||||
}); err != nil && err != orm.ErrNoRows {
|
||||
logs.Error("读取项目文档时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if len(docs) > 0 {
|
||||
if err := recursiveInsertDocument(docs, o, book.BookId, 0); err != nil {
|
||||
beego.Error("复制项目时出错 -> ", err)
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
return recursiveInsertDocument(docs, txOrm, book.BookId, 0)
|
||||
}); err != nil {
|
||||
logs.Error("复制项目时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return o.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
//递归的复制文档
|
||||
func recursiveInsertDocument(docs []*Document, o orm.Ormer, bookId int, parentId int) error {
|
||||
func recursiveInsertDocument(docs []*Document, o orm.TxOrmer, bookId int, parentId int) error {
|
||||
for _, doc := range docs {
|
||||
|
||||
docId := doc.DocumentId
|
||||
@@ -262,7 +300,7 @@ func recursiveInsertDocument(docs []*Document, o orm.Ormer, bookId int, parentId
|
||||
doc.Version = time.Now().Unix()
|
||||
|
||||
if _, err := o.Insert(doc); err != nil {
|
||||
beego.Error("插入项目时出错 -> ", err)
|
||||
logs.Error("插入项目时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -281,7 +319,7 @@ func recursiveInsertDocument(docs []*Document, o orm.Ormer, bookId int, parentId
|
||||
var subDocs []*Document
|
||||
|
||||
if _, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("parent_id", docId).All(&subDocs); err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("读取文档时出错 -> ", err)
|
||||
logs.Error("读取文档时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
if len(subDocs) > 0 {
|
||||
@@ -419,42 +457,49 @@ func (book *Book) ThoroughDeleteBook(id int) error {
|
||||
o.Begin()
|
||||
|
||||
//删除附件,这里没有删除实际物理文件
|
||||
_, err = o.Raw("DELETE FROM "+NewAttachment().TableNameWithPrefix()+" WHERE book_id=?", book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewAttachment().TableNameWithPrefix()+" WHERE book_id=?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//删除文档
|
||||
_, err = o.Raw("DELETE FROM "+NewDocument().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewDocument().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
//删除项目
|
||||
_, err = o.Raw("DELETE FROM "+book.TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+book.TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//删除关系
|
||||
_, err = o.Raw("DELETE FROM "+NewRelationship().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewRelationship().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = o.Raw(fmt.Sprintf("DELETE FROM %s WHERE book_id=?", NewTeamRelationship().TableNameWithPrefix()), book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw(fmt.Sprintf("DELETE FROM %s WHERE book_id=?", NewTeamRelationship().TableNameWithPrefix()), book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
//删除模板
|
||||
_, err = o.Raw("DELETE FROM "+NewTemplate().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewTemplate().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -464,14 +509,14 @@ func (book *Book) ThoroughDeleteBook(id int) error {
|
||||
|
||||
//删除导出缓存
|
||||
if err := os.RemoveAll(filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(id))); err != nil {
|
||||
beego.Error("删除项目缓存失败 ->", err)
|
||||
logs.Error("删除项目缓存失败 ->", err)
|
||||
}
|
||||
//删除附件和图片
|
||||
if err := os.RemoveAll(filepath.Join(conf.WorkingDirectory, "uploads", book.Identify)); err != nil {
|
||||
beego.Error("删除项目附件和图片失败 ->", err)
|
||||
logs.Error("删除项目附件和图片失败 ->", err)
|
||||
}
|
||||
|
||||
return o.Commit()
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
@@ -592,7 +637,7 @@ func (book *Book) ReleaseContent(bookId int) {
|
||||
go func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
beego.Error("协程崩溃 ->", err)
|
||||
logs.Error("协程崩溃 ->", err)
|
||||
}
|
||||
}()
|
||||
for bookId := range releaseQueue {
|
||||
@@ -602,7 +647,7 @@ func (book *Book) ReleaseContent(bookId int) {
|
||||
_, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).All(&docs)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("发布失败 =>", bookId, err)
|
||||
logs.Error("发布失败 =>", bookId, err)
|
||||
continue
|
||||
}
|
||||
for _, item := range docs {
|
||||
@@ -626,10 +671,10 @@ func (book *Book) ResetDocumentNumber(bookId int) {
|
||||
if err == nil {
|
||||
_, err = o.Raw("UPDATE md_books SET doc_count = ? WHERE book_id = ?", int(totalCount), bookId).Exec()
|
||||
if err != nil {
|
||||
beego.Error("重置文档数量失败 =>", bookId, err)
|
||||
logs.Error("重置文档数量失败 =>", bookId, err)
|
||||
}
|
||||
} else {
|
||||
beego.Error("获取文档数量失败 =>", bookId, err)
|
||||
logs.Error("获取文档数量失败 =>", bookId, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,7 +693,7 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
tempPath := filepath.Join(os.TempDir(), md5str)
|
||||
|
||||
if err := os.MkdirAll(tempPath, 0766); err != nil {
|
||||
beego.Error("创建导入目录出错 => ", err)
|
||||
logs.Error("创建导入目录出错 => ", err)
|
||||
}
|
||||
//如果加压缩失败
|
||||
if err := ziptil.Unzip(zipPath, tempPath); err != nil {
|
||||
@@ -693,7 +738,7 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
ext := filepath.Ext(info.Name())
|
||||
//如果是Markdown文件
|
||||
if strings.EqualFold(ext, ".md") || strings.EqualFold(ext, ".markdown") {
|
||||
beego.Info("正在处理 =>", path, info.Name())
|
||||
logs.Info("正在处理 =>", path, info.Name())
|
||||
doc := NewDocument()
|
||||
doc.BookId = book.BookId
|
||||
doc.MemberId = book.MemberId
|
||||
@@ -796,11 +841,11 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
//如果本地存在该链接
|
||||
if filetil.FileExists(linkPath) {
|
||||
ext := filepath.Ext(linkPath)
|
||||
//beego.Info("当前后缀 -> ",ext)
|
||||
//logs.Info("当前后缀 -> ",ext)
|
||||
//如果链接是Markdown文件,则生成文档标识,否则,将目标文件复制到项目目录
|
||||
if strings.EqualFold(ext, ".md") || strings.EqualFold(ext, ".markdown") {
|
||||
docIdentify := strings.Replace(strings.TrimPrefix(strings.Replace(linkPath, "\\", "/", -1), tempPath+"/"), "/", "-", -1)
|
||||
//beego.Info(originalLink, "|", linkPath, "|", docIdentify)
|
||||
//logs.Info(originalLink, "|", linkPath, "|", docIdentify)
|
||||
if ok, err := regexp.MatchString(`[a-z]+[a-zA-Z0-9_.\-]*$`, docIdentify); !ok || err != nil {
|
||||
docIdentify = "import-" + docIdentify
|
||||
}
|
||||
@@ -819,7 +864,7 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
|
||||
}
|
||||
} else {
|
||||
beego.Info("文件不存在 ->", linkPath)
|
||||
logs.Info("文件不存在 ->", linkPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -829,7 +874,7 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
//codeRe := regexp.MustCompile("```\\w+")
|
||||
|
||||
//doc.Markdown = codeRe.ReplaceAllStringFunc(doc.Markdown, func(s string) string {
|
||||
// //beego.Info(s)
|
||||
// //logs.Info(s)
|
||||
// return strings.Replace(s,"```","``` ",-1)
|
||||
//})
|
||||
|
||||
@@ -863,21 +908,21 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
}
|
||||
}
|
||||
if strings.EqualFold(info.Name(), "README.md") {
|
||||
beego.Info(path, "|", info.Name(), "|", parentIdentify, "|", parentId)
|
||||
logs.Info(path, "|", info.Name(), "|", parentIdentify, "|", parentId)
|
||||
}
|
||||
isInsert := false
|
||||
//如果当前文件是README.md,则将内容更新到父级
|
||||
if strings.EqualFold(info.Name(), "README.md") && parentId != 0 {
|
||||
|
||||
doc.DocumentId = parentId
|
||||
//beego.Info(path,"|",parentId)
|
||||
//logs.Info(path,"|",parentId)
|
||||
} else {
|
||||
//beego.Info(path,"|",parentIdentify)
|
||||
//logs.Info(path,"|",parentIdentify)
|
||||
doc.ParentId = parentId
|
||||
isInsert = true
|
||||
}
|
||||
if err := doc.InsertOrUpdate("document_name", "markdown", "content"); err != nil {
|
||||
beego.Error(doc.DocumentId, err)
|
||||
logs.Error(doc.DocumentId, err)
|
||||
}
|
||||
if isInsert {
|
||||
docMap[docIdentify] = doc.DocumentId
|
||||
@@ -886,7 +931,7 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
} else {
|
||||
//如果当前目录下存在Markdown文件,则需要创建此节点
|
||||
if filetil.HasFileOfExt(path, []string{".md", ".markdown"}) {
|
||||
beego.Info("正在处理 =>", path, info.Name())
|
||||
logs.Info("正在处理 =>", path, info.Name())
|
||||
identify := strings.Replace(strings.Trim(strings.TrimPrefix(path, tempPath), "/"), "/", "-", -1)
|
||||
if ok, err := regexp.MatchString(`[a-z]+[a-zA-Z0-9_.\-]*$`, identify); !ok || err != nil {
|
||||
identify = "import-" + identify
|
||||
@@ -911,11 +956,11 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
parentDoc.ParentId = parentId
|
||||
|
||||
if err := parentDoc.InsertOrUpdate(); err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
}
|
||||
|
||||
docMap[identify] = parentDoc.DocumentId
|
||||
//beego.Info(path,"|",parentDoc.DocumentId,"|",identify,"|",info.Name(),"|",parentIdentify)
|
||||
//logs.Info(path,"|",parentDoc.DocumentId,"|",identify,"|",info.Name(),"|",parentIdentify)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -923,10 +968,10 @@ func (book *Book) ImportBook(zipPath string) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
beego.Error("导入项目异常 => ", err)
|
||||
logs.Error("导入项目异常 => ", err)
|
||||
book.Description = "【项目导入存在错误:" + err.Error() + "】"
|
||||
}
|
||||
beego.Info("项目导入完毕 => ", book.BookName)
|
||||
logs.Info("项目导入完毕 => ", book.BookName)
|
||||
book.ReleaseContent(book.BookId)
|
||||
return err
|
||||
}
|
||||
@@ -953,7 +998,7 @@ where mtr.book_id = ? and mtm.member_id = ? order by mtm.role_id asc limit 1;`
|
||||
err = o.Raw(sql, bookId, memberId).QueryRow(&roleId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询用户项目角色出错 -> book_id=", bookId, " member_id=", memberId, err)
|
||||
logs.Error("查询用户项目角色出错 -> book_id=", bookId, " member_id=", memberId, err)
|
||||
return 0, err
|
||||
}
|
||||
return conf.BookRole(roleId), nil
|
||||
|
@@ -14,9 +14,9 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/converter"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/mindoc-org/mindoc/utils/gopool"
|
||||
"github.com/mindoc-org/mindoc/utils/requests"
|
||||
"github.com/mindoc-org/mindoc/utils/ziptil"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -97,7 +97,7 @@ func (m *BookResult) FindByIdentify(identify string, memberId int) (*BookResult,
|
||||
err := NewBook().QueryTable().Filter("identify", identify).One(&book)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("获取项目失败 ->", err)
|
||||
logs.Error("获取项目失败 ->", err)
|
||||
return m, err
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
|
||||
}
|
||||
|
||||
if m.ItemId > 0 {
|
||||
if item,err := NewItemsets().First(m.ItemId); err == nil {
|
||||
if item, err := NewItemsets().First(m.ItemId); err == nil {
|
||||
m.ItemName = item.ItemName
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
|
||||
func BackgroundConvert(sessionId string, bookResult *BookResult) error {
|
||||
|
||||
if err := converter.CheckConvertCommand(); err != nil {
|
||||
beego.Error("检查转换程序失败 -> ", err)
|
||||
logs.Error("检查转换程序失败 -> ", err)
|
||||
return err
|
||||
}
|
||||
err := exportLimitWorkerChannel.LoadOrStore(bookResult.Identify, func() {
|
||||
@@ -260,7 +260,7 @@ func BackgroundConvert(sessionId string, bookResult *BookResult) error {
|
||||
|
||||
if err != nil {
|
||||
|
||||
beego.Error("将导出任务加入任务队列失败 -> ", err)
|
||||
logs.Error("将导出任务加入任务队列失败 -> ", err)
|
||||
return err
|
||||
}
|
||||
exportLimitWorkerChannel.Start()
|
||||
@@ -273,7 +273,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
convertBookResult := ConvertBookResult{}
|
||||
|
||||
outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(m.BookId))
|
||||
viewPath := beego.BConfig.WebConfig.ViewsPath
|
||||
viewPath := web.BConfig.WebConfig.ViewsPath
|
||||
|
||||
pdfpath := filepath.Join(outputPath, "book.pdf")
|
||||
epubpath := filepath.Join(outputPath, "book.epub")
|
||||
@@ -286,15 +286,15 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
sourceDir := strings.TrimSuffix(tempOutputPath, "source")
|
||||
if filetil.FileExists(sourceDir) {
|
||||
if err := os.RemoveAll(sourceDir); err != nil {
|
||||
beego.Error("删除临时目录失败 ->", sourceDir, err)
|
||||
logs.Error("删除临时目录失败 ->", sourceDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(outputPath, 0766); err != nil {
|
||||
beego.Error("创建目录失败 -> ", outputPath, err)
|
||||
logs.Error("创建目录失败 -> ", outputPath, err)
|
||||
}
|
||||
if err := os.MkdirAll(tempOutputPath, 0766); err != nil {
|
||||
beego.Error("创建目录失败 -> ", tempOutputPath, err)
|
||||
logs.Error("创建目录失败 -> ", tempOutputPath, err)
|
||||
}
|
||||
os.MkdirAll(filepath.Join(tempOutputPath, "Images"), 0755)
|
||||
|
||||
@@ -370,7 +370,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
|
||||
if tempOutputPath, err = filepath.Abs(tempOutputPath); err != nil {
|
||||
beego.Error("导出目录配置错误:" + err.Error())
|
||||
logs.Error("导出目录配置错误:" + err.Error())
|
||||
return convertBookResult, err
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := beego.ExecuteViewPathTemplate(&buf, "document/export.tpl", viewPath, map[string]interface{}{"Model": m, "Lists": item, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
if err := web.ExecuteViewPathTemplate(&buf, "document/export.tpl", viewPath, map[string]interface{}{"Model": m, "Lists": item, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
return convertBookResult, err
|
||||
}
|
||||
html := buf.String()
|
||||
@@ -407,7 +407,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
if strings.HasPrefix(src, "/") {
|
||||
spath := filepath.Join(conf.WorkingDirectory, src)
|
||||
if filetil.CopyFile(spath, filepath.Join(tempOutputPath, dstSrcString)); err != nil {
|
||||
beego.Error("复制图片失败 -> ", err, src)
|
||||
logs.Error("复制图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -426,15 +426,15 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
if body, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||
//encodeString = base64.StdEncoding.EncodeToString(body)
|
||||
if err := ioutil.WriteFile(filepath.Join(tempOutputPath, dstSrcString), body, 0755); err != nil {
|
||||
beego.Error("下载图片失败 -> ", err, src)
|
||||
logs.Error("下载图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
beego.Error("下载图片失败 -> ", err, src)
|
||||
logs.Error("下载图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
beego.Error("下载图片失败 -> ", err, src)
|
||||
logs.Error("下载图片失败 -> ", err, src)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -457,27 +457,27 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "kancloud.css"), filepath.Join(tempOutputPath, "styles", "css", "kancloud.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/css/kancloud.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/css/kancloud.css", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "export.css"), filepath.Join(tempOutputPath, "styles", "css", "export.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/css/export.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/css/export.css", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "css", "editormd.preview.css"), filepath.Join(tempOutputPath, "styles", "editor.md", "css", "editormd.preview.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/editor.md/css/editormd.preview.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/editor.md/css/editormd.preview.css", err)
|
||||
}
|
||||
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "markdown.preview.css"), filepath.Join(tempOutputPath, "styles", "css", "markdown.preview.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/css/markdown.preview.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/css/markdown.preview.css", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "lib", "highlight", "styles", "github.css"), filepath.Join(tempOutputPath, "styles", "css", "github.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/editor.md/lib/highlight/styles/github.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/editor.md/lib/highlight/styles/github.css", err)
|
||||
}
|
||||
|
||||
if err := filetil.CopyDir(filepath.Join(conf.WorkingDirectory, "static", "font-awesome"), filepath.Join(tempOutputPath, "styles", "font-awesome")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/font-awesome", err)
|
||||
logs.Error("复制CSS样式出错 -> static/font-awesome", err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "lib", "mermaid", "mermaid.css"), filepath.Join(tempOutputPath, "styles", "css", "mermaid.css")); err != nil {
|
||||
beego.Error("复制CSS样式出错 -> static/editor.md/lib/mermaid/mermaid.css", err)
|
||||
logs.Error("复制CSS样式出错 -> static/editor.md/lib/mermaid/mermaid.css", err)
|
||||
}
|
||||
|
||||
eBookConverter := &converter.Converter{
|
||||
@@ -491,22 +491,22 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
os.MkdirAll(eBookConverter.OutputPath, 0766)
|
||||
|
||||
if err := eBookConverter.Convert(); err != nil {
|
||||
beego.Error("转换文件错误:" + m.BookName + " -> " + err.Error())
|
||||
logs.Error("转换文件错误:" + m.BookName + " -> " + err.Error())
|
||||
return convertBookResult, err
|
||||
}
|
||||
beego.Info("文档转换完成:" + m.BookName)
|
||||
logs.Info("文档转换完成:" + m.BookName)
|
||||
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), mobipath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.mobi"), err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.pdf"), pdfpath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.pdf"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.pdf"), err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.epub"), epubpath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.epub"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.epub"), err)
|
||||
}
|
||||
if err := filetil.CopyFile(filepath.Join(eBookConverter.OutputPath, "output", "book.docx"), docxpath); err != nil {
|
||||
beego.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.docx"), err)
|
||||
logs.Error("复制文档失败 -> ", filepath.Join(eBookConverter.OutputPath, "output", "book.docx"), err)
|
||||
}
|
||||
|
||||
convertBookResult.MobiPath = mobipath
|
||||
@@ -536,7 +536,7 @@ func (m *BookResult) ExportMarkdown(sessionId string) (string, error) {
|
||||
}
|
||||
|
||||
if err := ziptil.Compress(outputPath, tempOutputPath); err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return "", err
|
||||
}
|
||||
return outputPath, nil
|
||||
@@ -551,7 +551,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
_, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", parentId).All(&docs)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return err
|
||||
}
|
||||
for _, doc := range docs {
|
||||
@@ -559,7 +559,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
subDocCount, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("parent_id", doc.DocumentId).Count()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -634,13 +634,13 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
if id, err := strconv.Atoi(docIdentify); err == nil && id > 0 {
|
||||
err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("document_id", id).One(tempDoc, "identify", "parent_id", "document_id")
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
return link
|
||||
}
|
||||
} else {
|
||||
err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("identify", docIdentify).One(tempDoc, "identify", "parent_id", "document_id")
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
return link
|
||||
}
|
||||
}
|
||||
@@ -655,7 +655,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
relative = strings.TrimSuffix(strings.TrimPrefix(relative, "/"), "/")
|
||||
repeat = strings.Count(relative, "/") + 1
|
||||
}
|
||||
beego.Info(repeat, "|", relative, "|", p, "|", baseDir)
|
||||
logs.Info(repeat, "|", relative, "|", p, "|", baseDir)
|
||||
tempLink = strings.Repeat("../", repeat) + tempLink
|
||||
|
||||
link = strings.TrimSuffix(link, originalLink+")") + tempLink + ")"
|
||||
@@ -669,7 +669,7 @@ func exportMarkdown(p string, parentId int, bookId int, baseDir string, bookUrl
|
||||
markdown = "# " + doc.DocumentName + "\n"
|
||||
}
|
||||
if err := ioutil.WriteFile(docPath, []byte(markdown), 0644); err != nil {
|
||||
beego.Error("导出Markdown失败->", err)
|
||||
logs.Error("导出Markdown失败->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ func recursiveJoinDocumentIdentify(parentDocId int, identify string) string {
|
||||
err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("document_id", parentDocId).One(doc, "identify", "parent_id", "document_id")
|
||||
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
return identify
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
import "github.com/astaxie/beego/orm"
|
||||
import "github.com/beego/beego/v2/client/orm"
|
||||
|
||||
type Dashboard struct {
|
||||
BookNumber int64 `json:"book_number"`
|
||||
|
@@ -3,8 +3,8 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ type DocumentHistory struct {
|
||||
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
||||
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
||||
Version int64 `orm:"type(bigint);column(version)" json:"version"`
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
}
|
||||
|
||||
type DocumentHistorySimpleResult struct {
|
||||
@@ -127,22 +127,22 @@ func (m *DocumentHistory) InsertOrUpdate() (history *DocumentHistory, err error)
|
||||
} else {
|
||||
_, err = o.Insert(m)
|
||||
if err == nil {
|
||||
if doc,e := NewDocument().Find(m.DocumentId);e == nil {
|
||||
if book,e := NewBook().Find(doc.BookId);e == nil && book.HistoryCount > 0 {
|
||||
if doc, e := NewDocument().Find(m.DocumentId); e == nil {
|
||||
if book, e := NewBook().Find(doc.BookId); e == nil && book.HistoryCount > 0 {
|
||||
//如果已存在的历史记录大于指定的记录,则清除旧记录
|
||||
if c,e := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc.DocumentId).Count(); e == nil && c > int64(book.HistoryCount) {
|
||||
if c, e := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc.DocumentId).Count(); e == nil && c > int64(book.HistoryCount) {
|
||||
|
||||
count := c - int64(book.HistoryCount)
|
||||
beego.Info("需要删除的历史文档数量:" ,count)
|
||||
logs.Info("需要删除的历史文档数量:", count)
|
||||
var lists []DocumentHistory
|
||||
|
||||
if _,e := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc.DocumentId).OrderBy("history_id").Limit(count).All(&lists,"history_id"); e == nil {
|
||||
for _,d := range lists {
|
||||
if _, e := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc.DocumentId).OrderBy("history_id").Limit(count).All(&lists, "history_id"); e == nil {
|
||||
for _, d := range lists {
|
||||
o.Delete(&d)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
beego.Info(book.HistoryCount)
|
||||
} else {
|
||||
logs.Info(book.HistoryCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,8 +12,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/mindoc-org/mindoc/cache"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
@@ -143,7 +144,7 @@ func (item *Document) RecursiveDocument(docId int) error {
|
||||
|
||||
_, err := o.Raw("SELECT document_id FROM " + item.TableNameWithPrefix() + " WHERE parent_id=" + strconv.Itoa(docId)).Values(&maps)
|
||||
if err != nil {
|
||||
beego.Error("RecursiveDocument => ", err)
|
||||
logs.Error("RecursiveDocument => ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -165,11 +166,11 @@ func (item *Document) PutToCache() {
|
||||
if m.Identify == "" {
|
||||
|
||||
if err := cache.Put("Document.Id."+strconv.Itoa(m.DocumentId), m, time.Second*3600); err != nil {
|
||||
beego.Info("文档缓存失败:", m.DocumentId)
|
||||
logs.Info("文档缓存失败:", m.DocumentId)
|
||||
}
|
||||
} else {
|
||||
if err := cache.Put(fmt.Sprintf("Document.BookId.%d.Identify.%s", m.BookId, m.Identify), m, time.Second*3600); err != nil {
|
||||
beego.Info("文档缓存失败:", m.DocumentId)
|
||||
logs.Info("文档缓存失败:", m.DocumentId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +192,7 @@ func (item *Document) RemoveCache() {
|
||||
func (item *Document) FromCacheById(id int) (*Document, error) {
|
||||
|
||||
if err := cache.Get("Document.Id."+strconv.Itoa(id), &item); err == nil && item.DocumentId > 0 {
|
||||
beego.Info("从缓存中获取文档信息成功 ->", item.DocumentId)
|
||||
logs.Info("从缓存中获取文档信息成功 ->", item.DocumentId)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
@@ -212,7 +213,7 @@ func (item *Document) FromCacheByIdentify(identify string, bookId int) (*Documen
|
||||
key := fmt.Sprintf("Document.BookId.%d.Identify.%s", bookId, identify)
|
||||
|
||||
if err := cache.Get(key, item); err == nil && item.DocumentId > 0 {
|
||||
beego.Info("从缓存中获取文档信息成功 ->", key)
|
||||
logs.Info("从缓存中获取文档信息成功 ->", key)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
@@ -248,14 +249,14 @@ func (item *Document) ReleaseContent() error {
|
||||
err := item.Processor().InsertOrUpdate("release")
|
||||
|
||||
if err != nil {
|
||||
beego.Error(fmt.Sprintf("发布失败 -> %+v", item), err)
|
||||
logs.Error(fmt.Sprintf("发布失败 -> %+v", item), err)
|
||||
return err
|
||||
}
|
||||
//当文档发布后,需要清除已缓存的转换文档和文档缓存
|
||||
item.RemoveCache()
|
||||
|
||||
if err := os.RemoveAll(filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(item.BookId))); err != nil {
|
||||
beego.Error("删除已缓存的文档目录失败 -> ", filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(item.BookId)))
|
||||
logs.Error("删除已缓存的文档目录失败 -> ", filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(item.BookId)))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -334,7 +335,7 @@ func (item *Document) Processor() *Document {
|
||||
selector.First().AppendHtml(release)
|
||||
}
|
||||
}
|
||||
cdnimg := beego.AppConfig.String("cdnimg")
|
||||
cdnimg,_ := web.AppConfig.String("cdnimg")
|
||||
|
||||
docQuery.Find("img").Each(func(i int, selection *goquery.Selection) {
|
||||
|
||||
@@ -361,7 +362,7 @@ func (item *Document) Processor() *Document {
|
||||
selection.SetAttr("href", "#")
|
||||
return
|
||||
}
|
||||
val = strings.Replace(strings.ToLower(val), " ", "",-1)
|
||||
val = strings.Replace(strings.ToLower(val), " ", "", -1)
|
||||
//移除危险脚本链接
|
||||
if strings.HasPrefix(val, "data:text/html") ||
|
||||
strings.HasPrefix(val, "vbscript:") ||
|
||||
|
@@ -3,9 +3,10 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/astaxie/beego"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
)
|
||||
|
||||
type DocumentSearchResult struct {
|
||||
@@ -33,7 +34,7 @@ func (m *DocumentSearchResult) FindToPager(keyword string, pageIndex, pageSize,
|
||||
|
||||
offset := (pageIndex - 1) * pageSize
|
||||
|
||||
keyword = "%" + strings.Replace(keyword," ","%",-1) + "%"
|
||||
keyword = "%" + strings.Replace(keyword, " ", "%", -1) + "%"
|
||||
|
||||
if memberId <= 0 {
|
||||
sql1 := `SELECT count(doc.document_id) as total_count FROM md_documents AS doc
|
||||
@@ -99,7 +100,7 @@ LIMIT ?, ?;`
|
||||
|
||||
err = o.Raw(sql1, keyword, keyword).QueryRow(&totalCount)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
logs.Error("查询搜索结果失败 -> ", err)
|
||||
return
|
||||
}
|
||||
sql3 := ` SELECT
|
||||
@@ -110,7 +111,7 @@ LIMIT ?, ?;`
|
||||
c := 0
|
||||
err = o.Raw(sql3, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
logs.Error("查询搜索结果失败 -> ", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -121,15 +122,15 @@ WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LI
|
||||
|
||||
err = o.Raw(sql4, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
logs.Error("查询搜索结果失败 -> ", err)
|
||||
return
|
||||
}
|
||||
|
||||
totalCount += c
|
||||
|
||||
_, err = o.Raw(sql2, keyword, keyword,keyword,keyword,keyword,keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
_, err = o.Raw(sql2, keyword, keyword, keyword, keyword, keyword, keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
logs.Error("查询搜索结果失败 -> ", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
@@ -236,9 +237,9 @@ LIMIT ?, ?;`
|
||||
(blog.blog_release LIKE ? OR blog.blog_title LIKE ?);`
|
||||
|
||||
c := 0
|
||||
err = o.Raw(sql3,memberId, keyword, keyword).QueryRow(&c)
|
||||
err = o.Raw(sql3, memberId, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
logs.Error("查询搜索结果失败 -> ", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -253,15 +254,15 @@ LIMIT ?, ?;`
|
||||
on team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (book.book_name LIKE ? OR book.description LIKE ?);`
|
||||
|
||||
err = o.Raw(sql4,memberId, memberId,keyword, keyword).QueryRow(&c)
|
||||
err = o.Raw(sql4, memberId, memberId, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
logs.Error("查询搜索结果失败 -> ", err)
|
||||
return
|
||||
}
|
||||
|
||||
totalCount += c
|
||||
|
||||
_, err = o.Raw(sql2, memberId, memberId, keyword, keyword,memberId,memberId,keyword, keyword,memberId,keyword, keyword,offset, pageSize).QueryRows(&searchResult)
|
||||
_, err = o.Raw(sql2, memberId, memberId, keyword, keyword, memberId, memberId, keyword, keyword, memberId, keyword, keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"html/template"
|
||||
"math"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
@@ -5,8 +5,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
@@ -55,7 +55,7 @@ func (item *Itemsets) First(itemId int) (*Itemsets, error) {
|
||||
}
|
||||
err := item.QueryTable().Filter("item_id", itemId).One(item)
|
||||
if err != nil {
|
||||
beego.Error("查询项目空间失败 -> item_id=", itemId, err)
|
||||
logs.Error("查询项目空间失败 -> item_id=", itemId, err)
|
||||
} else {
|
||||
item.Include()
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (item *Itemsets) First(itemId int) (*Itemsets, error) {
|
||||
func (item *Itemsets) FindFirst(itemKey string) (*Itemsets, error) {
|
||||
err := item.QueryTable().Filter("item_key", itemKey).One(item)
|
||||
if err != nil {
|
||||
beego.Error("查询项目空间失败 -> itemKey=", itemKey, err)
|
||||
logs.Error("查询项目空间失败 -> itemKey=", itemKey, err)
|
||||
} else {
|
||||
item.Include()
|
||||
}
|
||||
@@ -112,19 +112,20 @@ func (item *Itemsets) Delete(itemId int) (err error) {
|
||||
if !item.Exist(itemId) {
|
||||
return errors.New("项目空间不存在")
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
if err := o.Begin(); err != nil {
|
||||
beego.Error("开启事物失败 ->", err)
|
||||
ormer := orm.NewOrm()
|
||||
o, err := ormer.Begin()
|
||||
if err != nil {
|
||||
logs.Error("开启事物失败 ->", err)
|
||||
return err
|
||||
}
|
||||
_, err = o.QueryTable(item.TableNameWithPrefix()).Filter("item_id", itemId).Delete()
|
||||
if err != nil {
|
||||
beego.Error("删除项目空间失败 -> item_id=", itemId, err)
|
||||
logs.Error("删除项目空间失败 -> item_id=", itemId, err)
|
||||
o.Rollback()
|
||||
}
|
||||
_, err = o.Raw("update md_books set item_id=1 where item_id=?;", itemId).Exec()
|
||||
if err != nil {
|
||||
beego.Error("删除项目空间失败 -> item_id=", itemId, err)
|
||||
logs.Error("删除项目空间失败 -> item_id=", itemId, err)
|
||||
o.Rollback()
|
||||
}
|
||||
|
||||
@@ -190,7 +191,7 @@ func (item *Itemsets) FindItemsetsByName(name string, limit int) (*SelectMemberR
|
||||
_, err = item.QueryTable().Filter("item_name__icontains", name).Limit(limit).All(&itemsets)
|
||||
}
|
||||
if err != nil {
|
||||
beego.Error("查询项目空间失败 ->", err)
|
||||
logs.Error("查询项目空间失败 ->", err)
|
||||
return &result, err
|
||||
}
|
||||
|
||||
@@ -214,7 +215,7 @@ func (item *Itemsets) FindItemsetsByItemKey(key string, pageIndex, pageSize, mem
|
||||
err = item.QueryTable().Filter("item_key", key).One(item)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询项目空间时出错 ->", key, err)
|
||||
logs.Error("查询项目空间时出错 ->", key, err)
|
||||
return nil, 0, err
|
||||
}
|
||||
offset := (pageIndex - 1) * pageSize
|
||||
@@ -232,7 +233,7 @@ WHERE book.item_id = ? AND (book.privately_owned = 0 or rel.role_id >= 0 or team
|
||||
|
||||
err = o.Raw(sql1, memberId, memberId, item.ItemId).QueryRow(&totalCount)
|
||||
if err != nil {
|
||||
beego.Error("查询项目空间时出错 ->", key, err)
|
||||
logs.Error("查询项目空间时出错 ->", key, err)
|
||||
return
|
||||
}
|
||||
sql2 := `SELECT book.*,rel1.*,member.account AS create_name FROM md_books AS book
|
||||
|
@@ -3,8 +3,8 @@ package models
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -74,10 +74,11 @@ func (m *Label) InsertOrUpdateMulti(labels string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//删除标签
|
||||
func (m *Label) Delete() error {
|
||||
o := orm.NewOrm()
|
||||
_,err := o.Raw("DELETE FROM " + m.TableNameWithPrefix() + " WHERE label_id= ?",m.LabelId).Exec()
|
||||
_, err := o.Raw("DELETE FROM "+m.TableNameWithPrefix()+" WHERE label_id= ?", m.LabelId).Exec()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -101,13 +102,9 @@ func (m *Label) FindToPager(pageIndex, pageSize int) (labels []*Label, totalCoun
|
||||
_, err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-book_number").Offset(offset).Limit(pageSize).All(&labels)
|
||||
|
||||
if err == orm.ErrNoRows {
|
||||
beego.Info("没有查询到标签 ->",err)
|
||||
logs.Info("没有查询到标签 ->", err)
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
@@ -19,9 +19,9 @@ import (
|
||||
|
||||
"math"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
)
|
||||
@@ -74,14 +74,14 @@ func (m *Member) Login(account string, password string) (*Member, error) {
|
||||
err := o.Raw("select * from md_members where (account = ? or email = ?) and status = 0 limit 1;", account, account).QueryRow(member)
|
||||
|
||||
if err != nil {
|
||||
if beego.AppConfig.DefaultBool("ldap_enable", false) == true {
|
||||
if web.AppConfig.DefaultBool("ldap_enable", false) {
|
||||
logs.Info("转入LDAP登陆 ->", account)
|
||||
return member.ldapLogin(account, password)
|
||||
} else if beego.AppConfig.String("http_login_url") != "" {
|
||||
} else if url, err := web.AppConfig.String("http_login_url"); url != "" {
|
||||
logs.Info("转入 HTTP 接口登陆 ->", account)
|
||||
return member.httpLogin(account, password)
|
||||
} else {
|
||||
logs.Error("用户登录 ->", err)
|
||||
logs.Error("user login for `%s`: %s", account, err)
|
||||
return member, ErrMemberNoExist
|
||||
}
|
||||
}
|
||||
@@ -118,32 +118,38 @@ func (m *Member) TmpLogin(account string) (*Member, error) {
|
||||
|
||||
//ldapLogin 通过LDAP登陆
|
||||
func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
if beego.AppConfig.DefaultBool("ldap_enable", false) == false {
|
||||
if !web.AppConfig.DefaultBool("ldap_enable", false) {
|
||||
return m, ErrMemberAuthMethodInvalid
|
||||
}
|
||||
var err error
|
||||
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", beego.AppConfig.String("ldap_host"), beego.AppConfig.DefaultInt("ldap_port", 3268)))
|
||||
ldaphost, _ := web.AppConfig.String("ldap_host")
|
||||
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldaphost, web.AppConfig.DefaultInt("ldap_port", 3268)))
|
||||
if err != nil {
|
||||
beego.Error("绑定 LDAP 用户失败 ->", err)
|
||||
logs.Error("绑定 LDAP 用户失败 ->", err)
|
||||
return m, ErrLDAPConnect
|
||||
}
|
||||
defer lc.Close()
|
||||
err = lc.Bind(beego.AppConfig.String("ldap_user"), beego.AppConfig.String("ldap_password"))
|
||||
ldapuser, _ := web.AppConfig.String("ldap_user")
|
||||
ldappass, _ := web.AppConfig.String("ldap_password")
|
||||
err = lc.Bind(ldapuser, ldappass)
|
||||
if err != nil {
|
||||
beego.Error("绑定 LDAP 用户失败 ->", err)
|
||||
logs.Error("绑定 LDAP 用户失败 ->", err)
|
||||
return m, ErrLDAPFirstBind
|
||||
}
|
||||
ldapbase, _ := web.AppConfig.String("ldap_base")
|
||||
ldapfilter, _ := web.AppConfig.String("ldap_filter")
|
||||
ldapattr, _ := web.AppConfig.String("ldap_attribute")
|
||||
searchRequest := ldap.NewSearchRequest(
|
||||
beego.AppConfig.String("ldap_base"),
|
||||
ldapbase,
|
||||
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
||||
//修改objectClass通过配置文件获取值
|
||||
fmt.Sprintf("(&(%s)(%s=%s))", beego.AppConfig.String("ldap_filter"), beego.AppConfig.String("ldap_attribute"), account),
|
||||
fmt.Sprintf("(&(%s)(%s=%s))", ldapfilter, ldapattr, account),
|
||||
[]string{"dn", "mail"},
|
||||
nil,
|
||||
)
|
||||
searchResult, err := lc.Search(searchRequest)
|
||||
if err != nil {
|
||||
beego.Error("绑定 LDAP 用户失败 ->", err)
|
||||
logs.Error("绑定 LDAP 用户失败 ->", err)
|
||||
return m, ErrLDAPSearch
|
||||
}
|
||||
if len(searchResult.Entries) != 1 {
|
||||
@@ -152,7 +158,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
userdn := searchResult.Entries[0].DN
|
||||
err = lc.Bind(userdn, password)
|
||||
if err != nil {
|
||||
beego.Error("绑定 LDAP 用户失败 ->", err)
|
||||
logs.Error("绑定 LDAP 用户失败 ->", err)
|
||||
return m, ErrorMemberPasswordError
|
||||
}
|
||||
if m.MemberId <= 0 {
|
||||
@@ -160,12 +166,12 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
m.Email = searchResult.Entries[0].GetAttributeValue("mail")
|
||||
m.AuthMethod = "ldap"
|
||||
m.Avatar = "/static/images/headimgurl.jpg"
|
||||
m.Role = conf.SystemRole(beego.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
m.Role = conf.SystemRole(web.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
m.CreateTime = time.Now()
|
||||
|
||||
err = m.Add()
|
||||
if err != nil {
|
||||
beego.Error("自动注册LDAP用户错误", err)
|
||||
logs.Error("自动注册LDAP用户错误", err)
|
||||
return m, ErrorMemberPasswordError
|
||||
}
|
||||
m.ResolveRoleName()
|
||||
@@ -174,7 +180,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
}
|
||||
|
||||
func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||
urlStr := beego.AppConfig.String("http_login_url")
|
||||
urlStr, _ := web.AppConfig.String("http_login_url")
|
||||
if urlStr == "" {
|
||||
return nil, ErrMemberAuthMethodInvalid
|
||||
}
|
||||
@@ -185,28 +191,28 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||
"time": []string{strconv.FormatInt(time.Now().Unix(), 10)},
|
||||
}
|
||||
h := md5.New()
|
||||
h.Write([]byte(val.Encode() + beego.AppConfig.DefaultString("http_login_secret", "")))
|
||||
h.Write([]byte(val.Encode() + web.AppConfig.DefaultString("http_login_secret", "")))
|
||||
|
||||
val.Add("sn", hex.EncodeToString(h.Sum(nil)))
|
||||
|
||||
resp, err := http.PostForm(urlStr, val)
|
||||
if err != nil {
|
||||
beego.Error("通过接口登录失败 -> ", urlStr, account, err)
|
||||
logs.Error("通过接口登录失败 -> ", urlStr, account, err)
|
||||
return nil, ErrHTTPServerFail
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
beego.Error("读取接口返回值失败 -> ", urlStr, account, err)
|
||||
logs.Error("读取接口返回值失败 -> ", urlStr, account, err)
|
||||
return nil, ErrHTTPServerFail
|
||||
}
|
||||
beego.Info("HTTP 登录接口返回数据 ->", string(body))
|
||||
logs.Info("HTTP 登录接口返回数据 ->", string(body))
|
||||
|
||||
var result map[string]interface{}
|
||||
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
beego.Error("解析接口返回值失败 -> ", urlStr, account, string(body))
|
||||
logs.Error("解析接口返回值失败 -> ", urlStr, account, string(body))
|
||||
return nil, ErrHTTPServerFail
|
||||
}
|
||||
|
||||
@@ -237,10 +243,10 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||
member.Account = account
|
||||
member.Password = password
|
||||
member.AuthMethod = "http"
|
||||
member.Role = conf.SystemRole(beego.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
member.Role = conf.SystemRole(web.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
member.CreateTime = time.Now()
|
||||
if err := member.Add(); err != nil {
|
||||
beego.Error("自动注册用户错误", err)
|
||||
logs.Error("自动注册用户错误", err)
|
||||
return m, ErrorMemberPasswordError
|
||||
}
|
||||
member.ResolveRoleName()
|
||||
@@ -274,7 +280,7 @@ func (m *Member) Add() error {
|
||||
hash, err := utils.PasswordHash(m.Password)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("加密用户密码失败 =>", err)
|
||||
logs.Error("加密用户密码失败 =>", err)
|
||||
return errors.New("加密用户密码失败")
|
||||
}
|
||||
|
||||
@@ -285,7 +291,7 @@ func (m *Member) Add() error {
|
||||
_, err = o.Insert(m)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("保存用户数据到数据时失败 =>", err)
|
||||
logs.Error("保存用户数据到数据时失败 =>", err)
|
||||
return errors.New("保存用户失败")
|
||||
}
|
||||
m.ResolveRoleName()
|
||||
@@ -303,7 +309,7 @@ func (m *Member) Update(cols ...string) error {
|
||||
return errors.New("邮箱已被使用")
|
||||
}
|
||||
if _, err := o.Update(m, cols...); err != nil {
|
||||
beego.Error("保存用户信息失败=>", err)
|
||||
logs.Error("保存用户信息失败=>", err)
|
||||
return errors.New("保存用户信息失败")
|
||||
}
|
||||
return nil
|
||||
@@ -456,9 +462,9 @@ func (m *Member) Valid(is_hash_password bool) error {
|
||||
|
||||
//删除一个用户.
|
||||
func (m *Member) Delete(oldId int, newId int) error {
|
||||
o := orm.NewOrm()
|
||||
ormer := orm.NewOrm()
|
||||
|
||||
err := o.Begin()
|
||||
o, err := ormer.Begin()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -552,18 +558,18 @@ func (m *Member) Delete(oldId int, newId int) error {
|
||||
err = o.QueryTable(relationship.TableNameWithPrefix()).Filter("book_id", relationship.BookId).Filter("member_id", newId).One(rel)
|
||||
if err == nil {
|
||||
if _, err := o.Delete(relationship); err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
}
|
||||
relationship.RelationshipId = rel.RelationshipId
|
||||
}
|
||||
relationship.MemberId = newId
|
||||
relationship.RoleId = 0
|
||||
if _, err := o.Update(relationship); err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
}
|
||||
} else {
|
||||
if _, err := o.Delete(relationship); err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -118,8 +118,7 @@ func (m *MemberRelationshipResult) FindNotJoinUsersByAccountOrRealName(bookId, l
|
||||
|
||||
var members []*Member
|
||||
|
||||
_, err := o.Raw(sql, bookId, keyWord,keyWord, limit).QueryRows(&members)
|
||||
_, err := o.Raw(sql, bookId, keyWord, keyWord, limit).QueryRows(&members)
|
||||
|
||||
return members, err
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
@@ -3,8 +3,8 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ func (m *Relationship) TableUnique() [][]string {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Relationship) QueryTable() orm.QuerySeter {
|
||||
func (m *Relationship) QueryTable() orm.QuerySeter {
|
||||
return orm.NewOrm().QueryTable(m.TableNameWithPrefix())
|
||||
}
|
||||
func NewRelationship() *Relationship {
|
||||
@@ -122,11 +122,11 @@ func (m *Relationship) Insert() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Relationship) Update() error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
_, err := o.Update(m)
|
||||
|
||||
func (m *Relationship) Update(txOrm orm.TxOrmer) error {
|
||||
_, err := txOrm.Update(m)
|
||||
if err != nil {
|
||||
txOrm.Rollback()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -152,11 +152,11 @@ func (m *Relationship) DeleteByBookIdAndMemberId(book_id, member_id int) error {
|
||||
}
|
||||
|
||||
func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||
o := orm.NewOrm()
|
||||
ormer := orm.NewOrm()
|
||||
|
||||
founder := NewRelationship()
|
||||
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", founder_id).One(founder)
|
||||
err := ormer.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", founder_id).One(founder)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -166,12 +166,12 @@ func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||
}
|
||||
receive := NewRelationship()
|
||||
|
||||
err = o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", receive_id).One(receive)
|
||||
err = ormer.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", receive_id).One(receive)
|
||||
|
||||
if err != orm.ErrNoRows && err != nil {
|
||||
return err
|
||||
}
|
||||
o.Begin()
|
||||
o, _ := ormer.Begin()
|
||||
|
||||
founder.RoleId = conf.BookAdmin
|
||||
|
||||
@@ -179,8 +179,7 @@ func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||
receive.RoleId = conf.BookFounder
|
||||
receive.BookId = book_id
|
||||
|
||||
if err := founder.Update(); err != nil {
|
||||
o.Rollback()
|
||||
if err := founder.Update(o); err != nil {
|
||||
return err
|
||||
}
|
||||
if receive.RelationshipId > 0 {
|
||||
|
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -48,8 +48,8 @@ func (t *Team) First(id int, cols ...string) (*Team, error) {
|
||||
err := o.QueryTable(t.TableNameWithPrefix()).Filter("team_id", id).One(t, cols...)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队失败 ->",id, err)
|
||||
return nil,err
|
||||
logs.Error("查询团队失败 ->", id, err)
|
||||
return nil, err
|
||||
}
|
||||
t.Include()
|
||||
return t, err
|
||||
@@ -59,34 +59,34 @@ func (t *Team) Delete(id int) (err error) {
|
||||
if id <= 0 {
|
||||
return ErrInvalidParameter
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
ormer := orm.NewOrm()
|
||||
|
||||
err = o.Begin()
|
||||
o, err := ormer.Begin()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("开启事物时出错 ->",err)
|
||||
logs.Error("开启事物时出错 ->", err)
|
||||
return
|
||||
}
|
||||
_,err = o.QueryTable(t.TableNameWithPrefix()).Filter("team_id",id).Delete()
|
||||
_, err = o.QueryTable(t.TableNameWithPrefix()).Filter("team_id", id).Delete()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("删除团队时出错 ->", err)
|
||||
logs.Error("删除团队时出错 ->", err)
|
||||
o.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
_,err = o.Raw("delete from md_team_member where team_id=?;", id).Exec()
|
||||
_, err = o.Raw("delete from md_team_member where team_id=?;", id).Exec()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("删除团队成员时出错 ->", err)
|
||||
logs.Error("删除团队成员时出错 ->", err)
|
||||
o.Rollback()
|
||||
return
|
||||
}
|
||||
|
||||
_,err = o.Raw("delete from md_team_relationship where team_id=?;",id).Exec()
|
||||
_, err = o.Raw("delete from md_team_relationship where team_id=?;", id).Exec()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("删除团队项目时出错 ->", err)
|
||||
logs.Error("删除团队项目时出错 ->", err)
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (t *Team) FindToPager(pageIndex, pageSize int) (list []*Team, totalCount in
|
||||
}
|
||||
totalCount = int(c)
|
||||
|
||||
for _,item := range list {
|
||||
for _, item := range list {
|
||||
item.Include()
|
||||
}
|
||||
return
|
||||
@@ -123,23 +123,23 @@ func (t *Team) Include() {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
if member,err := NewMember().Find(t.MemberId,"account","real_name"); err == nil {
|
||||
if member, err := NewMember().Find(t.MemberId, "account", "real_name"); err == nil {
|
||||
if member.RealName != "" {
|
||||
t.MemberName = member.RealName
|
||||
} else {
|
||||
t.MemberName = member.Account
|
||||
}
|
||||
}
|
||||
if c,err := o.QueryTable(NewTeamRelationship().TableNameWithPrefix()).Filter("team_id", t.TeamId).Count(); err == nil {
|
||||
if c, err := o.QueryTable(NewTeamRelationship().TableNameWithPrefix()).Filter("team_id", t.TeamId).Count(); err == nil {
|
||||
t.BookCount = int(c)
|
||||
}
|
||||
if c,err := o.QueryTable(NewTeamMember().TableNameWithPrefix()).Filter("team_id", t.TeamId).Count(); err == nil {
|
||||
if c, err := o.QueryTable(NewTeamMember().TableNameWithPrefix()).Filter("team_id", t.TeamId).Count(); err == nil {
|
||||
t.MemberCount = int(c)
|
||||
}
|
||||
}
|
||||
|
||||
//更新或添加一个团队.
|
||||
func (t *Team) Save(cols ... string) (err error) {
|
||||
func (t *Team) Save(cols ...string) (err error) {
|
||||
if t.TeamName == "" {
|
||||
return NewError(5001, "团队名称不能为空")
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func (t *Team) Save(cols ... string) (err error) {
|
||||
_, err = o.Update(t, cols...)
|
||||
}
|
||||
if err != nil {
|
||||
beego.Error("在保存团队时出错 ->", err)
|
||||
logs.Error("在保存团队时出错 ->", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -55,7 +55,7 @@ func (m *TeamMember) First(id int, cols ...string) (*TeamMember, error) {
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("team_member_id", id).One(m, cols...)
|
||||
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
beego.Error("查询团队成员错误 ->", err)
|
||||
logs.Error("查询团队成员错误 ->", err)
|
||||
}
|
||||
|
||||
return m.Include(), err
|
||||
@@ -71,7 +71,7 @@ func (m *TeamMember) ChangeRoleId(teamId int, memberId int, roleId conf.BookRole
|
||||
err = o.QueryTable(m.TableNameWithPrefix()).Filter("team_id", teamId).Filter("member_id", memberId).OrderBy("-team_member_id").One(m)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队用户时失败 ->", err)
|
||||
logs.Error("查询团队用户时失败 ->", err)
|
||||
return m, err
|
||||
}
|
||||
m.RoleId = roleId
|
||||
@@ -93,7 +93,7 @@ func (m *TeamMember) FindFirst(teamId, memberId int) (*TeamMember, error) {
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("team_id", teamId).Filter("member_id", memberId).One(m)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队用户失败 ->", err)
|
||||
logs.Error("查询团队用户失败 ->", err)
|
||||
return nil, err
|
||||
}
|
||||
return m.Include(), nil
|
||||
@@ -127,7 +127,7 @@ func (m *TeamMember) Save(cols ...string) (err error) {
|
||||
_, err = o.Update(m, cols...)
|
||||
}
|
||||
if err != nil {
|
||||
beego.Error("在保存团队时出错 ->", err)
|
||||
logs.Error("在保存团队时出错 ->", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func (m *TeamMember) Delete(id int) (err error) {
|
||||
_, err = orm.NewOrm().QueryTable(m.TableNameWithPrefix()).Filter("team_member_id", id).Delete()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("删除团队用户时出错 ->", err)
|
||||
logs.Error("删除团队用户时出错 ->", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func (m *TeamMember) FindToPager(teamId, pageIndex, pageSize int) (list []*TeamM
|
||||
|
||||
if err != nil {
|
||||
if err != orm.ErrNoRows {
|
||||
beego.Error("查询团队成员失败 ->", err)
|
||||
logs.Error("查询团队成员失败 ->", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -217,7 +217,7 @@ limit ?;`
|
||||
_, err := o.Raw(sql, teamId, "%"+account+"%", "%"+account+"%", limit).QueryRows(&members)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队用户时出错 ->", err)
|
||||
logs.Error("查询团队用户时出错 ->", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ and team.member_id = ? order by team.role_id asc limit 1;`
|
||||
err := o.Raw(sql, bookId, memberId).QueryRow(m)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询用户项目所在团队失败 ->bookId=", bookId, " memberId=", memberId, err)
|
||||
logs.Error("查询用户项目所在团队失败 ->bookId=", bookId, " memberId=", memberId, err)
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
|
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ func (m *TeamRelationship) First(teamId int, cols ...string) (*TeamRelationship,
|
||||
}
|
||||
err := m.QueryTable().Filter("team_id", teamId).One(m, cols...)
|
||||
if err != nil {
|
||||
beego.Error("查询项目团队失败 ->", err)
|
||||
logs.Error("查询项目团队失败 ->", err)
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func (m *TeamRelationship) FindByBookId(bookId int, teamId int) (*TeamRelationsh
|
||||
}
|
||||
err := m.QueryTable().Filter("team_id", teamId).Filter("book_id", bookId).One(m)
|
||||
if err != nil {
|
||||
beego.Error("查询项目团队失败 ->", err)
|
||||
logs.Error("查询项目团队失败 ->", err)
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (m *TeamRelationship) FindByBookId(bookId int, teamId int) (*TeamRelationsh
|
||||
func (m *TeamRelationship) DeleteByBookId(bookId int, teamId int) error {
|
||||
err := m.QueryTable().Filter("team_id", teamId).Filter("book_id", bookId).One(m)
|
||||
if err != nil {
|
||||
beego.Error("查询项目团队失败 ->", err)
|
||||
logs.Error("查询项目团队失败 ->", err)
|
||||
return err
|
||||
}
|
||||
m.Include()
|
||||
@@ -95,7 +95,7 @@ func (m *TeamRelationship) Save(cols ...string) (err error) {
|
||||
_, err = orm.NewOrm().Insert(m)
|
||||
}
|
||||
if err != nil {
|
||||
beego.Error("保存团队项目时出错 ->", err)
|
||||
logs.Error("保存团队项目时出错 ->", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (m *TeamRelationship) Delete(teamRelId int) (err error) {
|
||||
_, err = m.QueryTable().Filter("team_relationship_id", teamRelId).Delete()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("删除团队项目失败 ->", err)
|
||||
logs.Error("删除团队项目失败 ->", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -125,13 +125,13 @@ func (m *TeamRelationship) FindToPager(teamId, pageIndex, pageSize int) (list []
|
||||
_, err = o.QueryTable(m.TableNameWithPrefix()).Filter("team_id", teamId).OrderBy("-team_relationship_id").Offset(offset).Limit(pageSize).All(&list)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队项目时出错 ->", err)
|
||||
logs.Error("查询团队项目时出错 ->", err)
|
||||
return
|
||||
}
|
||||
count, err := m.QueryTable().Filter("team_id", teamId).Count()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队项目时出错 ->", err)
|
||||
logs.Error("查询团队项目时出错 ->", err)
|
||||
return
|
||||
}
|
||||
totalCount = int(count)
|
||||
@@ -162,8 +162,8 @@ func (m *TeamRelationship) Include() (*TeamRelationship, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.TeamId > 0{
|
||||
team ,err := NewTeam().First(m.TeamId)
|
||||
if m.TeamId > 0 {
|
||||
team, err := NewTeam().First(m.TeamId)
|
||||
if err == nil {
|
||||
m.TeamName = team.TeamName
|
||||
m.MemberCount = team.MemberCount
|
||||
@@ -189,7 +189,7 @@ and book.book_name like ? order by book_id desc limit ?;`
|
||||
_, err := o.Raw(sql, teamId, "%"+bookName+"%", limit).QueryRows(&books)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队项目时出错 ->", err)
|
||||
logs.Error("查询团队项目时出错 ->", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ order by team.team_id desc limit ?;`
|
||||
_, err := o.Raw(sql, bookId, "%"+teamName+"%", limit).QueryRows(&teams)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队项目时出错 ->", err)
|
||||
logs.Error("查询团队项目时出错 ->", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -257,13 +257,13 @@ func (m *TeamRelationship) FindByBookToPager(bookId, pageIndex, pageSize int) (l
|
||||
_, err = o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", bookId).OrderBy("-team_relationship_id").Offset(offset).Limit(pageSize).All(&list)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队项目时出错 ->", err)
|
||||
logs.Error("查询团队项目时出错 ->", err)
|
||||
return
|
||||
}
|
||||
count, err := m.QueryTable().Filter("book_id", bookId).Count()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询团队项目时出错 ->", err)
|
||||
logs.Error("查询团队项目时出错 ->", err)
|
||||
return
|
||||
}
|
||||
totalCount = int(count)
|
||||
|
@@ -4,27 +4,26 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
type Template struct {
|
||||
TemplateId int `orm:"column(template_id);pk;auto;unique;" json:"template_id"`
|
||||
TemplateName string `orm:"column(template_name);size(500);" json:"template_name"`
|
||||
MemberId int `orm:"column(member_id);index" json:"member_id"`
|
||||
BookId int `orm:"column(book_id);index" json:"book_id"`
|
||||
BookName string `orm:"-" json:"book_name"`
|
||||
TemplateId int `orm:"column(template_id);pk;auto;unique;" json:"template_id"`
|
||||
TemplateName string `orm:"column(template_name);size(500);" json:"template_name"`
|
||||
MemberId int `orm:"column(member_id);index" json:"member_id"`
|
||||
BookId int `orm:"column(book_id);index" json:"book_id"`
|
||||
BookName string `orm:"-" json:"book_name"`
|
||||
//是否是全局模板:0 否/1 是; 全局模板在所有项目中都可以使用;否则只能在创建模板的项目中使用
|
||||
IsGlobal int `orm:"column(is_global);default(0)" json:"is_global"`
|
||||
TemplateContent string `orm:"column(template_content);type(text);null" json:"template_content"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
CreateName string `orm:"-" json:"create_name"`
|
||||
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
||||
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
||||
ModifyName string `orm:"-" json:"modify_name"`
|
||||
Version int64 `orm:"type(bigint);column(version)" json:"version"`
|
||||
IsGlobal int `orm:"column(is_global);default(0)" json:"is_global"`
|
||||
TemplateContent string `orm:"column(template_content);type(text);null" json:"template_content"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
CreateName string `orm:"-" json:"create_name"`
|
||||
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
||||
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
||||
ModifyName string `orm:"-" json:"modify_name"`
|
||||
Version int64 `orm:"type(bigint);column(version)" json:"version"`
|
||||
}
|
||||
|
||||
// TableName 获取对应数据库表名.
|
||||
@@ -41,82 +40,83 @@ func (m *Template) TableNameWithPrefix() string {
|
||||
return conf.GetDatabasePrefix() + m.TableName()
|
||||
}
|
||||
|
||||
func NewTemplate() *Template {
|
||||
func NewTemplate() *Template {
|
||||
return &Template{}
|
||||
}
|
||||
|
||||
//查询指定ID的模板
|
||||
func (t *Template) Find(templateId int) (*Template,error) {
|
||||
func (t *Template) Find(templateId int) (*Template, error) {
|
||||
if templateId <= 0 {
|
||||
return t, ErrInvalidParameter
|
||||
}
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
err := o.QueryTable(t.TableNameWithPrefix()).Filter("template_id",templateId).One(t)
|
||||
err := o.QueryTable(t.TableNameWithPrefix()).Filter("template_id", templateId).One(t)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("查询模板时失败 ->%s",err)
|
||||
logs.Error("查询模板时失败 ->%s", err)
|
||||
}
|
||||
return t,err
|
||||
return t, err
|
||||
}
|
||||
|
||||
//查询属于指定项目的模板.
|
||||
func (t *Template) FindByBookId(bookId int) ([]*Template,error) {
|
||||
func (t *Template) FindByBookId(bookId int) ([]*Template, error) {
|
||||
if bookId <= 0 {
|
||||
return nil,ErrInvalidParameter
|
||||
return nil, ErrInvalidParameter
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
|
||||
var templateList []*Template
|
||||
|
||||
_,err := o.QueryTable(t.TableNameWithPrefix()).Filter("book_id",bookId).OrderBy("-template_id").All(&templateList)
|
||||
_, err := o.QueryTable(t.TableNameWithPrefix()).Filter("book_id", bookId).OrderBy("-template_id").All(&templateList)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询模板列表失败 ->",err)
|
||||
logs.Error("查询模板列表失败 ->", err)
|
||||
}
|
||||
return templateList,err
|
||||
return templateList, err
|
||||
}
|
||||
|
||||
//查询指定项目所有可用模板列表.
|
||||
func (t *Template) FindAllByBookId(bookId int) ([]*Template,error) {
|
||||
func (t *Template) FindAllByBookId(bookId int) ([]*Template, error) {
|
||||
if bookId <= 0 {
|
||||
return nil,ErrInvalidParameter
|
||||
return nil, ErrInvalidParameter
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
|
||||
cond := orm.NewCondition()
|
||||
|
||||
cond1 := cond.And("book_id",bookId).Or("is_global",1)
|
||||
cond1 := cond.And("book_id", bookId).Or("is_global", 1)
|
||||
|
||||
qs := o.QueryTable(t.TableNameWithPrefix())
|
||||
|
||||
var templateList []*Template
|
||||
|
||||
_,err := qs.SetCond(cond1).OrderBy("-template_id").All(&templateList)
|
||||
_, err := qs.SetCond(cond1).OrderBy("-template_id").All(&templateList)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询模板列表失败 ->",err)
|
||||
logs.Error("查询模板列表失败 ->", err)
|
||||
}
|
||||
return templateList,err
|
||||
return templateList, err
|
||||
}
|
||||
|
||||
//删除一个模板
|
||||
func (t *Template) Delete(templateId int,memberId int) error {
|
||||
func (t *Template) Delete(templateId int, memberId int) error {
|
||||
if templateId <= 0 {
|
||||
return ErrInvalidParameter
|
||||
}
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
qs := o.QueryTable(t.TableNameWithPrefix()).Filter("template_id",templateId)
|
||||
qs := o.QueryTable(t.TableNameWithPrefix()).Filter("template_id", templateId)
|
||||
|
||||
if memberId > 0 {
|
||||
qs = qs.Filter("member_id",memberId)
|
||||
qs = qs.Filter("member_id", memberId)
|
||||
}
|
||||
_,err := qs.Delete()
|
||||
_, err := qs.Delete()
|
||||
|
||||
if err != nil {
|
||||
beego.Error("删除模板失败 ->",err)
|
||||
logs.Error("删除模板失败 ->", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -129,20 +129,20 @@ func (t *Template) Save(cols ...string) (err error) {
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
|
||||
if !o.QueryTable(NewBook().TableNameWithPrefix()).Filter("book_id",t.BookId).Exist() {
|
||||
if !o.QueryTable(NewBook().TableNameWithPrefix()).Filter("book_id", t.BookId).Exist() {
|
||||
return errors.New("项目不存在")
|
||||
}
|
||||
if !o.QueryTable(NewMember().TableNameWithPrefix()).Filter("member_id",t.MemberId).Filter("status",0).Exist() {
|
||||
if !o.QueryTable(NewMember().TableNameWithPrefix()).Filter("member_id", t.MemberId).Filter("status", 0).Exist() {
|
||||
return errors.New("用户已被禁用")
|
||||
}
|
||||
t.Version = time.Now().Unix()
|
||||
|
||||
if t.TemplateId > 0 {
|
||||
t.ModifyTime = time.Now()
|
||||
_,err = o.Update(t,cols...)
|
||||
}else{
|
||||
_, err = o.Update(t, cols...)
|
||||
} else {
|
||||
t.CreateTime = time.Now()
|
||||
_,err = o.Insert(t)
|
||||
_, err = o.Insert(t)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -152,36 +152,31 @@ func (t *Template) Save(cols ...string) (err error) {
|
||||
func (t *Template) Preload() *Template {
|
||||
if t != nil {
|
||||
if t.MemberId > 0 {
|
||||
m,err := NewMember().Find(t.MemberId,"account","real_name");
|
||||
m, err := NewMember().Find(t.MemberId, "account", "real_name")
|
||||
if err == nil {
|
||||
if m.RealName != "" {
|
||||
t.CreateName = m.RealName
|
||||
}else{
|
||||
} else {
|
||||
t.CreateName = m.Account
|
||||
}
|
||||
}else{
|
||||
beego.Error("加载模板所有者失败 ->",err)
|
||||
} else {
|
||||
logs.Error("加载模板所有者失败 ->", err)
|
||||
}
|
||||
}
|
||||
if t.ModifyAt > 0 {
|
||||
if m,err := NewMember().Find(t.ModifyAt,"account","real_name"); err == nil {
|
||||
if m, err := NewMember().Find(t.ModifyAt, "account", "real_name"); err == nil {
|
||||
if m.RealName != "" {
|
||||
t.ModifyName = m.RealName
|
||||
}else{
|
||||
} else {
|
||||
t.ModifyName = m.Account
|
||||
}
|
||||
}
|
||||
}
|
||||
if t.BookId > 0 {
|
||||
if b,err := NewBook().Find(t.BookId,"book_name");err == nil {
|
||||
if b, err := NewBook().Find(t.BookId, "book_name"); err == nil {
|
||||
t.BookName = b.BookName
|
||||
}
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
import "github.com/astaxie/beego/orm"
|
||||
import "github.com/beego/beego/v2/client/orm"
|
||||
|
||||
type CommentResult struct {
|
||||
Comment
|
||||
|
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user