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

Function initialization

commands/install.go:64–113  ·  view source on GitHub ↗

初始化数据

()

Source from the content-addressed store, hash-verified

62
63//初始化数据
64func initialization() {
65 models.InstallAdsPosition()
66 err := models.NewOption().Init()
67 if err != nil {
68 panic(err.Error())
69 os.Exit(1)
70 }
71
72 member, err := models.NewMember().FindByFieldFirst("account", "admin")
73 if err == orm.ErrNoRows {
74 member.Account = "admin"
75 member.Avatar = beego.AppConfig.String("avatar")
76 member.Password = "admin888"
77 member.AuthMethod = "local"
78 member.Nickname = "管理员"
79 member.Role = 0
80 member.Email = "bookstack@qq.cn"
81
82 if err := member.Add(); err != nil {
83 beego.Error("Member.Add => " + err.Error())
84 }
85
86 book := models.NewBook()
87 book.MemberId = member.MemberId
88 book.BookName = "BookStack"
89 book.Status = 0
90 book.Description = "这是一个BookStack演示书籍,该书籍是由系统初始化时自动创建。"
91 book.CommentCount = 0
92 book.PrivatelyOwned = 0
93 book.CommentStatus = "closed"
94 book.Identify = "bookstack"
95 book.DocCount = 0
96 book.CommentCount = 0
97 book.Version = time.Now().Unix()
98 book.Cover = conf.GetDefaultCover()
99 book.Editor = "markdown"
100 book.Theme = "default"
101 //设置默认时间,因为beego的orm好像无法设置datetime的默认值
102 defaultTime, _ := time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05")
103 book.LastClickGenerate = defaultTime
104 book.GenerateTime = defaultTime
105 //book.ReleaseTime = defaultTime
106 book.ReleaseTime, _ = time.Parse("2006-01-02 15:04:05", "2000-01-02 15:04:05")
107 book.Score = 40
108
109 if err := book.Insert(); err != nil {
110 beego.Error("Book.Insert => " + err.Error())
111 }
112 }
113}
114
115//初始化SEO
116func initSeo() {

Callers 1

InstallFunction · 0.85

Calls 9

InsertMethod · 0.95
InstallAdsPositionFunction · 0.92
NewOptionFunction · 0.92
NewMemberFunction · 0.92
NewBookFunction · 0.92
GetDefaultCoverFunction · 0.92
InitMethod · 0.45
FindByFieldFirstMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected