aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-22 11:18:22 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit587568e1cc0e33c023c1ac62dd28fef313285250 (patch)
treee905b243d8a5fe5fb18ef5ef821c867cdde45aa6
parent6691c52280363fc42f7865230ebb3741f02fff23 (diff)
downloadPeerTube-587568e1cc0e33c023c1ac62dd28fef313285250.tar.gz
PeerTube-587568e1cc0e33c023c1ac62dd28fef313285250.tar.zst
PeerTube-587568e1cc0e33c023c1ac62dd28fef313285250.zip
Add plugin table migration table
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0405-plugin.ts40
-rw-r--r--server/lib/plugins/hooks.ts2
-rw-r--r--server/lib/plugins/plugin-manager.ts7
-rw-r--r--server/tests/plugins/action-hooks.ts2
-rw-r--r--shared/core-utils/plugins/hooks.ts2
6 files changed, 51 insertions, 4 deletions
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'
14 14
15// --------------------------------------------------------------------------- 15// ---------------------------------------------------------------------------
16 16
17const LAST_MIGRATION_VERSION = 400 17const LAST_MIGRATION_VERSION = 405
18 18
19// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
20 20
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 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction,
5 queryInterface: Sequelize.QueryInterface,
6 sequelize: Sequelize.Sequelize,
7 db: any
8}): Promise<void> {
9 {
10 const query = `
11CREATE TABLE IF NOT EXISTS "plugin"
12(
13 "id" SERIAL,
14 "name" VARCHAR(255) NOT NULL,
15 "type" INTEGER NOT NULL,
16 "version" VARCHAR(255) NOT NULL,
17 "latestVersion" VARCHAR(255),
18 "enabled" BOOLEAN NOT NULL,
19 "uninstalled" BOOLEAN NOT NULL,
20 "peertubeEngine" VARCHAR(255) NOT NULL,
21 "description" VARCHAR(255),
22 "homepage" VARCHAR(255) NOT NULL,
23 "settings" JSONB,
24 "storage" JSONB,
25 "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
26 "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
27 PRIMARY KEY ("id")
28);`
29 await utils.sequelize.query(query)
30 }
31}
32
33function down (options) {
34 throw new Error('Not implemented.')
35}
36
37export {
38 up,
39 down
40}
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 <U, T> = (params: U) => T
9// Helpers to run hooks 9// Helpers to run hooks
10const Hooks = { 10const Hooks = {
11 wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U) => { 11 wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U) => {
12 return PluginManager.Instance.runHook(hookName, result) as Promise<T> 12 return PluginManager.Instance.runHook(hookName, result)
13 }, 13 },
14 14
15 wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, params: U, hookName: V) => { 15 wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, 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 {
125 try { 125 try {
126 await this.registerPluginOrTheme(plugin) 126 await this.registerPluginOrTheme(plugin)
127 } catch (err) { 127 } catch (err) {
128 // Try to unregister the plugin
129 try {
130 await this.unregister(PluginModel.buildNpmName(plugin.name, plugin.type))
131 } catch {
132 // we don't care if we cannot unregister it
133 }
134
128 logger.error('Cannot register plugin %s, skipping.', plugin.name, { err }) 135 logger.error('Cannot register plugin %s, skipping.', plugin.name, { err })
129 } 136 }
130 } 137 }
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 () {
43 path: getPluginTestPath() 43 path: getPluginTestPath()
44 }) 44 })
45 45
46 await killallServers([ servers[0] ]) 46 killallServers([ servers[0] ])
47 47
48 await reRunServer(servers[0]) 48 await reRunServer(servers[0])
49 }) 49 })
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) {
8 return HookType.STATIC 8 return HookType.STATIC
9} 9}
10 10
11async function internalRunHook <T>(handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { 11async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) {
12 try { 12 try {
13 if (hookType === HookType.FILTER) { 13 if (hookType === HookType.FILTER) {
14 const p = handler(result, params) 14 const p = handler(result, params)