mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-22 00:00:10 +00:00
feat(website): add batch checkout php version (#14481)
This commit is contained in:
@@ -1340,3 +1340,16 @@ func (b *BaseApi) BatchSetHttps(c *gin.Context) {
|
||||
}
|
||||
helper.Success(c)
|
||||
}
|
||||
|
||||
func (b *BaseApi) BatchChangePHPVersion(c *gin.Context) {
|
||||
var req request.WebsiteBatchPHPVersionReq
|
||||
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||
return
|
||||
}
|
||||
results, err := websiteService.BatchChangePHPVersion(req)
|
||||
if err != nil {
|
||||
helper.InternalServer(c, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, results)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type WebsiteSearch struct {
|
||||
RuntimeType string `json:"runtimeType" validate:"omitempty,oneof=php node java go python dotnet"`
|
||||
dto.PageInfo
|
||||
Name string `json:"name"`
|
||||
OrderBy string `json:"orderBy" validate:"required,oneof=primary_domain type status createdAt expire_date created_at favorite"`
|
||||
@@ -393,3 +394,9 @@ type ExecComposerReq struct {
|
||||
WebsiteID uint `json:"websiteID" validate:"required"`
|
||||
TaskID string `json:"taskID" validate:"required"`
|
||||
}
|
||||
|
||||
// WebsiteBatchPHPVersionReq changes only existing PHP websites.
|
||||
type WebsiteBatchPHPVersionReq struct {
|
||||
IDs []uint `json:"ids" validate:"required,min=1"`
|
||||
RuntimeID uint `json:"runtimeID" validate:"required"`
|
||||
}
|
||||
|
||||
@@ -129,3 +129,10 @@ type Database struct {
|
||||
From string `json:"from"`
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
|
||||
type WebsiteBatchPHPVersionResult struct {
|
||||
ID uint `json:"id"`
|
||||
Domain string `json:"domain"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ type IWebsiteRepo interface {
|
||||
WithDefaultServer() DBOption
|
||||
WithDomainLike(domain string) DBOption
|
||||
WithSearchKeyword(keyword string, ids []uint) DBOption
|
||||
WithRuntimeType(runtimeType string) DBOption
|
||||
WithRuntimeID(runtimeID uint) DBOption
|
||||
WithParentID(websiteID uint) DBOption
|
||||
WithType(websiteType string) DBOption
|
||||
@@ -60,6 +61,13 @@ func (w *WebsiteRepo) WithAppInstallIds(appInstallIDs []uint) DBOption {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebsiteRepo) WithRuntimeType(runtimeType string) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
runtimes := db.Session(&gorm.Session{NewDB: true}).Model(&model.Runtime{}).Select("id").Where("type = ?", runtimeType)
|
||||
return db.Where("type = ? AND runtime_id IN (?)", "runtime", runtimes)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebsiteRepo) WithRuntimeID(runtimeID uint) DBOption {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("runtime_id = ?", runtimeID)
|
||||
|
||||
@@ -83,6 +83,7 @@ type IWebsiteService interface {
|
||||
GetWebsite(id uint) (response.WebsiteDTO, error)
|
||||
|
||||
ChangePHPVersion(req request.WebsitePHPVersionReq) error
|
||||
BatchChangePHPVersion(req request.WebsiteBatchPHPVersionReq) ([]response.WebsiteBatchPHPVersionResult, error)
|
||||
OperateCrossSiteAccess(req request.CrossSiteAccessOp) error
|
||||
ExecComposer(req request.ExecComposerReq) error
|
||||
ChangeGroup(group, newGroup uint) error
|
||||
@@ -190,6 +191,9 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
|
||||
if req.Type != "" {
|
||||
opts = append(opts, websiteRepo.WithType(req.Type))
|
||||
}
|
||||
if req.RuntimeType != "" {
|
||||
opts = append(opts, websiteRepo.WithRuntimeType(req.RuntimeType))
|
||||
}
|
||||
total, websites, err := websiteRepo.Page(req.Page, req.PageSize, opts...)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
@@ -1425,14 +1429,6 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) (err
|
||||
if oldRuntime.Resource == constant.ResourceLocal {
|
||||
return buserr.New("ErrPHPResource")
|
||||
}
|
||||
client, err := docker.NewDockerClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Close()
|
||||
if !checkImageLike(client, oldRuntime.Image) {
|
||||
return buserr.WithName("ErrImageNotExist", oldRuntime.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if req.RuntimeID > 0 {
|
||||
@@ -1443,6 +1439,17 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) (err
|
||||
if runtime.Resource == constant.ResourceLocal {
|
||||
return buserr.New("ErrPHPResource")
|
||||
}
|
||||
if runtime.Type != constant.RuntimePHP {
|
||||
return fmt.Errorf("target runtime must be PHP")
|
||||
}
|
||||
client, err := docker.NewDockerClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.Close()
|
||||
if err := validateWebsitePHPImage(context.Background(), client, runtime.Image, runtime.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
website.RuntimeID = runtime.ID
|
||||
website.AppInstallID = 0
|
||||
website.Proxy = fmt.Sprintf("127.0.0.1:%s", runtime.Port)
|
||||
@@ -2685,3 +2692,59 @@ func (w WebsiteService) UpdateStream(req request.StreamUpdate) error {
|
||||
website.StreamPorts = req.StreamConfig.StreamPorts
|
||||
return websiteRepo.Save(context.Background(), &website)
|
||||
}
|
||||
|
||||
func (w WebsiteService) BatchChangePHPVersion(req request.WebsiteBatchPHPVersionReq) ([]response.WebsiteBatchPHPVersionResult, error) {
|
||||
target, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(req.RuntimeID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if target.Type != constant.RuntimePHP {
|
||||
return nil, fmt.Errorf("target runtime must be PHP")
|
||||
}
|
||||
if target.Resource == constant.ResourceLocal {
|
||||
return nil, buserr.New("ErrPHPResource")
|
||||
}
|
||||
results := make([]response.WebsiteBatchPHPVersionResult, 0, len(req.IDs))
|
||||
seen := make(map[uint]bool)
|
||||
for _, id := range req.IDs {
|
||||
if seen[id] {
|
||||
continue
|
||||
}
|
||||
seen[id] = true
|
||||
result := response.WebsiteBatchPHPVersionResult{ID: id, Status: "failed"}
|
||||
website, err := websiteRepo.GetFirst(repo.WithByID(id))
|
||||
if err != nil {
|
||||
result.Message = err.Error()
|
||||
results = append(results, result)
|
||||
continue
|
||||
}
|
||||
result.Domain = website.PrimaryDomain
|
||||
if website.Type != constant.Runtime {
|
||||
result.Status = "skipped"
|
||||
result.Message = "notPHP"
|
||||
} else {
|
||||
runtime, lookupErr := runtimeRepo.GetFirst(context.Background(), repo.WithByID(website.RuntimeID))
|
||||
switch {
|
||||
case lookupErr != nil:
|
||||
result.Message = lookupErr.Error()
|
||||
case runtime.Type != constant.RuntimePHP:
|
||||
result.Status = "skipped"
|
||||
result.Message = "notPHP"
|
||||
case runtime.Resource == constant.ResourceLocal:
|
||||
result.Status = "skipped"
|
||||
result.Message = "localPHP"
|
||||
case website.RuntimeID == req.RuntimeID:
|
||||
result.Status = "skipped"
|
||||
result.Message = "samePHP"
|
||||
default:
|
||||
if err := w.ChangePHPVersion(request.WebsitePHPVersionReq{WebsiteID: id, RuntimeID: req.RuntimeID}); err != nil {
|
||||
result.Message = err.Error()
|
||||
} else {
|
||||
result.Status = "success"
|
||||
}
|
||||
}
|
||||
}
|
||||
results = append(results, result)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/nginx"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/nginx/parser"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/re"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -2136,3 +2138,23 @@ func getManualWebsiteSSL(req request.WebsiteHTTPSOp) (model.WebsiteSSL, error) {
|
||||
websiteSSL.Status = constant.SSLReady
|
||||
return websiteSSL, nil
|
||||
}
|
||||
|
||||
type websitePHPImageInspector interface {
|
||||
ImageInspect(context.Context, string, ...client.ImageInspectOption) (image.InspectResponse, error)
|
||||
}
|
||||
|
||||
// Let Docker resolve the full reference, including registries, tags, digests and IDs.
|
||||
// A missing source image must not prevent switching away from that environment.
|
||||
func validateWebsitePHPImage(ctx context.Context, inspector websitePHPImageInspector, reference, name string) error {
|
||||
if strings.TrimSpace(reference) == "" {
|
||||
return buserr.WithName("ErrImageNotExist", name)
|
||||
}
|
||||
_, err := inspector.ImageInspect(ctx, reference)
|
||||
if client.IsErrNotFound(err) {
|
||||
return buserr.WithName("ErrImageNotExist", name)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("inspect PHP runtime %s image %s: %w", name, reference, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ func (a *WebsiteRouter) InitRouter(Router *gin.RouterGroup) {
|
||||
websiteRouter.POST("/lbs/file", baseApi.UpdateLoadBalanceFile)
|
||||
|
||||
websiteRouter.POST("/php/version", baseApi.ChangePHPVersion)
|
||||
websiteRouter.POST("/php/version/batch", baseApi.BatchChangePHPVersion)
|
||||
|
||||
websiteRouter.POST("/realip/config", baseApi.SetRealIPConfig)
|
||||
websiteRouter.GET("/realip/config/:id", baseApi.GetRealIPConfig)
|
||||
|
||||
@@ -75,6 +75,8 @@ export namespace Website {
|
||||
}
|
||||
|
||||
export interface WebSiteSearch extends ReqPage {
|
||||
type?: string;
|
||||
runtimeType?: string;
|
||||
name: string;
|
||||
orderBy: string;
|
||||
order: string;
|
||||
@@ -576,6 +578,18 @@ export namespace Website {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface BatchPHPVersionChange {
|
||||
ids: number[];
|
||||
runtimeID: number;
|
||||
}
|
||||
|
||||
export interface BatchPHPVersionResult {
|
||||
id: number;
|
||||
domain: string;
|
||||
status: 'success' | 'failed' | 'skipped';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface PHPVersionChange {
|
||||
websiteID: number;
|
||||
runtimeID: number;
|
||||
|
||||
@@ -466,3 +466,7 @@ export const importCA = (params: {
|
||||
}) => {
|
||||
return http.post(`/websites/ca/import`, params);
|
||||
};
|
||||
|
||||
export const batchChangePHPVersion = (req: Website.BatchPHPVersionChange) => {
|
||||
return http.post<Website.BatchPHPVersionResult[]>(`/websites/php/version/batch`, req, 600000);
|
||||
};
|
||||
|
||||
@@ -4636,6 +4636,17 @@ const message = {
|
||||
isEdirWarn: 'Changes to docker-compose.yml were detected. Please review the diff.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'Switch PHP version',
|
||||
batchPHPHelper:
|
||||
'Only PHP websites will be changed. Other websites are skipped. Local PHP environments are not supported.',
|
||||
batchPHPCount: 'Selected: {0}; PHP websites: {1}; others: {2}.',
|
||||
notPHP: 'Not a PHP website',
|
||||
localPHP: 'Local PHP is not supported',
|
||||
samePHP: 'Already using the target PHP environment',
|
||||
batchPHPResult: 'Results',
|
||||
batchPHPStatus_success: 'Succeeded',
|
||||
batchPHPStatus_failed: 'Failed',
|
||||
batchPHPStatus_skipped: 'Skipped',
|
||||
sslDomainMismatchWebsite: 'The certificate domains do not match the website domains',
|
||||
primaryDomain: 'Primary domain',
|
||||
otherDomains: 'Other domains',
|
||||
|
||||
@@ -4725,6 +4725,17 @@ const message = {
|
||||
isEdirWarn: 'Se detectaron cambios en el archivo docker-compose.yml. Revise la comparación.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'Cambiar versión de PHP',
|
||||
batchPHPHelper:
|
||||
'Solo se modificarán los sitios PHP. Los demás se omitirán. No se admiten entornos PHP locales.',
|
||||
batchPHPCount: 'Sitios seleccionados: {0}; sitios PHP: {1}; otros: {2}.',
|
||||
notPHP: 'No es un sitio PHP',
|
||||
localPHP: 'No se admiten entornos PHP locales',
|
||||
samePHP: 'Ya utiliza el entorno PHP de destino',
|
||||
batchPHPResult: 'Resultados',
|
||||
batchPHPStatus_success: 'Correcto',
|
||||
batchPHPStatus_failed: 'Error',
|
||||
batchPHPStatus_skipped: 'Omitido',
|
||||
sslDomainMismatchWebsite: 'Los dominios del certificado no coinciden con los dominios del sitio web',
|
||||
primaryDomain: 'Dominio principal',
|
||||
otherDomains: 'Otros dominios',
|
||||
|
||||
@@ -4594,6 +4594,17 @@ const message = {
|
||||
isEdirWarn: 'تغییرات در docker-compose.yml شناسایی شد. لطفاً تفاوت را بررسی کنید.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'تغییر نسخه PHP',
|
||||
batchPHPHelper:
|
||||
'فقط سایتهای PHP تغییر میکنند. سایر سایتها نادیده گرفته میشوند. محیطهای PHP محلی پشتیبانی نمیشوند.',
|
||||
batchPHPCount: 'سایتهای انتخابشده: {0}؛ سایتهای PHP: {1}؛ سایر: {2}.',
|
||||
notPHP: 'سایت PHP نیست',
|
||||
localPHP: 'محیطهای PHP محلی پشتیبانی نمیشوند',
|
||||
samePHP: 'از قبل از محیط PHP مقصد استفاده میکند',
|
||||
batchPHPResult: 'نتایج',
|
||||
batchPHPStatus_success: 'موفق',
|
||||
batchPHPStatus_failed: 'ناموفق',
|
||||
batchPHPStatus_skipped: 'رد شد',
|
||||
sslDomainMismatchWebsite: 'دامنههای گواهی با دامنههای وبسایت مطابقت ندارند',
|
||||
primaryDomain: 'دامنه اصلی',
|
||||
otherDomains: 'سایر دامنهها',
|
||||
|
||||
@@ -4617,6 +4617,17 @@ const message = {
|
||||
isEdirWarn: 'docker-compose.yml ファイルの変更が検出されました。差分を確認してください。',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'PHP バージョンを切り替え',
|
||||
batchPHPHelper:
|
||||
'PHP サイトのみ変更します。他のサイトはスキップされます。ローカル PHP 環境はサポートされていません。',
|
||||
batchPHPCount: '選択したサイト: {0}、PHP サイト: {1}、その他: {2}。',
|
||||
notPHP: 'PHP サイトではありません',
|
||||
localPHP: 'ローカル PHP 環境はサポートされていません',
|
||||
samePHP: '既に対象の PHP 環境を使用しています',
|
||||
batchPHPResult: '処理結果',
|
||||
batchPHPStatus_success: '成功',
|
||||
batchPHPStatus_failed: '失敗',
|
||||
batchPHPStatus_skipped: 'スキップ',
|
||||
sslDomainMismatchWebsite: '証明書のドメインがウェブサイトのドメインと一致しません',
|
||||
primaryDomain: 'プライマリドメイン',
|
||||
otherDomains: '他のドメイン',
|
||||
|
||||
@@ -4535,6 +4535,16 @@ const message = {
|
||||
isEdirWarn: 'docker-compose.yml 파일 변경이 감지되었습니다. 차이점을 확인해 주세요.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'PHP 버전 전환',
|
||||
batchPHPHelper: 'PHP 웹사이트에만 적용됩니다. 다른 웹사이트는 건너뜁니다. 로컬 PHP 환경은 지원되지 않습니다.',
|
||||
batchPHPCount: '선택한 웹사이트: {0}, PHP 웹사이트: {1}, 기타: {2}.',
|
||||
notPHP: 'PHP 웹사이트가 아닙니다',
|
||||
localPHP: '로컬 PHP 환경은 지원되지 않습니다',
|
||||
samePHP: '이미 대상 PHP 환경을 사용 중입니다',
|
||||
batchPHPResult: '처리 결과',
|
||||
batchPHPStatus_success: '성공',
|
||||
batchPHPStatus_failed: '실패',
|
||||
batchPHPStatus_skipped: '건너뜀',
|
||||
sslDomainMismatchWebsite: '인증서 도메인이 웹사이트 도메인과 일치하지 않습니다',
|
||||
primaryDomain: '기본 도메인',
|
||||
otherDomains: '기타 도메인',
|
||||
|
||||
@@ -4497,6 +4497,16 @@ const message = {
|
||||
isEdirWarn: 'ກວດພົບການປ່ຽນແປງໃນ docker-compose.yml. ກະລຸນາກວດສອບຄວາມແຕກຕ່າງ.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'ປ່ຽນເວີຊັນ PHP',
|
||||
batchPHPHelper: 'ປ່ຽນແປງສະເພາະເວັບໄຊ PHP. ເວັບໄຊອື່ນຈະຖືກຂ້າມ. ບໍ່ຮອງຮັບສະພາບແວດລ້ອມ PHP ພາຍໃນເຄື່ອງ.',
|
||||
batchPHPCount: 'ເວັບໄຊທີ່ເລືອກ: {0}; ເວັບໄຊ PHP: {1}; ອື່ນໆ: {2}.',
|
||||
notPHP: 'ບໍ່ແມ່ນເວັບໄຊ PHP',
|
||||
localPHP: 'ບໍ່ຮອງຮັບສະພາບແວດລ້ອມ PHP ພາຍໃນເຄື່ອງ',
|
||||
samePHP: 'ກຳລັງໃຊ້ສະພາບແວດລ້ອມ PHP ເປົ້າໝາຍແລ້ວ',
|
||||
batchPHPResult: 'ຜົນການດຳເນີນງານ',
|
||||
batchPHPStatus_success: 'ສຳເລັດ',
|
||||
batchPHPStatus_failed: 'ລົ້ມເຫຼວ',
|
||||
batchPHPStatus_skipped: 'ຂ້າມແລ້ວ',
|
||||
sslDomainMismatchWebsite: 'ໂດເມນຂອງໃບຢັ້ງຢືນບໍ່ກົງກັບໂດເມນຂອງເວັບໄຊ',
|
||||
primaryDomain: 'ໂດເມນຫຼັກ',
|
||||
otherDomains: 'ໂດເມນອື່ນໆ',
|
||||
|
||||
@@ -4708,6 +4708,17 @@ const message = {
|
||||
isEdirWarn: 'Perubahan pada fail docker-compose.yml telah dikesan. Sila semak perbezaannya.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'Tukar versi PHP',
|
||||
batchPHPHelper:
|
||||
'Hanya laman PHP akan diubah. Laman lain akan dilangkau. Persekitaran PHP setempat tidak disokong.',
|
||||
batchPHPCount: 'Laman dipilih: {0}; laman PHP: {1}; lain-lain: {2}.',
|
||||
notPHP: 'Bukan laman PHP',
|
||||
localPHP: 'Persekitaran PHP setempat tidak disokong',
|
||||
samePHP: 'Sudah menggunakan persekitaran PHP sasaran',
|
||||
batchPHPResult: 'Keputusan',
|
||||
batchPHPStatus_success: 'Berjaya',
|
||||
batchPHPStatus_failed: 'Gagal',
|
||||
batchPHPStatus_skipped: 'Dilangkau',
|
||||
sslDomainMismatchWebsite: 'Domain sijil tidak sepadan dengan domain laman web',
|
||||
primaryDomain: 'Domain Utama',
|
||||
otherDomains: 'Domain Lain',
|
||||
|
||||
@@ -4731,6 +4731,17 @@ const message = {
|
||||
isEdirWarn: 'Foram detectadas alterações no arquivo docker-compose.yml. Revise a comparação.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'Alterar versão do PHP',
|
||||
batchPHPHelper:
|
||||
'Somente sites PHP serão alterados. Os demais serão ignorados. Ambientes PHP locais não são compatíveis.',
|
||||
batchPHPCount: 'Sites selecionados: {0}; sites PHP: {1}; outros: {2}.',
|
||||
notPHP: 'Não é um site PHP',
|
||||
localPHP: 'Ambientes PHP locais não são compatíveis',
|
||||
samePHP: 'Já utiliza o ambiente PHP de destino',
|
||||
batchPHPResult: 'Resultados',
|
||||
batchPHPStatus_success: 'Sucesso',
|
||||
batchPHPStatus_failed: 'Falha',
|
||||
batchPHPStatus_skipped: 'Ignorado',
|
||||
sslDomainMismatchWebsite: 'Os domínios do certificado não correspondem aos domínios do site',
|
||||
primaryDomain: 'Domínio principal',
|
||||
otherDomains: 'Outros domínios',
|
||||
|
||||
@@ -4702,6 +4702,17 @@ const message = {
|
||||
isEdirWarn: 'Обнаружены изменения в файле docker-compose.yml. Проверьте различия.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'Переключить версию PHP',
|
||||
batchPHPHelper:
|
||||
'Изменения применяются только к сайтам PHP. Остальные сайты будут пропущены. Локальные окружения PHP не поддерживаются.',
|
||||
batchPHPCount: 'Выбрано сайтов: {0}; сайтов PHP: {1}; остальных: {2}.',
|
||||
notPHP: 'Не является сайтом PHP',
|
||||
localPHP: 'Локальные окружения PHP не поддерживаются',
|
||||
samePHP: 'Уже используется целевое окружение PHP',
|
||||
batchPHPResult: 'Результаты',
|
||||
batchPHPStatus_success: 'Успешно',
|
||||
batchPHPStatus_failed: 'Ошибка',
|
||||
batchPHPStatus_skipped: 'Пропущено',
|
||||
sslDomainMismatchWebsite: 'Домены сертификата не соответствуют доменам сайта',
|
||||
primaryDomain: 'Основной домен',
|
||||
otherDomains: 'Другие домены',
|
||||
|
||||
@@ -4709,6 +4709,16 @@ const message = {
|
||||
isEdirWarn: 'docker-compose.yml dosyasında değişiklikler algılandı. Lütfen farkları inceleyin.',
|
||||
},
|
||||
website: {
|
||||
batchPHP: 'PHP sürümünü değiştir',
|
||||
batchPHPHelper: 'Yalnızca PHP siteleri değiştirilir. Diğer siteler atlanır. Yerel PHP ortamları desteklenmez.',
|
||||
batchPHPCount: 'Seçilen siteler: {0}; PHP siteleri: {1}; diğerleri: {2}.',
|
||||
notPHP: 'PHP sitesi değil',
|
||||
localPHP: 'Yerel PHP ortamları desteklenmez',
|
||||
samePHP: 'Hedef PHP ortamı zaten kullanılıyor',
|
||||
batchPHPResult: 'Sonuçlar',
|
||||
batchPHPStatus_success: 'Başarılı',
|
||||
batchPHPStatus_failed: 'Başarısız',
|
||||
batchPHPStatus_skipped: 'Atlandı',
|
||||
sslDomainMismatchWebsite: 'Sertifika alan adları web sitesinin alan adlarıyla eşleşmiyor',
|
||||
primaryDomain: 'Birincil alan adı',
|
||||
otherDomains: 'Diğer alan adları',
|
||||
|
||||
@@ -4295,6 +4295,16 @@ const message = {
|
||||
isEdirWarn: '偵測到 docker-compose.yml 檔案被修改,請檢視對比',
|
||||
},
|
||||
website: {
|
||||
batchPHP: '切換 PHP 版本',
|
||||
batchPHPHelper: '僅對 PHP 網站生效,其他網站自動略過。不支援本機 PHP 環境。',
|
||||
batchPHPCount: '已選擇 {0} 個網站,其中 PHP 網站 {1} 個,其他 {2} 個。',
|
||||
notPHP: '非 PHP 網站',
|
||||
localPHP: '不支援本機 PHP 環境',
|
||||
samePHP: '已使用目標 PHP 環境',
|
||||
batchPHPResult: '處理結果',
|
||||
batchPHPStatus_success: '成功',
|
||||
batchPHPStatus_failed: '失敗',
|
||||
batchPHPStatus_skipped: '略過',
|
||||
sslDomainMismatchWebsite: '憑證網域與網站網域不相符',
|
||||
primaryDomain: '主域名',
|
||||
otherDomains: '其他域名',
|
||||
|
||||
@@ -4329,6 +4329,16 @@ const message = {
|
||||
isEdirWarn: '检测到 docker-compose.yml 文件被修改,请查看对比',
|
||||
},
|
||||
website: {
|
||||
batchPHP: '切换 PHP 版本',
|
||||
batchPHPHelper: '仅对 PHP 网站生效,其他网站自动跳过。不支持本地 PHP 环境。',
|
||||
batchPHPCount: '已选择 {0} 个网站,其中 PHP 网站 {1} 个,其他 {2} 个。',
|
||||
notPHP: '非 PHP 网站',
|
||||
localPHP: '不支持本地 PHP 环境',
|
||||
samePHP: '已使用目标 PHP 环境',
|
||||
batchPHPResult: '处理结果',
|
||||
batchPHPStatus_success: '成功',
|
||||
batchPHPStatus_failed: '失败',
|
||||
batchPHPStatus_skipped: '跳过',
|
||||
sslDomainMismatchWebsite: '证书域名与网站域名不匹配',
|
||||
primaryDomain: '主域名',
|
||||
otherDomains: '其他域名',
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="open"
|
||||
:title="$t('website.batchPHP')"
|
||||
width="600px"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!loading"
|
||||
:show-close="!loading"
|
||||
>
|
||||
<el-alert :title="$t('website.batchPHPHelper')" type="info" :closable="false" />
|
||||
<p>{{ $t('website.batchPHPCount', [sites.length, eligible.length, sites.length - eligible.length]) }}</p>
|
||||
<el-select v-model="runtimeID" :disabled="loading || !!results" :loading="fetching" class="w-full">
|
||||
<el-option
|
||||
v-for="item in versions"
|
||||
:key="item.id"
|
||||
:value="item.id"
|
||||
:label="item.name + ' [' + item.version + ']'"
|
||||
:disabled="item.resource === 'local'"
|
||||
/>
|
||||
</el-select>
|
||||
<el-table v-if="results" :data="results" max-height="350">
|
||||
<el-table-column prop="domain" :label="$t('website.primaryDomain')" />
|
||||
<el-table-column :label="$t('website.batchPHPResult')">
|
||||
<template #default="{ row }">
|
||||
{{ $t('website.batchPHPStatus_' + row.status) }}
|
||||
<span v-if="row.message">
|
||||
:
|
||||
{{
|
||||
['notPHP', 'localPHP', 'samePHP'].includes(row.message)
|
||||
? $t('website.' + row.message)
|
||||
: row.message
|
||||
}}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<template #footer>
|
||||
<el-button :disabled="loading" @click="open = false">{{ $t('commons.button.close') }}</el-button>
|
||||
<el-button
|
||||
v-if="!results"
|
||||
v-permission
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
:disabled="fetching || !runtimeID || !eligible.length"
|
||||
@click="submit"
|
||||
>
|
||||
{{ $t('commons.button.confirm') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { Website } from '@/api/interface/website';
|
||||
import { SearchRuntimes } from '@/api/modules/runtime';
|
||||
import { batchChangePHPVersion } from '@/api/modules/website';
|
||||
const emit = defineEmits(['updated']);
|
||||
type Site = { id: number; primaryDomain: string; type: string; runtimeType?: string };
|
||||
const open = ref(false);
|
||||
const loading = ref(false);
|
||||
const fetching = ref(false);
|
||||
const runtimeID = ref<number>();
|
||||
const sites = ref<Site[]>([]);
|
||||
const versions = ref<{ id: number; name: string; version: string; resource: string }[]>([]);
|
||||
const results = ref<Website.BatchPHPVersionResult[]>();
|
||||
const eligible = computed(() => sites.value.filter((site) => site.type === 'runtime' && site.runtimeType === 'php'));
|
||||
let runtimeRequestID = 0;
|
||||
const acceptParams = async (selected: Site[]) => {
|
||||
const requestID = ++runtimeRequestID;
|
||||
sites.value = [...selected];
|
||||
runtimeID.value = undefined;
|
||||
results.value = undefined;
|
||||
versions.value = [];
|
||||
open.value = true;
|
||||
fetching.value = true;
|
||||
try {
|
||||
const options: typeof versions.value = [];
|
||||
let page = 1;
|
||||
while (true) {
|
||||
const { data } = await SearchRuntimes({ page, pageSize: 200, type: 'php' });
|
||||
if (requestID !== runtimeRequestID || !open.value) return;
|
||||
const items = data.items || [];
|
||||
options.push(
|
||||
...items.map((item) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
resource: item.resource,
|
||||
version: item.params?.['PHP_VERSION'] || item.version,
|
||||
})),
|
||||
);
|
||||
if (!items.length || options.length >= data.total) break;
|
||||
page++;
|
||||
}
|
||||
versions.value = options;
|
||||
} catch {
|
||||
// The request interceptor reports loading errors. Keep the list empty.
|
||||
} finally {
|
||||
if (requestID === runtimeRequestID) fetching.value = false;
|
||||
}
|
||||
};
|
||||
const submit = async () => {
|
||||
if (loading.value || fetching.value || !runtimeID.value || !eligible.value.length) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await batchChangePHPVersion({
|
||||
ids: sites.value.map((site) => site.id),
|
||||
runtimeID: runtimeID.value,
|
||||
});
|
||||
results.value = data;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
emit('updated');
|
||||
}
|
||||
};
|
||||
defineExpose({ acceptParams });
|
||||
</script>
|
||||
@@ -32,16 +32,17 @@
|
||||
</template>
|
||||
<template v-if="!openNginxConfig" #rightToolBar>
|
||||
<TableViewSwitch v-model="viewMode" storage-key="website" />
|
||||
<el-select class="p-w-200" v-model="req.type" @change="search()" :disabled="disabledConfig">
|
||||
<template #prefix>{{ $t('commons.table.type') }}</template>
|
||||
<el-option :label="$t('commons.table.all')" :value="''"></el-option>
|
||||
<el-option
|
||||
v-for="item in WebsiteTypes"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
:key="item.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
<el-cascader
|
||||
class="p-w-200"
|
||||
v-model="websiteTypeFilter"
|
||||
:options="websiteTypeOptions"
|
||||
:props="{ checkStrictly: true }"
|
||||
:disabled="disabledConfig"
|
||||
@change="
|
||||
paginationConfig.currentPage = 1;
|
||||
search();
|
||||
"
|
||||
/>
|
||||
<el-select v-model="req.websiteGroupId" @change="search()" class="p-w-200" :disabled="disabledConfig">
|
||||
<template #prefix>{{ $t('commons.table.group') }}</template>
|
||||
<el-option :label="$t('commons.table.all')" :value="0"></el-option>
|
||||
@@ -59,7 +60,7 @@
|
||||
</template>
|
||||
<template v-if="!openNginxConfig" #main>
|
||||
<ComplexTable
|
||||
:selection-context="() => [req.name, req.type, req.websiteGroupId]"
|
||||
:selection-context="() => [req.name, req.type, req.runtimeType, req.websiteGroupId]"
|
||||
row-key="id"
|
||||
:cache-pagination="false"
|
||||
:pagination-config="paginationConfig"
|
||||
@@ -274,6 +275,7 @@
|
||||
<template #footerLeft="{ selected, toggleSelection }">
|
||||
<div class="footer-left-button" v-permission>
|
||||
<el-select class="p-w-200" v-model="batchReq.operate">
|
||||
<el-option :label="$t('website.batchPHP')" value="changePHP" />
|
||||
<template #prefix>
|
||||
<el-checkbox
|
||||
:model-value="selected"
|
||||
@@ -338,6 +340,7 @@
|
||||
<NginxConfig v-if="openNginxConfig" v-loading="loading" :containerName="containerName" :status="nginxStatus" />
|
||||
<TaskLog ref="taskLogRef" @close="search" />
|
||||
<OpDialog ref="opRef" @search="openTaskLog" />
|
||||
<BatchPHP ref="batchPHPRef" @updated="search" />
|
||||
<BatchSetGroup ref="batchSetGroupRef" @close="search" />
|
||||
<BatchSetHttps ref="batchSetHttpsRef" @open-task="openTaskLog" />
|
||||
</div>
|
||||
@@ -356,6 +359,7 @@ import GroupDialog from '@/components/agent-group/index.vue';
|
||||
import AppStatus from '@/components/app-status/index.vue';
|
||||
import TaskLog from '@/components/log/task/index.vue';
|
||||
import Domain from '@/views/website/website/domain/index.vue';
|
||||
import BatchPHP from '@/views/website/website/batch-op/php.vue';
|
||||
import BatchSetGroup from '@/views/website/website/batch-op/group.vue';
|
||||
import BatchSetHttps from '@/views/website/website/batch-op/https.vue';
|
||||
|
||||
@@ -395,7 +399,24 @@ const shortcuts = [
|
||||
},
|
||||
},
|
||||
];
|
||||
const WebsiteTypes = getWebsiteTypes();
|
||||
const websiteTypeOptions = computed(() => [
|
||||
{ label: i18n.global.t('commons.table.all'), value: '' },
|
||||
...getWebsiteTypes().map((item) => ({
|
||||
...item,
|
||||
...(item.value === 'runtime'
|
||||
? {
|
||||
children: [
|
||||
{ label: 'PHP', value: 'php' },
|
||||
{ label: 'Node.js', value: 'node' },
|
||||
{ label: 'Java', value: 'java' },
|
||||
{ label: 'Go', value: 'go' },
|
||||
{ label: 'Python', value: 'python' },
|
||||
{ label: '.NET', value: 'dotnet' },
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
})),
|
||||
]);
|
||||
const loading = ref(false);
|
||||
const viewMode = ref<'table' | 'card'>('table');
|
||||
const maskShow = ref(false);
|
||||
@@ -423,6 +444,7 @@ const batchReq = reactive({
|
||||
const taskLogRef = ref();
|
||||
const opRef = ref();
|
||||
const batchSetGroupRef = ref();
|
||||
const batchPHPRef = ref();
|
||||
const batchSetHttpsRef = ref();
|
||||
const nginxVersion = ref();
|
||||
const appStatusRef = ref();
|
||||
@@ -441,6 +463,7 @@ const pageState = usePageState(() => ({
|
||||
order: 'descending',
|
||||
websiteGroupId: 0,
|
||||
type: '',
|
||||
runtimeType: '',
|
||||
},
|
||||
tableSort: {
|
||||
prop: '',
|
||||
@@ -449,6 +472,13 @@ const pageState = usePageState(() => ({
|
||||
}));
|
||||
const paginationConfig = pageState.paginationConfig;
|
||||
const req = pageState.req;
|
||||
const websiteTypeFilter = computed<string[]>({
|
||||
get: () => (req.type === 'runtime' && req.runtimeType ? [req.type, req.runtimeType] : [req.type]),
|
||||
set: (value) => {
|
||||
req.type = value?.[0] || '';
|
||||
req.runtimeType = req.type === 'runtime' ? value?.[1] || '' : '';
|
||||
},
|
||||
});
|
||||
useSearchState(
|
||||
'website/website/index',
|
||||
{
|
||||
@@ -501,18 +531,21 @@ const changeSort = ({ prop, order }) => {
|
||||
search();
|
||||
};
|
||||
|
||||
let searchVersion = 0;
|
||||
const search = async () => {
|
||||
const version = ++searchVersion;
|
||||
req.page = paginationConfig.currentPage;
|
||||
req.pageSize = paginationConfig.pageSize;
|
||||
|
||||
loading.value = true;
|
||||
await searchWebsites(req)
|
||||
await searchWebsites({ ...req })
|
||||
.then((res) => {
|
||||
if (version !== searchVersion) return;
|
||||
data.value = res.data.items;
|
||||
paginationConfig.total = res.data.total;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
if (version === searchVersion) loading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -721,6 +754,9 @@ const openTaskLog = () => {
|
||||
|
||||
const batchOp = () => {
|
||||
switch (batchReq.operate) {
|
||||
case 'changePHP':
|
||||
batchPHPRef.value.acceptParams(selects.value);
|
||||
break;
|
||||
case 'setHttps':
|
||||
const tID = newUUID();
|
||||
batchReq.taskID = tID;
|
||||
|
||||
Reference in New Issue
Block a user