diff options
-rwxr-xr-x | scripts/plugin/install.ts | 7 | ||||
-rwxr-xr-x | scripts/plugin/uninstall.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/plugins.ts | 4 | ||||
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 34 |
4 files changed, 34 insertions, 13 deletions
diff --git a/scripts/plugin/install.ts b/scripts/plugin/install.ts index 0795d7c93..138f34446 100755 --- a/scripts/plugin/install.ts +++ b/scripts/plugin/install.ts | |||
@@ -32,5 +32,10 @@ async function run () { | |||
32 | await initDatabaseModels(true) | 32 | await initDatabaseModels(true) |
33 | 33 | ||
34 | const toInstall = options.npmName || options.pluginPath | 34 | const toInstall = options.npmName || options.pluginPath |
35 | await PluginManager.Instance.install(toInstall, options.pluginVersion, !!options.pluginPath) | 35 | await PluginManager.Instance.install({ |
36 | toInstall, | ||
37 | version: options.pluginVersion, | ||
38 | fromDisk: !!options.pluginPath, | ||
39 | register: false | ||
40 | }) | ||
36 | } | 41 | } |
diff --git a/scripts/plugin/uninstall.ts b/scripts/plugin/uninstall.ts index 152b651dd..770594685 100755 --- a/scripts/plugin/uninstall.ts +++ b/scripts/plugin/uninstall.ts | |||
@@ -25,5 +25,5 @@ async function run () { | |||
25 | await initDatabaseModels(true) | 25 | await initDatabaseModels(true) |
26 | 26 | ||
27 | const toUninstall = options.npmName | 27 | const toUninstall = options.npmName |
28 | await PluginManager.Instance.uninstall(toUninstall) | 28 | await PluginManager.Instance.uninstall({ npmName: toUninstall, unregister: false }) |
29 | } | 29 | } |
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index de9e055dc..e85fd6e11 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts | |||
@@ -150,7 +150,7 @@ async function installPlugin (req: express.Request, res: express.Response) { | |||
150 | : undefined | 150 | : undefined |
151 | 151 | ||
152 | try { | 152 | try { |
153 | const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk) | 153 | const plugin = await PluginManager.Instance.install({ toInstall, version: pluginVersion, fromDisk }) |
154 | 154 | ||
155 | return res.json(plugin.toFormattedJSON()) | 155 | return res.json(plugin.toFormattedJSON()) |
156 | } catch (err) { | 156 | } catch (err) { |
@@ -177,7 +177,7 @@ async function updatePlugin (req: express.Request, res: express.Response) { | |||
177 | async function uninstallPlugin (req: express.Request, res: express.Response) { | 177 | async function uninstallPlugin (req: express.Request, res: express.Response) { |
178 | const body: ManagePlugin = req.body | 178 | const body: ManagePlugin = req.body |
179 | 179 | ||
180 | await PluginManager.Instance.uninstall(body.npmName) | 180 | await PluginManager.Instance.uninstall({ npmName: body.npmName }) |
181 | 181 | ||
182 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 182 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
183 | } | 183 | } |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index d368aecfc..ca7275366 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -325,7 +325,14 @@ export class PluginManager implements ServerHook { | |||
325 | 325 | ||
326 | // ###################### Installation ###################### | 326 | // ###################### Installation ###################### |
327 | 327 | ||
328 | async install (toInstall: string, version?: string, fromDisk = false) { | 328 | async install (options: { |
329 | toInstall: string | ||
330 | version?: string | ||
331 | fromDisk?: boolean // default false | ||
332 | register?: boolean // default true | ||
333 | }) { | ||
334 | const { toInstall, version, fromDisk = false, register = true } = options | ||
335 | |||
329 | let plugin: PluginModel | 336 | let plugin: PluginModel |
330 | let npmName: string | 337 | let npmName: string |
331 | 338 | ||
@@ -357,12 +364,14 @@ export class PluginManager implements ServerHook { | |||
357 | 364 | ||
358 | logger.info('Successful installation of plugin %s.', toInstall) | 365 | logger.info('Successful installation of plugin %s.', toInstall) |
359 | 366 | ||
360 | await this.registerPluginOrTheme(plugin) | 367 | if (register) { |
368 | await this.registerPluginOrTheme(plugin) | ||
369 | } | ||
361 | } catch (rootErr) { | 370 | } catch (rootErr) { |
362 | logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) | 371 | logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr }) |
363 | 372 | ||
364 | try { | 373 | try { |
365 | await this.uninstall(npmName) | 374 | await this.uninstall({ npmName }) |
366 | } catch (err) { | 375 | } catch (err) { |
367 | logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) | 376 | logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err }) |
368 | 377 | ||
@@ -394,16 +403,23 @@ export class PluginManager implements ServerHook { | |||
394 | // Unregister old hooks | 403 | // Unregister old hooks |
395 | await this.unregister(npmName) | 404 | await this.unregister(npmName) |
396 | 405 | ||
397 | return this.install(toUpdate, version, fromDisk) | 406 | return this.install({ toInstall: toUpdate, version, fromDisk }) |
398 | } | 407 | } |
399 | 408 | ||
400 | async uninstall (npmName: string) { | 409 | async uninstall (options: { |
410 | npmName: string | ||
411 | unregister?: boolean // default true | ||
412 | }) { | ||
413 | const { npmName, unregister } = options | ||
414 | |||
401 | logger.info('Uninstalling plugin %s.', npmName) | 415 | logger.info('Uninstalling plugin %s.', npmName) |
402 | 416 | ||
403 | try { | 417 | if (unregister) { |
404 | await this.unregister(npmName) | 418 | try { |
405 | } catch (err) { | 419 | await this.unregister(npmName) |
406 | logger.warn('Cannot unregister plugin %s.', npmName, { err }) | 420 | } catch (err) { |
421 | logger.warn('Cannot unregister plugin %s.', npmName, { err }) | ||
422 | } | ||
407 | } | 423 | } |
408 | 424 | ||
409 | const plugin = await PluginModel.loadByNpmName(npmName) | 425 | const plugin = await PluginModel.loadByNpmName(npmName) |