From 587568e1cc0e33c023c1ac62dd28fef313285250 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 Jul 2019 11:18:22 +0200 Subject: Add plugin table migration table --- server/initializers/constants.ts | 2 +- server/initializers/migrations/0405-plugin.ts | 40 +++++++++++++++++++++++++++ server/lib/plugins/hooks.ts | 2 +- server/lib/plugins/plugin-manager.ts | 7 +++++ server/tests/plugins/action-hooks.ts | 2 +- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 server/initializers/migrations/0405-plugin.ts (limited to 'server') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 1111fd97f..5329d5fab 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 400 +const LAST_MIGRATION_VERSION = 405 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0405-plugin.ts b/server/initializers/migrations/0405-plugin.ts new file mode 100644 index 000000000..c55b81960 --- /dev/null +++ b/server/initializers/migrations/0405-plugin.ts @@ -0,0 +1,40 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize, + db: any +}): Promise { + { + const query = ` +CREATE TABLE IF NOT EXISTS "plugin" +( + "id" SERIAL, + "name" VARCHAR(255) NOT NULL, + "type" INTEGER NOT NULL, + "version" VARCHAR(255) NOT NULL, + "latestVersion" VARCHAR(255), + "enabled" BOOLEAN NOT NULL, + "uninstalled" BOOLEAN NOT NULL, + "peertubeEngine" VARCHAR(255) NOT NULL, + "description" VARCHAR(255), + "homepage" VARCHAR(255) NOT NULL, + "settings" JSONB, + "storage" JSONB, + "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, + "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, + PRIMARY KEY ("id") +);` + await utils.sequelize.query(query) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts index b694d4118..bcc8c674e 100644 --- a/server/lib/plugins/hooks.ts +++ b/server/lib/plugins/hooks.ts @@ -9,7 +9,7 @@ type RawFunction = (params: U) => T // Helpers to run hooks const Hooks = { wrapObject: (result: T, hookName: U) => { - return PluginManager.Instance.runHook(hookName, result) as Promise + return PluginManager.Instance.runHook(hookName, result) }, wrapPromiseFun: async (fun: PromiseFunction, params: U, hookName: V) => { diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index 6485a47c5..afc07a151 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -125,6 +125,13 @@ export class PluginManager implements ServerHook { try { await this.registerPluginOrTheme(plugin) } catch (err) { + // Try to unregister the plugin + try { + await this.unregister(PluginModel.buildNpmName(plugin.name, plugin.type)) + } catch { + // we don't care if we cannot unregister it + } + logger.error('Cannot register plugin %s, skipping.', plugin.name, { err }) } } diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 2a941148a..e28732cac 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -43,7 +43,7 @@ describe('Test plugin action hooks', function () { path: getPluginTestPath() }) - await killallServers([ servers[0] ]) + killallServers([ servers[0] ]) await reRunServer(servers[0]) }) -- cgit v1.2.3