1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

feat: wordpress 增加6.0.2版本,修改可更新逻辑

This commit is contained in:
zhengkunwang223 2022-10-12 10:54:09 +08:00 committed by zhengkunwang223
parent c65afb7083
commit 7f4e8a25ea
12 changed files with 138 additions and 122 deletions

View File

@ -47,7 +47,7 @@
"key": "wordpress",
"name": "Wordpress",
"tags": ["WebSite"],
"versions": ["6.0.1"],
"versions": ["6.0.1","6.0.2"],
"short_desc": "老牌博客网站模版",
"icon": "wordpress.png",
"author": "Wordpress",

View File

@ -0,0 +1,22 @@
version: '3'
services:
1panel_wordpress:
image: wordpress:6.0.2
container_name: ${CONTAINER_NAME}
ports:
- ${PANEL_APP_PORT_HTTP}:80
restart: always
networks:
- 1panel
volumes:
- ./data:/var/www/html
environment:
WORDPRESS_DB_HOST: ${PANEL_DB_HOST}
WORDPRESS_DB_NAME: ${PANEL_DB_NAME}
WORDPRESS_DB_USER: ${PANEL_DB_USER}
WORDPRESS_DB_PASSWORD: ${PANEL_DB_USER_PASSWORD}
WORDPRESS_DEBUG: 1
networks:
1panel:
external: true

View File

@ -0,0 +1,45 @@
{
"formFields": [
{
"type": "service",
"key": "mysql",
"labelZh": "数据库服务",
"labelEn": "Database Service",
"required": true,
"default": "",
"envKey": "PANEL_DB_HOST"
},
{
"type": "text",
"labelZh": "数据库名",
"labelEn": "Database",
"required": true,
"default": "random",
"envKey": "PANEL_DB_NAME"
},
{
"type": "text",
"labelZh": "数据库用户",
"labelEn": "User",
"required": true,
"default": "random",
"envKey": "PANEL_DB_USER"
},
{
"type": "text",
"labelZh": "数据库用户密码",
"labelEn": "Password",
"required": true,
"default": "random",
"envKey": "PANEL_DB_USER_PASSWORD"
},
{
"type": "number",
"labelZh": "端口",
"labelEn": "Port",
"required": true,
"default": 8080,
"envKey": "PANEL_APP_PORT_HTTP"
}
]
}

View File

@ -3,7 +3,6 @@ package repo
import (
"context"
"github.com/1Panel-dev/1Panel/app/model"
"github.com/1Panel-dev/1Panel/global"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
@ -19,10 +18,7 @@ func (a AppRepo) WithKey(key string) DBOption {
func (a AppRepo) Page(page, size int, opts ...DBOption) (int64, []model.App, error) {
var apps []model.App
db := global.DB.Model(&model.App{})
for _, opt := range opts {
db = opt(db)
}
db := getDb(opts...).Model(&model.App{})
count := int64(0)
db = db.Count(&count)
err := db.Debug().Limit(size).Offset(size * (page - 1)).Preload("AppTags").Find(&apps).Error
@ -31,10 +27,7 @@ func (a AppRepo) Page(page, size int, opts ...DBOption) (int64, []model.App, err
func (a AppRepo) GetFirst(opts ...DBOption) (model.App, error) {
var app model.App
db := global.DB.Model(&model.App{})
for _, opt := range opts {
db = opt(db)
}
db := getDb(opts...).Model(&model.App{})
if err := db.Preload("AppTags").First(&app).Error; err != nil {
return app, err
}
@ -43,10 +36,7 @@ func (a AppRepo) GetFirst(opts ...DBOption) (model.App, error) {
func (a AppRepo) GetBy(opts ...DBOption) ([]model.App, error) {
var apps []model.App
db := global.DB.Model(&model.App{})
for _, opt := range opts {
db = opt(db)
}
db := getDb(opts...).Model(&model.App{})
if err := db.Preload("Details").Preload("AppTags").Find(&apps).Error; err != nil {
return apps, err
}
@ -54,25 +44,21 @@ func (a AppRepo) GetBy(opts ...DBOption) ([]model.App, error) {
}
func (a AppRepo) BatchCreate(ctx context.Context, apps []model.App) error {
db := ctx.Value("db").(*gorm.DB)
return db.Omit(clause.Associations).Create(&apps).Error
return getTx(ctx).Omit(clause.Associations).Create(&apps).Error
}
func (a AppRepo) GetByKey(ctx context.Context, key string) (model.App, error) {
db := ctx.Value("db").(*gorm.DB)
var app model.App
if err := db.Where("key = ?", key).First(&app).Error; err != nil {
if err := getTx(ctx).Where("key = ?", key).First(&app).Error; err != nil {
return app, err
}
return app, nil
}
func (a AppRepo) Create(ctx context.Context, app *model.App) error {
db := ctx.Value("db").(*gorm.DB)
return db.Omit(clause.Associations).Create(app).Error
return getTx(ctx).Omit(clause.Associations).Create(app).Error
}
func (a AppRepo) Save(ctx context.Context, app *model.App) error {
db := ctx.Value("db").(*gorm.DB)
return db.Omit(clause.Associations).Save(app).Error
return getTx(ctx).Omit(clause.Associations).Save(app).Error
}

View File

@ -3,7 +3,6 @@ package repo
import (
"context"
"github.com/1Panel-dev/1Panel/app/model"
"github.com/1Panel-dev/1Panel/global"
"gorm.io/gorm"
)
@ -23,43 +22,32 @@ func (a AppDetailRepo) WithAppId(id uint) DBOption {
func (a AppDetailRepo) GetFirst(opts ...DBOption) (model.AppDetail, error) {
var detail model.AppDetail
db := global.DB
for _, opt := range opts {
db = opt(db)
}
err := db.Find(&detail).Error
err := getDb(opts...).Model(&model.AppDetail{}).Find(&detail).Error
return detail, err
}
func (a AppDetailRepo) Update(ctx context.Context, detail model.AppDetail) error {
db := ctx.Value("db").(*gorm.DB)
return db.Save(&detail).Error
return getTx(ctx).Save(&detail).Error
}
func (a AppDetailRepo) BatchCreate(ctx context.Context, details []model.AppDetail) error {
db := ctx.Value("db").(*gorm.DB)
return db.Model(&model.AppDetail{}).Create(&details).Error
return getTx(ctx).Model(&model.AppDetail{}).Create(&details).Error
}
func (a AppDetailRepo) DeleteByAppIds(ctx context.Context, appIds []uint) error {
db := ctx.Value("db").(*gorm.DB)
return db.Where("app_id in (?)", appIds).Delete(&model.AppDetail{}).Error
return getTx(ctx).Where("app_id in (?)", appIds).Delete(&model.AppDetail{}).Error
}
func (a AppDetailRepo) GetBy(opts ...DBOption) ([]model.AppDetail, error) {
var details []model.AppDetail
db := global.DB
for _, opt := range opts {
db = opt(db)
}
err := db.Find(&details).Error
err := getDb(opts...).Find(&details).Error
return details, err
}
func (a AppDetailRepo) BatchUpdateBy(update model.AppDetail, opts ...DBOption) error {
db := global.DB.Model(model.AppDetail{})
for _, opt := range opts {
db = opt(db)
func (a AppDetailRepo) BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error {
db := getDb(opts...).Model(&model.AppDetail{})
if len(opts) == 0 {
db = db.Where("1=1")
}
return db.Updates(update).Error
return db.Updates(&maps).Error
}

View File

@ -3,7 +3,6 @@ package repo
import (
"context"
"github.com/1Panel-dev/1Panel/app/model"
"github.com/1Panel-dev/1Panel/global"
"gorm.io/gorm"
)
@ -14,6 +13,13 @@ func (a AppInstallRepo) WithDetailIdsIn(detailIds []uint) DBOption {
return g.Where("app_detail_id in (?)", detailIds)
}
}
func (a AppInstallRepo) WithDetailIdNotIn(detailIds []uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("app_detail_id not in (?)", detailIds)
}
}
func (a AppInstallRepo) WithAppId(appId uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("app_id = ?", appId)
@ -32,21 +38,15 @@ func (a AppInstallRepo) WithServiceName(serviceName string) DBOption {
}
func (a AppInstallRepo) GetBy(opts ...DBOption) ([]model.AppInstall, error) {
db := global.DB.Model(&model.AppInstall{})
for _, opt := range opts {
db = opt(db)
}
var install []model.AppInstall
db := getDb(opts...).Model(&model.AppInstall{})
err := db.Preload("App").Find(&install).Error
return install, err
}
func (a AppInstallRepo) GetFirst(opts ...DBOption) (model.AppInstall, error) {
db := global.DB.Model(&model.AppInstall{})
for _, opt := range opts {
db = opt(db)
}
var install model.AppInstall
db := getDb(opts...).Model(&model.AppInstall{})
err := db.Preload("App").First(&install).Error
return install, err
}
@ -65,26 +65,24 @@ func (a AppInstallRepo) DeleteBy(opts ...DBOption) error {
}
func (a AppInstallRepo) Delete(ctx context.Context, install model.AppInstall) error {
db := ctx.Value("db").(*gorm.DB).Model(&model.AppInstall{})
db := getTx(ctx).Model(&model.AppInstall{})
return db.Delete(&install).Error
}
func (a AppInstallRepo) Page(page, size int, opts ...DBOption) (int64, []model.AppInstall, error) {
var apps []model.AppInstall
db := global.DB.Model(&model.AppInstall{})
for _, opt := range opts {
db = opt(db)
}
db := getDb(opts...).Model(&model.AppInstall{})
count := int64(0)
db = db.Count(&count)
err := db.Debug().Limit(size).Offset(size * (page - 1)).Preload("App").Find(&apps).Error
return count, apps, err
}
func (a AppInstallRepo) BatchUpdateBy(update model.AppInstall, opts ...DBOption) error {
db := global.DB.Model(model.AppInstall{})
for _, opt := range opts {
db = opt(db)
func (a AppInstallRepo) BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error {
db := getDb(opts...).Model(&model.AppInstall{})
if len(opts) == 0 {
db = db.Where("1=1")
}
return db.Updates(update).Error
return db.Updates(&maps).Error
}

View File

@ -63,6 +63,12 @@ func (c *CommonRepo) WithIdsIn(ids []uint) DBOption {
}
}
func (c *CommonRepo) WithIdsNotIn(ids []uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id not in (?)", ids)
}
}
func getTx(ctx context.Context, opts ...DBOption) *gorm.DB {
tx := ctx.Value("db").(*gorm.DB)
for _, opt := range opts {

View File

@ -623,19 +623,28 @@ func syncCanUpdate() {
var updateDetailIds []uint
for _, detail := range details {
if common.CompareVersion(lastVersion, detail.Version) {
if app.CrossVersionUpdate || !common.IsCrossVersion(detail.Version, lastVersion) {
updateDetailIds = append(updateDetailIds, detail.ID)
}
if lastVersion == detail.Version {
continue
}
if common.CompareVersion(lastVersion, detail.Version) && (app.CrossVersionUpdate || !common.IsCrossVersion(detail.Version, lastVersion)) {
updateDetailIds = append(updateDetailIds, detail.ID)
}
}
if err := appDetailRepo.BatchUpdateBy(map[string]interface{}{"last_version": ""}); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
if err := appInstallRepo.BatchUpdateBy(map[string]interface{}{"can_update": 0}); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
if len(updateDetailIds) > 0 {
if err := appDetailRepo.BatchUpdateBy(model.AppDetail{LastVersion: lastVersion}, commonRepo.WithIdsIn(updateDetailIds)); err != nil {
if err := appDetailRepo.BatchUpdateBy(map[string]interface{}{"last_version": lastVersion}, commonRepo.WithIdsIn(updateDetailIds)); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
if err := appInstallRepo.BatchUpdateBy(model.AppInstall{CanUpdate: true}, appInstallRepo.WithDetailIdsIn(updateDetailIds)); err != nil {
if err := appInstallRepo.BatchUpdateBy(map[string]interface{}{"can_update": 1}, appInstallRepo.WithDetailIdsIn(updateDetailIds)); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error())
}
}
}
}

View File

@ -417,5 +417,6 @@ export default {
delete: 'Delete',
deleteWarn:
'Delete the operation data and delete the operation data. This operation cannot be rolled back. Do you want to continue?',
canUpdate: 'CanUpdate',
},
};

View File

@ -409,5 +409,6 @@ export default {
delete: '删除',
deleteWarn: '删除操作会把数据一并删除,此操作不可回滚,是否继续?',
syncSuccess: '同步成功',
canUpdate: '可更新',
},
};

View File

@ -3,14 +3,12 @@
<el-row :gutter="20">
<el-col :span="24">
<div style="margin-bottom: 10px">
<el-radio-group v-model="activeName">
<el-radio-button label="all" @click="routerTo('/apps/all')">
{{ $t('app.all') }}
</el-radio-button>
<el-radio-button label="installed" @click="routerTo('/apps/installed')">
{{ $t('app.installed') }}
</el-radio-button>
</el-radio-group>
<el-check-tag :checked="activeName === 'all'" @click="routerTo('/apps/all')">
{{ $t('app.all') }}
</el-check-tag>
<el-check-tag :checked="activeName === 'installed'" @click="routerTo('/apps/installed')">
{{ $t('app.installed') }}
</el-check-tag>
</div>
</el-col>
</el-row>
@ -45,47 +43,4 @@ onMounted(() => {
});
</script>
<style lang="scss">
.header {
padding-bottom: 10px;
}
.a-card {
height: 100px;
margin-top: 10px;
cursor: pointer;
padding: 1px;
.icon {
width: 100%;
height: 80%;
padding: 10%;
margin-top: 5px;
.image {
width: auto;
height: auto;
}
}
.a-detail {
margin-top: 10px;
height: 100%;
width: 100%;
.d-name {
height: 20%;
}
.d-description {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
}
}
.a-card:hover {
transform: scale(1.1);
}
</style>
<style lang="scss"></style>

View File

@ -3,7 +3,12 @@
<el-button @click="sync">{{ $t('app.sync') }}</el-button>
</div>
<ComplexTable :pagination-config="paginationConfig" :data="data" @search="search" v-loading="loading">
<el-table-column :label="$t('app.name')" prop="name"></el-table-column>
<el-table-column :label="$t('app.name')" prop="name">
<template #default="{ row }">
{{ row.name }}
<el-tag round effect="dark" v-if="row.canUpdate">{{ $t('app.canUpdate') }}</el-tag>
</template>
</el-table-column>
<!-- <el-table-column :label="$t('app.description')" prop="description"></el-table-column> -->
<el-table-column :label="$t('app.appName')" prop="appName"></el-table-column>
<el-table-column :label="$t('app.version')" prop="version"></el-table-column>