From: Chocobozzz Date: Mon, 22 Jul 2019 09:18:22 +0000 (+0200) Subject: Add plugin table migration table X-Git-Tag: v1.4.0-rc.1~94 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=587568e1cc0e33c023c1ac62dd28fef313285250;p=github%2FChocobozzz%2FPeerTube.git Add plugin table migration table --- 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]) }) diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts index 60f4130f5..3d59a7428 100644 --- a/shared/core-utils/plugins/hooks.ts +++ b/shared/core-utils/plugins/hooks.ts @@ -8,7 +8,7 @@ function getHookType (hookName: string) { return HookType.STATIC } -async function internalRunHook (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { +async function internalRunHook (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { try { if (hookType === HookType.FILTER) { const p = handler(result, params)