fix(website): fix issue with change website type failed (#8126)

This commit is contained in:
zhengkunwang 2025-03-12 11:16:38 +08:00 committed by GitHub
parent 99d3e65df5
commit fa8f90c493
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 7 deletions

View file

@ -1368,8 +1368,11 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
return errors.New("nginx config is not valid") return errors.New("nginx config is not valid")
} }
server := servers[0] server := servers[0]
fileOp := files.NewFileOp()
indexPHPPath := path.Join(GetSitePath(website, SiteIndexDir), "index.php")
indexHtmlPath := path.Join(GetSitePath(website, SiteIndexDir), "index.html")
if req.RuntimeID > 0 { if req.RuntimeID > 0 {
server.UpdateDirective("index", []string{"index.php index.html index.htm default.php default.htm default.html"})
server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"}) server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"})
runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.RuntimeID)) runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.RuntimeID))
if err != nil { if err != nil {
@ -1383,11 +1386,18 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
website.Proxy = phpProxy website.Proxy = phpProxy
server.UpdatePHPProxy([]string{website.Proxy}, "") server.UpdatePHPProxy([]string{website.Proxy}, "")
website.Type = constant.Runtime website.Type = constant.Runtime
if !fileOp.Stat(indexPHPPath) {
_ = fileOp.WriteFile(indexPHPPath, strings.NewReader(string(nginx_conf.IndexPHP)), constant.FilePerm)
}
} else { } else {
server.UpdateDirective("index", []string{"index.html index.php index.htm default.php default.htm default.html"})
website.RuntimeID = 0 website.RuntimeID = 0
website.Type = constant.Static website.Type = constant.Static
website.Proxy = "" website.Proxy = ""
server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"}) server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"})
if !fileOp.Stat(indexHtmlPath) {
_ = fileOp.WriteFile(indexHtmlPath, strings.NewReader(string(nginx_conf.Index)), constant.FilePerm)
}
} }
config.FilePath = configPath config.FilePath = configPath

View file

@ -862,7 +862,7 @@ func opWebsite(website *model.Website, operate string) error {
website.Status = constant.WebRunning website.Status = constant.WebRunning
now := time.Now() now := time.Now()
if website.ExpireDate.Before(now) { if website.ExpireDate.Before(now) {
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate) defaultDate, _ := time.Parse(constant.DateLayout, constant.WebsiteDefaultExpireDate)
website.ExpireDate = defaultDate website.ExpireDate = defaultDate
} }
} }

View file

@ -23,8 +23,7 @@ const (
TimeOut20s = 20 TimeOut20s = 20
TimeOut5m = 300 TimeOut5m = 300
DateLayout = "2006-01-02" // or use time.DateOnly while go version >= 1.20 DateLayout = "2006-01-02" // or use time.DateOnly while go version >= 1.20
DefaultDate = "1970-01-01"
DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20 DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20
DateTimeSlimLayout = "20060102150405" DateTimeSlimLayout = "20060102150405"
WebsiteDefaultExpireDate = "9999-12-31" WebsiteDefaultExpireDate = "9999-12-31"

View file

@ -25,7 +25,7 @@ func (w *website) Run() {
global.LOG.Info("Website scheduled task in progress ...") global.LOG.Info("Website scheduled task in progress ...")
now := time.Now().Add(10 * time.Minute) now := time.Now().Add(10 * time.Minute)
if len(websites) > 0 { if len(websites) > 0 {
neverExpireDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate) neverExpireDate, _ := time.Parse(constant.DateLayout, constant.WebsiteDefaultExpireDate)
var wg sync.WaitGroup var wg sync.WaitGroup
for _, site := range websites { for _, site := range websites {
if site.Status != constant.WebRunning || neverExpireDate.Equal(site.ExpireDate) { if site.Status != constant.WebRunning || neverExpireDate.Equal(site.ExpireDate) {

View file

@ -152,11 +152,11 @@
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="$t('website.remark')" prop="remark" min-width="120px"> <el-table-column :label="$t('website.remark')" prop="remark" min-width="150">
<template #default="{ row }"> <template #default="{ row }">
<fu-read-write-switch> <fu-read-write-switch>
<template #read> <template #read>
<MsgInfo :info="row.remark" :width="'280'" /> <MsgInfo :info="row.remark" :width="'150'" />
</template> </template>
<template #default="{ read }"> <template #default="{ read }">
<el-input v-model="row.remark" @blur="updateRemark(row, read)" /> <el-input v-model="row.remark" @blur="updateRemark(row, read)" />