mirror of https://github.com/mindoc-org/mindoc.git
fix(models): use client/orm instead of adapter/orm
- using new orm api, change some related logics - newer orm api has the concept of TxOrmer, for purpose of transaction handling. A transaction ormer in v2 is a stateful object, it should be dropped after using. A Ormer object is stateless and thread(routine) safe, and should not be used for transaction handling. More details count be found at official doc: https://beego.me/docs/mvc/model/orm.md, and pr note: https://github.com/mindoc-org/mindoc/pull/662#issuecomment-807040262pull/662/head
parent
8b7d56a547
commit
916c9c6c2a
|
@ -16,11 +16,11 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter"
|
"github.com/beego/beego/v2/adapter"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
|
||||||
beegoCache "github.com/beego/beego/v2/client/cache"
|
beegoCache "github.com/beego/beego/v2/client/cache"
|
||||||
_ "github.com/beego/beego/v2/client/cache/memcache"
|
_ "github.com/beego/beego/v2/client/cache/memcache"
|
||||||
"github.com/beego/beego/v2/client/cache/redis"
|
"github.com/beego/beego/v2/client/cache/redis"
|
||||||
_ "github.com/beego/beego/v2/client/cache/redis"
|
_ "github.com/beego/beego/v2/client/cache/redis"
|
||||||
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/howeyc/fsnotify"
|
"github.com/howeyc/fsnotify"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/graphics"
|
"github.com/mindoc-org/mindoc/graphics"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/boombuler/barcode"
|
"github.com/boombuler/barcode"
|
||||||
|
|
|
@ -2,7 +2,7 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter"
|
"github.com/beego/beego/v2/adapter"
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
"github.com/mindoc-org/mindoc/utils"
|
"github.com/mindoc-org/mindoc/utils"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
)
|
)
|
||||||
|
|
Binary file not shown.
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/mindoc-org/mindoc/cache"
|
"github.com/mindoc-org/mindoc/cache"
|
||||||
|
@ -273,7 +273,7 @@ func (b *Blog) Processor() *Blog {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
//设置图片为CDN地址
|
//设置图片为CDN地址
|
||||||
if cdnimg,_ := web.AppConfig.String("cdnimg"); cdnimg != "" {
|
if cdnimg, _ := web.AppConfig.String("cdnimg"); cdnimg != "" {
|
||||||
content.Find("img").Each(func(i int, contentSelection *goquery.Selection) {
|
content.Find("img").Each(func(i int, contentSelection *goquery.Selection) {
|
||||||
if src, ok := contentSelection.Attr("src"); ok && strings.HasPrefix(src, "/uploads/") {
|
if src, ok := contentSelection.Attr("src"); ok && strings.HasPrefix(src, "/uploads/") {
|
||||||
contentSelection.SetAttr("src", utils.JoinURI(cdnimg, src))
|
contentSelection.SetAttr("src", utils.JoinURI(cdnimg, src))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -17,7 +18,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/utils"
|
"github.com/mindoc-org/mindoc/utils"
|
||||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||||
|
@ -196,7 +197,7 @@ func (book *Book) Copy(identify string) error {
|
||||||
logs.Error("查询项目时出错 -> ", err)
|
logs.Error("查询项目时出错 -> ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := o.Begin(); err != nil {
|
if _, err := o.Begin(); err != nil {
|
||||||
logs.Error("开启事物时出错 -> ", err)
|
logs.Error("开启事物时出错 -> ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -209,49 +210,87 @@ func (book *Book) Copy(identify string) error {
|
||||||
book.CommentCount = 0
|
book.CommentCount = 0
|
||||||
book.HistoryCount = 0
|
book.HistoryCount = 0
|
||||||
|
|
||||||
if _, err := o.Insert(book); err != nil {
|
/* v2 version of beego remove the o.Rollback api for transaction operation.
|
||||||
logs.Error("复制项目时出错 -> ", err)
|
* typically, in v1, you can write code like this:
|
||||||
o.Rollback()
|
*
|
||||||
|
* 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var rels []*Relationship
|
var rels []*Relationship
|
||||||
|
|
||||||
if _, err := o.QueryTable(NewRelationship().TableNameWithPrefix()).Filter("book_id", bookId).All(&rels); err != nil {
|
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)
|
logs.Error("复制项目关系时出错 -> ", err)
|
||||||
o.Rollback()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rel := range rels {
|
for _, rel := range rels {
|
||||||
rel.BookId = book.BookId
|
rel.BookId = book.BookId
|
||||||
rel.RelationshipId = 0
|
rel.RelationshipId = 0
|
||||||
if _, err := o.Insert(rel); err != nil {
|
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||||
|
_, err := txo.Insert(rel)
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
logs.Error("复制项目关系时出错 -> ", err)
|
logs.Error("复制项目关系时出错 -> ", err)
|
||||||
o.Rollback()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var docs []*Document
|
var docs []*Document
|
||||||
|
|
||||||
if _, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", 0).All(&docs); err != nil && err != orm.ErrNoRows {
|
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)
|
logs.Error("读取项目文档时出错 -> ", err)
|
||||||
o.Rollback()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(docs) > 0 {
|
if len(docs) > 0 {
|
||||||
if err := recursiveInsertDocument(docs, o, book.BookId, 0); err != nil {
|
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||||
|
return recursiveInsertDocument(docs, txOrm, book.BookId, 0)
|
||||||
|
}); err != nil {
|
||||||
logs.Error("复制项目时出错 -> ", err)
|
logs.Error("复制项目时出错 -> ", err)
|
||||||
o.Rollback()
|
|
||||||
return 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 {
|
for _, doc := range docs {
|
||||||
|
|
||||||
docId := doc.DocumentId
|
docId := doc.DocumentId
|
||||||
|
@ -418,42 +457,49 @@ func (book *Book) ThoroughDeleteBook(id int) error {
|
||||||
o.Begin()
|
o.Begin()
|
||||||
|
|
||||||
//删除附件,这里没有删除实际物理文件
|
//删除附件,这里没有删除实际物理文件
|
||||||
_, err = o.Raw("DELETE FROM "+NewAttachment().TableNameWithPrefix()+" WHERE book_id=?", book.BookId).Exec()
|
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||||
if err != nil {
|
_, err = txOrm.Raw("DELETE FROM "+NewAttachment().TableNameWithPrefix()+" WHERE book_id=?", book.BookId).Exec()
|
||||||
o.Rollback()
|
return err
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除文档
|
//删除文档
|
||||||
_, err = o.Raw("DELETE FROM "+NewDocument().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
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()
|
||||||
if err != nil {
|
return err
|
||||||
o.Rollback()
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//删除项目
|
//删除项目
|
||||||
_, err = o.Raw("DELETE FROM "+book.TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
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()
|
||||||
if err != nil {
|
return err
|
||||||
o.Rollback()
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除关系
|
//删除关系
|
||||||
_, err = o.Raw("DELETE FROM "+NewRelationship().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
|
||||||
if err != nil {
|
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||||
o.Rollback()
|
_, err = txOrm.Raw("DELETE FROM "+NewRelationship().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = o.Raw(fmt.Sprintf("DELETE FROM %s WHERE book_id=?", NewTeamRelationship().TableNameWithPrefix()), book.BookId).Exec()
|
|
||||||
if err != nil {
|
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||||
o.Rollback()
|
_, err = txOrm.Raw(fmt.Sprintf("DELETE FROM %s WHERE book_id=?", NewTeamRelationship().TableNameWithPrefix()), book.BookId).Exec()
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//删除模板
|
//删除模板
|
||||||
_, err = o.Raw("DELETE FROM "+NewTemplate().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
|
||||||
if err != nil {
|
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||||
o.Rollback()
|
_, err = txOrm.Raw("DELETE FROM "+NewTemplate().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +516,7 @@ func (book *Book) ThoroughDeleteBook(id int) error {
|
||||||
logs.Error("删除项目附件和图片失败 ->", err)
|
logs.Error("删除项目附件和图片失败 ->", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return o.Commit()
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/beego/beego/v2/adapter"
|
"github.com/beego/beego/v2/adapter"
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/converter"
|
"github.com/mindoc-org/mindoc/converter"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/beego/beego/v2/adapter/orm"
|
import "github.com/beego/beego/v2/client/orm"
|
||||||
|
|
||||||
type Dashboard struct {
|
type Dashboard struct {
|
||||||
BookNumber int64 `json:"book_number"`
|
BookNumber int64 `json:"book_number"`
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/utils"
|
"github.com/mindoc-org/mindoc/utils"
|
||||||
|
@ -112,8 +112,9 @@ func (item *Itemsets) Delete(itemId int) (err error) {
|
||||||
if !item.Exist(itemId) {
|
if !item.Exist(itemId) {
|
||||||
return errors.New("项目空间不存在")
|
return errors.New("项目空间不存在")
|
||||||
}
|
}
|
||||||
o := orm.NewOrm()
|
ormer := orm.NewOrm()
|
||||||
if err := o.Begin(); err != nil {
|
o, err := ormer.Begin()
|
||||||
|
if err != nil {
|
||||||
logs.Error("开启事物失败 ->", err)
|
logs.Error("开启事物失败 ->", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/beego/beego/v2/server/web"
|
"github.com/beego/beego/v2/server/web"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
|
@ -81,7 +81,7 @@ func (m *Member) Login(account string, password string) (*Member, error) {
|
||||||
logs.Info("转入 HTTP 接口登陆 ->", account)
|
logs.Info("转入 HTTP 接口登陆 ->", account)
|
||||||
return member.httpLogin(account, password)
|
return member.httpLogin(account, password)
|
||||||
} else {
|
} else {
|
||||||
logs.Error("user login for `%s`: %s",account, err)
|
logs.Error("user login for `%s`: %s", account, err)
|
||||||
return member, ErrMemberNoExist
|
return member, ErrMemberNoExist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Member) httpLogin(account, password string) (*Member, error) {
|
func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||||
urlStr,_ := web.AppConfig.String("http_login_url")
|
urlStr, _ := web.AppConfig.String("http_login_url")
|
||||||
if urlStr == "" {
|
if urlStr == "" {
|
||||||
return nil, ErrMemberAuthMethodInvalid
|
return nil, ErrMemberAuthMethodInvalid
|
||||||
}
|
}
|
||||||
|
@ -462,9 +462,9 @@ func (m *Member) Valid(is_hash_password bool) error {
|
||||||
|
|
||||||
//删除一个用户.
|
//删除一个用户.
|
||||||
func (m *Member) Delete(oldId int, newId int) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/logs"
|
"github.com/beego/beego/v2/adapter/logs"
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -122,11 +122,11 @@ func (m *Relationship) Insert() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Relationship) Update() error {
|
func (m *Relationship) Update(txOrm orm.TxOrmer) error {
|
||||||
o := orm.NewOrm()
|
_, err := txOrm.Update(m)
|
||||||
|
if err != nil {
|
||||||
_, err := o.Update(m)
|
txOrm.Rollback()
|
||||||
|
}
|
||||||
return err
|
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 {
|
func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||||
o := orm.NewOrm()
|
ormer := orm.NewOrm()
|
||||||
|
|
||||||
founder := NewRelationship()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -166,12 +166,12 @@ func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||||
}
|
}
|
||||||
receive := NewRelationship()
|
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 {
|
if err != orm.ErrNoRows && err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
o.Begin()
|
o, _ := ormer.Begin()
|
||||||
|
|
||||||
founder.RoleId = conf.BookAdmin
|
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.RoleId = conf.BookFounder
|
||||||
receive.BookId = book_id
|
receive.BookId = book_id
|
||||||
|
|
||||||
if err := founder.Update(); err != nil {
|
if err := founder.Update(o); err != nil {
|
||||||
o.Rollback()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if receive.RelationshipId > 0 {
|
if receive.RelationshipId > 0 {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
@ -59,9 +59,9 @@ func (t *Team) Delete(id int) (err error) {
|
||||||
if id <= 0 {
|
if id <= 0 {
|
||||||
return ErrInvalidParameter
|
return ErrInvalidParameter
|
||||||
}
|
}
|
||||||
o := orm.NewOrm()
|
ormer := orm.NewOrm()
|
||||||
|
|
||||||
err = o.Begin()
|
o, err := ormer.Begin()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("开启事物时出错 ->", err)
|
logs.Error("开启事物时出错 ->", err)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "github.com/beego/beego/v2/adapter/orm"
|
import "github.com/beego/beego/v2/client/orm"
|
||||||
|
|
||||||
type CommentResult struct {
|
type CommentResult struct {
|
||||||
Comment
|
Comment
|
||||||
|
|
|
@ -3,7 +3,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/orm"
|
"github.com/beego/beego/v2/client/orm"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue