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