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")
}
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 {
server.UpdateDirective("index", []string{"index.php index.html index.htm default.php default.htm default.html"})
server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"})
runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.RuntimeID))
if err != nil {
@ -1383,11 +1386,18 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
website.Proxy = phpProxy
server.UpdatePHPProxy([]string{website.Proxy}, "")
website.Type = constant.Runtime
if !fileOp.Stat(indexPHPPath) {
_ = fileOp.WriteFile(indexPHPPath, strings.NewReader(string(nginx_conf.IndexPHP)), constant.FilePerm)
}
} else {
server.UpdateDirective("index", []string{"index.html index.php index.htm default.php default.htm default.html"})
website.RuntimeID = 0
website.Type = constant.Static
website.Proxy = ""
server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"})
if !fileOp.Stat(indexHtmlPath) {
_ = fileOp.WriteFile(indexHtmlPath, strings.NewReader(string(nginx_conf.Index)), constant.FilePerm)
}
}
config.FilePath = configPath

View file

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

View file

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

View file

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

View file

@ -152,11 +152,11 @@
/>
</template>
</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 }">
<fu-read-write-switch>
<template #read>
<MsgInfo :info="row.remark" :width="'280'" />
<MsgInfo :info="row.remark" :width="'150'" />
</template>
<template #default="{ read }">
<el-input v-model="row.remark" @blur="updateRemark(row, read)" />