[MM-40935] Add OnInstall() plugin hook (#19499)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2d986ef920
Коммит
6dab9eadf8
@@ -706,6 +706,42 @@ func (s *hooksRPCServer) RunDataRetention(args *Z_RunDataRetentionArgs, returns
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
hookNameToId["OnInstall"] = OnInstallID
|
||||
}
|
||||
|
||||
type Z_OnInstallArgs struct {
|
||||
A *Context
|
||||
B model.OnInstallEvent
|
||||
}
|
||||
|
||||
type Z_OnInstallReturns struct {
|
||||
A error
|
||||
}
|
||||
|
||||
func (g *hooksRPCClient) OnInstall(c *Context, event model.OnInstallEvent) error {
|
||||
_args := &Z_OnInstallArgs{c, event}
|
||||
_returns := &Z_OnInstallReturns{}
|
||||
if g.implemented[OnInstallID] {
|
||||
if err := g.client.Call("Plugin.OnInstall", _args, _returns); err != nil {
|
||||
g.log.Error("RPC call OnInstall to plugin failed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
return _returns.A
|
||||
}
|
||||
|
||||
func (s *hooksRPCServer) OnInstall(args *Z_OnInstallArgs, returns *Z_OnInstallReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
OnInstall(c *Context, event model.OnInstallEvent) error
|
||||
}); ok {
|
||||
returns.A = hook.OnInstall(args.A, args.B)
|
||||
returns.A = encodableError(returns.A)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("Hook OnInstall called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_RegisterCommandArgs struct {
|
||||
A *model.Command
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ const (
|
||||
OnWebSocketDisconnectID = 22
|
||||
WebSocketMessageHasBeenPostedID = 23
|
||||
RunDataRetentionID = 24
|
||||
OnInstallID = 25
|
||||
TotalHooksID = iota
|
||||
)
|
||||
|
||||
@@ -249,4 +250,12 @@ type Hooks interface {
|
||||
//
|
||||
// Minimum server version: 6.4
|
||||
RunDataRetention(nowTime, batchSize int64) (int64, error)
|
||||
|
||||
// OnInstall is invoked after the installation of a plugin as part of the onboarding.
|
||||
// It's called on every installation, not only once.
|
||||
//
|
||||
// In the future, other plugin installation methods will trigger this hook, e.g. an installation via the Marketplace.
|
||||
//
|
||||
// Minimum server version: 6.5
|
||||
OnInstall(c *Context, event model.OnInstallEvent) error
|
||||
}
|
||||
|
||||
@@ -193,3 +193,10 @@ func (hooks *hooksTimerLayer) RunDataRetention(nowTime, batchSize int64) (int64,
|
||||
hooks.recordTime(startTime, "RunDataRetention", _returnsB == nil)
|
||||
return _returnsA, _returnsB
|
||||
}
|
||||
|
||||
func (hooks *hooksTimerLayer) OnInstall(c *Context, event model.OnInstallEvent) error {
|
||||
startTime := timePkg.Now()
|
||||
_returnsA := hooks.hooksImpl.OnInstall(c, event)
|
||||
hooks.recordTime(startTime, "OnInstall", _returnsA == nil)
|
||||
return _returnsA
|
||||
}
|
||||
|
||||
@@ -194,6 +194,20 @@ func (_m *Hooks) OnDeactivate() error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// OnInstall provides a mock function with given fields: c, event
|
||||
func (_m *Hooks) OnInstall(c *plugin.Context, event model.OnInstallEvent) error {
|
||||
ret := _m.Called(c, event)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(*plugin.Context, model.OnInstallEvent) error); ok {
|
||||
r0 = rf(c, event)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// OnPluginClusterEvent provides a mock function with given fields: c, ev
|
||||
func (_m *Hooks) OnPluginClusterEvent(c *plugin.Context, ev model.PluginClusterEvent) {
|
||||
_m.Called(c, ev)
|
||||
|
||||
Ссылка в новой задаче
Block a user