fix: update or create plugins
This commit is contained in:
parent
8eb634459d
commit
0ed164ff09
@ -1,3 +1,4 @@
|
|||||||
|
import { Repository } from '@nocobase/database';
|
||||||
import { Plugin, PluginManager } from '@nocobase/server';
|
import { Plugin, PluginManager } from '@nocobase/server';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@ -71,7 +72,7 @@ export class PresetNocoBase extends Plugin {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.app.on('beforeUpgrade', async () => {
|
this.app.on('beforeUpgrade', async () => {
|
||||||
await this.createIfNotExists();
|
await this.updateOrCreatePlugins();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +92,20 @@ export class PresetNocoBase extends Plugin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateOrCreatePlugins() {
|
||||||
|
const repository = this.app.db.getRepository<Repository>('applicationPlugins');
|
||||||
|
return Promise.all(
|
||||||
|
this.allPlugins.map((values) =>
|
||||||
|
repository.updateOrCreate({
|
||||||
|
values,
|
||||||
|
filterKeys: ['name'],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async createIfNotExists() {
|
async createIfNotExists() {
|
||||||
const repository = this.app.db.getRepository<any>('applicationPlugins');
|
const repository = this.app.db.getRepository<Repository>('applicationPlugins');
|
||||||
const existPlugins = await repository.find();
|
const existPlugins = await repository.find();
|
||||||
const existPluginNames = existPlugins.map((item) => item.name);
|
const existPluginNames = existPlugins.map((item) => item.name);
|
||||||
const plugins = this.allPlugins.filter((item) => !existPluginNames.includes(item.name));
|
const plugins = this.allPlugins.filter((item) => !existPluginNames.includes(item.name));
|
||||||
|
Loading…
Reference in New Issue
Block a user