diff --git a/apps/list.json b/apps/list.json index c0275066a..bca1f8a0e 100644 --- a/apps/list.json +++ b/apps/list.json @@ -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", diff --git a/apps/wordpress/6.0.2/docker-compose.yml b/apps/wordpress/6.0.2/docker-compose.yml new file mode 100644 index 000000000..cdca9269e --- /dev/null +++ b/apps/wordpress/6.0.2/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/apps/wordpress/6.0.2/params.json b/apps/wordpress/6.0.2/params.json new file mode 100644 index 000000000..82b91fbe7 --- /dev/null +++ b/apps/wordpress/6.0.2/params.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/backend/app/repo/app.go b/backend/app/repo/app.go index 841181a2c..fa808952e 100644 --- a/backend/app/repo/app.go +++ b/backend/app/repo/app.go @@ -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 } diff --git a/backend/app/repo/app_detail.go b/backend/app/repo/app_detail.go index 92fc14603..ffa100811 100644 --- a/backend/app/repo/app_detail.go +++ b/backend/app/repo/app_detail.go @@ -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 } diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index 23eaf00fa..f50645e32 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -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 } diff --git a/backend/app/repo/common.go b/backend/app/repo/common.go index a628f5ca5..853ba3346 100644 --- a/backend/app/repo/common.go +++ b/backend/app/repo/common.go @@ -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 { diff --git a/backend/app/service/app.go b/backend/app/service/app.go index c96d49e42..004bb8d03 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -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()) } } + } } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index a7807b596..97c8ffa56 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -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', }, }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 3ba45f565..73fcfb1c4 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -409,5 +409,6 @@ export default { delete: '删除', deleteWarn: '删除操作会把数据一并删除,此操作不可回滚,是否继续?', syncSuccess: '同步成功', + canUpdate: '可更新', }, }; diff --git a/frontend/src/views/app-store/index.vue b/frontend/src/views/app-store/index.vue index ad541ec77..f13bbe0b3 100644 --- a/frontend/src/views/app-store/index.vue +++ b/frontend/src/views/app-store/index.vue @@ -3,14 +3,12 @@ - - - {{ $t('app.all') }} - - - {{ $t('app.installed') }} - - + + {{ $t('app.all') }} + + + {{ $t('app.installed') }} + @@ -45,47 +43,4 @@ onMounted(() => { }); - + diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 377534941..cba490ab6 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -3,7 +3,12 @@ {{ $t('app.sync') }} - + + + {{ row.name }} + {{ $t('app.canUpdate') }} + +