How to programmatically disable the Orchard module?

From Migrations.cs, I want to disable one module if it is enabled, and enable another if it is not already enabled. How can i do this?

+6
source share
2 answers

OK, I figured this out by looking at the Controller and Command classes in Orchard.Modules. First I had to add a link to the project for Orchard.Modules, and then in Migrations.cs:

public int UpdateFrom2() { var features = _moduleService.GetAvailableFeatures().ToDictionary(m=>m.Descriptor.Id, m=>m); if (features.ContainsKey("TinyMce") && features["TinyMce"].IsEnabled) { _moduleService.DisableFeatures(new string[] { "TinyMce" }); } if (features.ContainsKey("TinyMceDeluxe") && !features["TinyMceDeluxe"].IsEnabled) { _moduleService.EnableFeatures(new string[] { "TinyMceDeluxe" }); } return 3; } 
+8
source

I think you should take a look at the Orchard tool: you can enable or disable functions and get a list of allowed ones. Take a look at FeatureCommands.cs in the Orchard.Modules project. Hope this helps you.

+1
source

All Articles