(x *xorm.Engine, pluginSlugName string)
| 92 | } |
| 93 | |
| 94 | func deactivatePlugin(x *xorm.Engine, pluginSlugName string) (err error) { |
| 95 | fmt.Printf("try to deactivate plugin: %s\n", pluginSlugName) |
| 96 | |
| 97 | item := &entity.Config{Key: constant.PluginStatus} |
| 98 | exist, err := x.Get(item) |
| 99 | if err != nil { |
| 100 | return fmt.Errorf("get config failed: %w", err) |
| 101 | } |
| 102 | if !exist { |
| 103 | return nil |
| 104 | } |
| 105 | |
| 106 | pluginStatusMapping := make(map[string]bool) |
| 107 | _ = json.Unmarshal([]byte(item.Value), &pluginStatusMapping) |
| 108 | status, ok := pluginStatusMapping[pluginSlugName] |
| 109 | if !ok { |
| 110 | fmt.Printf("plugin %s not exist\n", pluginSlugName) |
| 111 | return nil |
| 112 | } |
| 113 | if !status { |
| 114 | fmt.Printf("plugin %s already deactivated\n", pluginSlugName) |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | pluginStatusMapping[pluginSlugName] = false |
| 119 | dataByte, _ := json.Marshal(pluginStatusMapping) |
| 120 | item.Value = string(dataByte) |
| 121 | _, err = x.ID(item.ID).Cols("value").Update(item) |
| 122 | if err != nil { |
| 123 | return fmt.Errorf("update plugin status failed: %w", err) |
| 124 | } |
| 125 | return nil |
| 126 | } |
no test coverage detected