fix: upgrade error (#1303)
This commit is contained in:
parent
638799fe0e
commit
f5c1a07f20
@ -43,6 +43,7 @@ export class PluginManager {
|
||||
this.repository.setPluginManager(this);
|
||||
this.app.resourcer.define(resourceOptions);
|
||||
this.app.acl.allow('pm', ['enable', 'disable', 'remove'], 'allowConfigure');
|
||||
this.app.acl.allow('applicationPlugins', 'list', 'allowConfigure');
|
||||
this.server = net.createServer((socket) => {
|
||||
socket.on('data', async (data) => {
|
||||
const { method, plugins } = JSON.parse(data.toString());
|
||||
@ -66,7 +67,9 @@ export class PluginManager {
|
||||
if (options?.method !== 'install' || options.reload) {
|
||||
await this.repository.load();
|
||||
}
|
||||
this.app.acl.allow('applicationPlugins', 'list');
|
||||
});
|
||||
this.app.on('beforeUpgrade', async () => {
|
||||
await this.collection.sync();
|
||||
});
|
||||
this.addStaticMultiple(options.plugins);
|
||||
}
|
||||
@ -209,11 +212,9 @@ export class PluginManager {
|
||||
transaction,
|
||||
filter: { name: plugin },
|
||||
});
|
||||
if (model) {
|
||||
throw new Error(`${plugin} plugin already exists`);
|
||||
}
|
||||
if (!model) {
|
||||
const { enabled, builtIn, installed, ...others } = options;
|
||||
await this.repository.create({
|
||||
model = await this.repository.create({
|
||||
transaction,
|
||||
values: {
|
||||
name: plugin,
|
||||
@ -226,6 +227,7 @@ export class PluginManager {
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
const file = resolve(
|
||||
process.cwd(),
|
||||
'packages',
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Database } from '@nocobase/database';
|
||||
import { Application } from './application';
|
||||
import { InstallOptions } from './plugin-manager';
|
||||
|
||||
@ -25,15 +24,17 @@ export type PluginType = typeof Plugin;
|
||||
export abstract class Plugin<O = any> implements PluginInterface {
|
||||
options: any;
|
||||
app: Application;
|
||||
db: Database;
|
||||
|
||||
constructor(app: Application, options?: any) {
|
||||
this.app = app;
|
||||
this.db = app.db;
|
||||
this.setOptions(options);
|
||||
this.afterAdd();
|
||||
}
|
||||
|
||||
get db() {
|
||||
return this.app.db;
|
||||
}
|
||||
|
||||
get enabled() {
|
||||
return this.options.enabled;
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ import {
|
||||
beforeCreateForChildrenCollection,
|
||||
beforeCreateForReverseField,
|
||||
beforeDestroyForeignKey,
|
||||
beforeInitOptions,
|
||||
beforeInitOptions
|
||||
} from './hooks';
|
||||
|
||||
import { CollectionModel, FieldModel } from './models';
|
||||
import { InheritedCollection } from '@nocobase/database';
|
||||
import { CollectionModel, FieldModel } from './models';
|
||||
|
||||
export class CollectionManagerPlugin extends Plugin {
|
||||
async beforeLoad() {
|
||||
|
@ -69,7 +69,7 @@ export class PresetNocoBase extends Plugin {
|
||||
await this.addBuiltInPlugins();
|
||||
}
|
||||
const builtInPlugins = this.getBuiltInPlugins();
|
||||
const plugins = await this.db.getRepository('applicationPlugins').find();
|
||||
const plugins = await this.app.db.getRepository('applicationPlugins').find();
|
||||
const pluginNames = plugins.map((p) => p.name);
|
||||
await this.app.pm.add(
|
||||
builtInPlugins.filter((plugin) => !pluginNames.includes(plugin)),
|
||||
|
Loading…
Reference in New Issue
Block a user