mirror of https://github.com/go-gitea/gitea.git
Fixing bug
This commit is contained in:
parent
03cc39ea12
commit
a6e12aaef6
|
@ -18,6 +18,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
orm *xorm.Engine
|
orm *xorm.Engine
|
||||||
|
HasEngine bool
|
||||||
|
|
||||||
DbCfg struct {
|
DbCfg struct {
|
||||||
Type, Host, Name, User, Pwd, Path, SslMode string
|
Type, Host, Name, User, Pwd, Path, SslMode string
|
||||||
|
@ -34,6 +35,28 @@ func LoadModelsConfig() {
|
||||||
DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db")
|
DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewTestEngine(x *xorm.Engine) (err error) {
|
||||||
|
switch DbCfg.Type {
|
||||||
|
case "mysql":
|
||||||
|
x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
|
||||||
|
DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
|
||||||
|
case "postgres":
|
||||||
|
x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
|
||||||
|
DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
|
||||||
|
case "sqlite3":
|
||||||
|
os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
|
||||||
|
x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("models.init(fail to conntect database): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
|
||||||
|
new(Action), new(Access), new(Issue), new(Comment))
|
||||||
|
}
|
||||||
|
|
||||||
func SetEngine() (err error) {
|
func SetEngine() (err error) {
|
||||||
switch DbCfg.Type {
|
switch DbCfg.Type {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
|
|
|
@ -21,6 +21,10 @@ import (
|
||||||
|
|
||||||
// SignedInId returns the id of signed in user.
|
// SignedInId returns the id of signed in user.
|
||||||
func SignedInId(session session.SessionStore) int64 {
|
func SignedInId(session session.SessionStore) int64 {
|
||||||
|
if !models.HasEngine {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
userId := session.Get("userId")
|
userId := session.Get("userId")
|
||||||
if userId == nil {
|
if userId == nil {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/Unknwon/goconfig"
|
"github.com/Unknwon/goconfig"
|
||||||
"github.com/codegangsta/martini"
|
"github.com/codegangsta/martini"
|
||||||
|
// "github.com/lunny/xorm"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/auth"
|
"github.com/gogits/gogs/modules/auth"
|
||||||
|
@ -38,10 +39,15 @@ func GlobalInit() {
|
||||||
models.LoadModelsConfig()
|
models.LoadModelsConfig()
|
||||||
models.LoadRepoConfig()
|
models.LoadRepoConfig()
|
||||||
models.NewRepoContext()
|
models.NewRepoContext()
|
||||||
if err := models.NewEngine(); err != nil && base.InstallLock {
|
|
||||||
|
if base.InstallLock {
|
||||||
|
if err := models.NewEngine(); err != nil {
|
||||||
log.Error("%v", err)
|
log.Error("%v", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
models.HasEngine = true
|
||||||
|
}
|
||||||
base.NewServices()
|
base.NewServices()
|
||||||
checkRunMode()
|
checkRunMode()
|
||||||
}
|
}
|
||||||
|
@ -107,7 +113,11 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
models.DbCfg.SslMode = form.SslMode
|
models.DbCfg.SslMode = form.SslMode
|
||||||
models.DbCfg.Path = form.DatabasePath
|
models.DbCfg.Path = form.DatabasePath
|
||||||
|
|
||||||
if err := models.NewEngine(); err != nil {
|
// ctx.RenderWithErr("Database setting is not correct: ", "install", &form)
|
||||||
|
// return
|
||||||
|
log.Trace("00000000000000000000000000000000000000000000")
|
||||||
|
var x *xorm.Engine
|
||||||
|
if err := models.NewTestEngine(x); err != nil {
|
||||||
if strings.Contains(err.Error(), `unknown driver "sqlite3"`) {
|
if strings.Contains(err.Error(), `unknown driver "sqlite3"`) {
|
||||||
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
||||||
"from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form)
|
"from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form)
|
||||||
|
@ -158,7 +168,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
|
|
||||||
base.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
base.Cfg.SetValue("security", "INSTALL_LOCK", "true")
|
||||||
|
|
||||||
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil {
|
if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil {
|
||||||
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue