diff --git a/packages/core/server/src/plugin-manager/plugin-manager.ts b/packages/core/server/src/plugin-manager/plugin-manager.ts index b88ae36f0..a0eb0e638 100644 --- a/packages/core/server/src/plugin-manager/plugin-manager.ts +++ b/packages/core/server/src/plugin-manager/plugin-manager.ts @@ -1027,6 +1027,9 @@ export class PluginManager { } this.app.log.debug(`upgrade plugin [${plugin.name}]`); await plugin.upgrade(); + for (const feature of plugin.featureInstances) { + await feature.upgrade(); + } plugin.state.upgraded = true; } await this.repository.update({ diff --git a/packages/plugins/@hera/plugin-core/src/server/features/departments.ts b/packages/plugins/@hera/plugin-core/src/server/features/departments.ts index 1afea7348..6edf2871b 100644 --- a/packages/plugins/@hera/plugin-core/src/server/features/departments.ts +++ b/packages/plugins/@hera/plugin-core/src/server/features/departments.ts @@ -1,6 +1,5 @@ -import { resolve } from 'path'; import type { CollectionRepository } from '@tachybase/plugin-collection-manager'; -import { Plugin } from '@tachybase/server'; +import { InstallOptions, Plugin } from '@tachybase/server'; import { aggregateSearch, @@ -32,14 +31,14 @@ export class DepartmentsPlugin extends Plugin { }); } async load() { - this.app.resource({ + this.app.resourcer.define({ name: 'users', actions: { listExcludeDept: listExcludeDept, setMainDepartment: setMainDepartmentAction, }, }); - this.app.resource({ + this.app.resourcer.define({ name: 'departments', actions: { aggregateSearch: aggregateSearch, @@ -84,7 +83,12 @@ export class DepartmentsPlugin extends Plugin { this.app.cache.del(`departments:${userId}`); }); } - async install(options) { + + async upgrade() { + await this.install(); + } + + async install(options?: InstallOptions) { const collectionRepo = this.db.getRepository<CollectionRepository>('collections'); if (collectionRepo) { await collectionRepo.db2cm('departments'); diff --git a/packages/plugins/@hera/plugin-core/src/server/plugin.ts b/packages/plugins/@hera/plugin-core/src/server/plugin.ts index d39f2085d..2cadfdde3 100644 --- a/packages/plugins/@hera/plugin-core/src/server/plugin.ts +++ b/packages/plugins/@hera/plugin-core/src/server/plugin.ts @@ -1,7 +1,7 @@ import './actions'; import path from 'path'; -import Application, { InstallOptions, NoticeLevel, Plugin, type PluginOptions } from '@tachybase/server'; +import { Plugin } from '@tachybase/server'; import { Container } from '@tachybase/utils'; import { DepartmentsPlugin } from './features/departments'; @@ -13,22 +13,14 @@ import { SqlLoader } from './services/sql-loader'; import { WebControllerService as WebService } from './services/web-service'; export class PluginCoreServer extends Plugin { - pluginDepartments: DepartmentsPlugin; - constructor(app: Application, options?: PluginOptions) { - super(app, options); - this.pluginDepartments = new DepartmentsPlugin(app, options); - } async afterAdd() { this.db.registerFieldTypes({ calc: CalcField, tstzrange: TstzrangeField, }); - } - beforeLoad() { - this.pluginDepartments.beforeLoad(); + this.addFeature(DepartmentsPlugin); } async load() { - await this.pluginDepartments.load(); try { await Container.get(ConnectionManager).load(); const fontManger = Container.get(FontManager); @@ -43,9 +35,6 @@ export class PluginCoreServer extends Plugin { console.warn(err); } } - async install(options?: InstallOptions) { - await this.pluginDepartments.install(options); - } async afterEnable() {} async afterDisable() {} async remove() {}