Don't call plugin register/unregister methods

This commit is contained in:
Chocobozzz 2023-05-05 14:14:26 +02:00
parent 257fa0d1a0
commit 841ddf8886
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 34 additions and 13 deletions

View File

@ -32,5 +32,10 @@ async function run () {
await initDatabaseModels(true) await initDatabaseModels(true)
const toInstall = options.npmName || options.pluginPath const toInstall = options.npmName || options.pluginPath
await PluginManager.Instance.install(toInstall, options.pluginVersion, !!options.pluginPath) await PluginManager.Instance.install({
toInstall,
version: options.pluginVersion,
fromDisk: !!options.pluginPath,
register: false
})
} }

View File

@ -25,5 +25,5 @@ async function run () {
await initDatabaseModels(true) await initDatabaseModels(true)
const toUninstall = options.npmName const toUninstall = options.npmName
await PluginManager.Instance.uninstall(toUninstall) await PluginManager.Instance.uninstall({ npmName: toUninstall, unregister: false })
} }

View File

@ -150,7 +150,7 @@ async function installPlugin (req: express.Request, res: express.Response) {
: undefined : undefined
try { try {
const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk) const plugin = await PluginManager.Instance.install({ toInstall, version: pluginVersion, fromDisk })
return res.json(plugin.toFormattedJSON()) return res.json(plugin.toFormattedJSON())
} catch (err) { } catch (err) {
@ -177,7 +177,7 @@ async function updatePlugin (req: express.Request, res: express.Response) {
async function uninstallPlugin (req: express.Request, res: express.Response) { async function uninstallPlugin (req: express.Request, res: express.Response) {
const body: ManagePlugin = req.body const body: ManagePlugin = req.body
await PluginManager.Instance.uninstall(body.npmName) await PluginManager.Instance.uninstall({ npmName: body.npmName })
return res.status(HttpStatusCode.NO_CONTENT_204).end() return res.status(HttpStatusCode.NO_CONTENT_204).end()
} }

View File

@ -325,7 +325,14 @@ export class PluginManager implements ServerHook {
// ###################### Installation ###################### // ###################### Installation ######################
async install (toInstall: string, version?: string, fromDisk = false) { async install (options: {
toInstall: string
version?: string
fromDisk?: boolean // default false
register?: boolean // default true
}) {
const { toInstall, version, fromDisk = false, register = true } = options
let plugin: PluginModel let plugin: PluginModel
let npmName: string let npmName: string
@ -357,12 +364,14 @@ export class PluginManager implements ServerHook {
logger.info('Successful installation of plugin %s.', toInstall) logger.info('Successful installation of plugin %s.', toInstall)
await this.registerPluginOrTheme(plugin) if (register) {
await this.registerPluginOrTheme(plugin)
}
} catch (rootErr) { } catch (rootErr) {
logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr })
try { try {
await this.uninstall(npmName) await this.uninstall({ npmName })
} catch (err) { } catch (err) {
logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err })
@ -394,16 +403,23 @@ export class PluginManager implements ServerHook {
// Unregister old hooks // Unregister old hooks
await this.unregister(npmName) await this.unregister(npmName)
return this.install(toUpdate, version, fromDisk) return this.install({ toInstall: toUpdate, version, fromDisk })
} }
async uninstall (npmName: string) { async uninstall (options: {
npmName: string
unregister?: boolean // default true
}) {
const { npmName, unregister } = options
logger.info('Uninstalling plugin %s.', npmName) logger.info('Uninstalling plugin %s.', npmName)
try { if (unregister) {
await this.unregister(npmName) try {
} catch (err) { await this.unregister(npmName)
logger.warn('Cannot unregister plugin %s.', npmName, { err }) } catch (err) {
logger.warn('Cannot unregister plugin %s.', npmName, { err })
}
} }
const plugin = await PluginModel.loadByNpmName(npmName) const plugin = await PluginModel.loadByNpmName(npmName)